-
June 30th, 2011, 06:43 PM
#1
new help with string
[code]
void getfilename (string,string&);
void reformat (string);
void writeinfo (ofstream&,string,string);
int main()
{
cout<<fixed<<showpoint<<setprecision(2);
ifstream input;//variable infile represents the name of the file being opened
ofstream output;//
string out_putname="velazq32_taxes";
string filename,lname,status;
getfilename("input",filename);
input.open(filename.c_str());
output.open(out_putname.c_str());
input >> lname;
while (!input.eof())
{
input >> status;
writeinfo(output,lname,status);
reformat(lname);
input >> lname;
}
input.close();
output.close();
return 0;
}
void writeinfo (ofstream& out,string lname,string status)
{
out << left <<"Tax summary for "<<lname<<" family"<<endl;
out<< left<<"Filling status: "<<status<<endl;
}
void getfilename(string filetype,string& filename)
{
cout << "Enter name of " << filetype << " file\n";
cin >> filename;
}
void reformat (string lname)
//Given a word, convert the first letter to upper case and the
//rest of the letters to lower case. The converted word will
//be passed back.
{
int wlen;
wlen = lname.length();
lname[0] = toupper(lname[0]);
for (int i=1; i<wlen; i++)
lname[i] = tolower(lname[i]);
}
Code:
void getfilename (string,string&);
void reformat (string);
void writeinfo (ofstream&,string,string);
int main()
{
cout<<fixed<<showpoint<<setprecision(2);
ifstream input;//variable infile represents the name of the file being opened
ofstream output;//
string out_putname="velazq32_taxes";
string filename,lname,status;
getfilename("input",filename);
input.open(filename.c_str());
output.open(out_putname.c_str());
input >> lname;
while (!input.eof())
{
input >> status;
writeinfo(output,lname,status);
reformat(lname);
input >> lname;
}
input.close();
output.close();
return 0;
}
void writeinfo (ofstream& out,string lname,string status)
{
out << left <<"Tax summary for "<<lname<<" family"<<endl;
out<< left<<"Filling status: "<<status<<endl;
}
void getfilename(string filetype,string& filename)
{
cout << "Enter name of " << filetype << " file\n";
cin >> filename;
}
void reformat (string lname)
//Given a word, convert the first letter to upper case and the
//rest of the letters to lower case. The converted word will
//be passed back.
{
int wlen;
wlen = lname.length();
lname[0] = toupper(lname[0]);
for (int i=1; i<wlen; i++)
lname[i] = tolower(lname[i]);
}
is not capalizing the first words
Tax summary for jones family
Filling status: married
this is my output
i want jones named capatalize for exanple if the input is JoneS to come out has Jones
thanks
Last edited by ryamjones; June 30th, 2011 at 07:04 PM.
-
June 30th, 2011, 06:59 PM
#2
Re: new help with string
You forgot your closing code tag.
Is there a question in there?
-
June 30th, 2011, 07:05 PM
#3
Re: new help with string
oh yeah i forgot my bad is not capalizing the words ??
-
June 30th, 2011, 07:23 PM
#4
Re: new help with string
"The converted word will
//be passed back."
I don't see that happening. Try passing the string in by reference or returning the formatted string.
Proper indentation would make your code much easier to read.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|