Thread: Editing and Changing c++ text output files

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    10

    Editing and Changing c++ text output files

    User should be able to choose whether they would like to add a new student or edit an existing student’s record. User should be able to save the edited document or discard changes.

    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <iomanip>
    
    
    
    using namespace std;
    
    int main()
    {
            string data;              //For outputting data to te screen
            string firstName;         //Student First Name
            string lastName;          //Student Last Name
            string courseName;        //Course Name
            int id;                   //Student I.D. Number
            int numCourse;            //Number of courses
            int numGrades;            //Number of grades to be entered
            double grade=0.00;        //Separate Grade
            double totGrade=0.00;     //Sum of Grades received
            double poss=0.00;         //Possible Grade to be received in part. quiz
            double totPoss=0.00;      //Total of possible marks
            double finGrade=0.00;     //Final Grade
            double i=0.00;
    
            ofstream myfile;
            myfile.open("STUDRECORD.txt");
    
            //ifstream yourfile;
            //yourfile.open("STUDRECORD.txt");
    
            cout<<"Please enter student first name\n ";
            cin>>firstName;
            myfile<<firstName<<" ";
    
            cout<<"Please enter student last name\n ";
            cin>>lastName;
            myfile<<setw(5)<<lastName;
    
            cout<<"Please enter Identification Number\n";
            cin>>id;
            myfile<<setw(12)<<id;
    
    
            cin.get();
     cout<<"How many courses have you done?\n";
            cin>>numCourse;
    
            for(int a=1;a<=numCourse;a++)
            {
            if (numCourse==a)
                    {
                             myfile<<"\t\t\t\t";
                    }
    
    
            cout<<"Please enter Course Name"<<endl;
            cin.get();
            getline(cin, courseName, '\n');
            myfile<<setw(20)<<courseName;
    
            cout<<"How many grades will you be entering for this course?"<<endl;
            cin>>numGrades;
    
                    for(int i=0;i<numGrades;i++)
                    {
                    cout<<"Please enter quiz grade"<<endl;
                    cin>>grade;
                    myfile<<setw(6)<<grade;
    
                    totGrade+=grade;
    
                    cout<<"How much was this quiz out of?"<<endl;
                    cin>>poss;
                    totPoss+=poss;
                    myfile<<"/"<<poss;
                  }
             myfile<<"\n";
    
            }
    
    
    
            finGrade=(totGrade/totPoss)*(100/1);
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    What's giving you trouble?
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    10
    Im not sure as to how to edit it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Editing exsiting files... Please help
    By Unregistered in forum Game Programming
    Replies: 3
    Last Post: 06-22-2002, 01:39 PM