I have written this program as a homework assignment and can't get it quite right, hopefully someone can help me. The program should perform the following task:
Design and document a program which uses a one-dimensional character array, and reads the string from an input data file and writes output to an output file.
The user’s data file should contain the user’s name with first character capitalized: First name, Middle Initial, Last Name, and address, with zip code, separated by spaces or enters (endline or carriage returns).
The program should read, from the user data file, the user's full name (first name, middle initial, last name) and address, display the full name, then find and display, from that string data, the user's nominal email name (nominally, in lower case, the first name, a dash, and the last name @utc.edu). Then the program should display the user’s address, calculate and display the number of characters in the user's total name and address. Finally, it should find and display the user's three initials in lower case. The output file should contain the same information in the same format as the display screen.
I can get the program to work about 90% correctly, it does everything except write to an output file and I can't figure out how to convert my initials from uppercase to lowercase. In case anyone was wondering I am running this from Bloodshed Dev C++.
What I have so far:
insert
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
//Open program reading from text file
ifstream fin("data.txt");
string s;
string info[5];
string details[5];
details[0] = "First name";
details[1] = "Middle initial";
details[2] = "Last name";
details[3] = "Address";
details[4] = "Email";
int i = 0;
while( getline(fin,s) )
{
info[i] = s;
cout << details[i]<<" : " << s << endl;
i++;
}
//Get total name,address, and initials
int totalName = info[0].length()+info[1].length()+info[2].length();
int totalAddress = info[3].length();
string initials;
for(int t= 0; t<3; t++)
initials += (info[t]).substr(0,1);
//Displays total name, address, and initials
cout<<"number of characters in the user's total name : "<<totalName<<endl;
cout<<"number of characters in the user's address : "<<totalAddress<<endl;
cout<<"Initials : "<<initials;
// End program
cin.ignore(256, '\n');
cout << "Press ENTER to continue..." << endl;
cin.get();
return 0;
}
Thanks for the help.