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

    HELP!! Urgent help needed for program assignment. (Output to notepad program)

    Its a basic program. Im using codeblocks to program this program. Can someone help me?!

    Question=

    Program with file output operation:
    -User to enter a group of students names and marks for a few subjects they have taken
    -User to enter a list of groceries purchased. It should include date, descreption, cost,etc.
    -User to enter his/her daily expenses. It should include date, amount, etc.
    -User to enter his/her car fuel consumption history. It should include date,amount,brand,odometer reading,etc.

    The content of the saved file must be on notepad. All the points above must be in one program.
    PLEASE HELP!! I need the code for this program urgently but i cant seem to program it myself.
    It requires fstream.

    If all the 4 features are too troublesome, can someone help me do the first feature at least? D:

    I am using codeblocks btw, it has to be able to run on codeblocks. Basically this assignment is program with file output operation.

    If someone can help me out i will be supeeeeeeeeeeeeeer happy. PLEASE
    Last edited by platoon181; February 10th, 2012 at 01:03 AM.

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: HELP!! Urgent help needed for program assignment.

    What have you tried?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Feb 2012
    Posts
    2

    Re: HELP!! Urgent help needed for program assignment. (Output to notepad program)

    Quote Originally Posted by laserlight View Post
    What have you tried?
    This is what i did, the output to notepad is fine. But this program only asks for one subject. I need it to allow the user to enter multiple subjects. But i dont know how to program it to allow the user to enter multiple subjects per student! PLEASE HELP


    Code:


    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    string subname_marks();
    string name, subject, mark;
    int main ()
    {
    string line;
    // char name[256], subject[256], mark[256];



    // ****** Declare Output File *****
    ofstream myfile;
    myfile.open ("StudentResult.txt");

    // ********* Input Student Information **********
    do
    { cout << "Enter Student name or Q to End: ";
    // cin.getline (name,256);
    cin >> name;

    if (name=="Q") break;

    subname_marks();

    myfile << "Name:" << name << "\nSubject:" << subject << "\nMark:" << mark << "\n";
    // ********* Write Information to file **********

    } while (true);


    // *********Close Output file **********
    myfile.close();


    // ********* Open file and display for Student Information **********
    ifstream myfile1 ("StudentResult.txt");
    cout << "\n\nThe content of the stored file:\n";
    if (myfile1.is_open())
    {
    while ( myfile1.good() )
    {
    getline (myfile1,line);
    cout << line << endl;
    }
    myfile1.close();
    }

    else cout << "Unable to open file";

    return 0;
    }
    string subname_marks(void)
    {
    cout << "Enter Subject name or Q when done: ";
    //cin.getline (subject,256);
    cin >> subject;

    cout << "Enter Mark: ";
    //cin.getline (mark,10);
    cin >> mark;

    cout <<"\n";

    return subject;

    }
    Last edited by platoon181; February 10th, 2012 at 01:02 AM.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: HELP!! Urgent help needed for program assignment. (Output to notepad program)

    Quote Originally Posted by platoon181 View Post
    This is what i did, the output to notepad is fine. But this program only asks for one subject. I need it to allow the user to enter multiple subjects.
    So where are you going to store these multiple subjects when they're inputted? You currently just have room for one subject. You need a vector of subjects for each student. So the issue is not really how you input, it's where you're going to store this information once its inputted.

    Once you figure that out, then you need to ask the student for the number of subjects, and then write a loop prompting for subject 1, 2, 3, 4, etc.

    Also, you should format your code properly.
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    string subname_marks();
    string name, subject, mark;
    
    int main ()
    {
        string line;
        // char name[256], subject[256], mark[256];
    
    
    
        // ****** Declare Output File *****
        ofstream myfile;
        myfile.open ("StudentResult.txt");
    
        // ********* Input Student Information **********
        do
        { 
            cout << "Enter Student name or Q to End: ";
            // cin.getline (name,256);
            cin >> name;
    
            if (name=="Q") break;
    
            subname_marks();
    
            myfile << "Name:" << name << "\nSubject:" << subject << "\nMark:" << mark << "\n";
            // ********* Write Information to file **********
    
        } while (true);
    
    
        // *********Close Output file **********
        myfile.close();
    
    
        // ********* Open file and display for Student Information **********
        ifstream myfile1 ("StudentResult.txt");
        cout << "\n\nThe content of the stored file:\n";
        if (myfile1.is_open())
        {
            while ( myfile1.good() )
            {
                getline (myfile1,line);
                cout << line << endl;
            }
            myfile1.close();
        }
    
        else cout << "Unable to open file";
    
        return 0;
    }
    
    string subname_marks(void)
    {
        cout << "Enter Subject name or Q when done: ";
        //cin.getline (subject,256);
        cin >> subject;
    
        cout << "Enter Mark: ";
        //cin.getline (mark,10);
        cin >> mark;
    
        cout <<"\n";
    
        return subject;
    }
    Also, codeblocks is not a compiler. The compiler is gcc. All CodeBlocks does is give you an environment to enter your code, compile it using the gcc compiler, and run your program.

    Last, the deadline is your issue, not ours. Your post is no more important than any other post here.

    Regards,

    Paul McKenzie

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