CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2011
    Posts
    21

    Question 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.

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: new help with string

    You forgot your closing code tag.

    Is there a question in there?

  3. #3
    Join Date
    Jun 2011
    Posts
    21

    Re: new help with string

    oh yeah i forgot my bad is not capalizing the words ??

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    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
  •  





Click Here to Expand Forum to Full Width

Featured