A program that accepts the information and calculated CGPA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dizzy
    New Member
    • Jan 2015
    • 4

    A program that accepts the information and calculated CGPA

    i want to display the grade report of two students in the table but this code will repeat the grade report of one student in the tables and what is wrong with this code below ?
    please guy just help me !!

    #include<iostre am>
    #include<string >
    #include<fstrea m>
    using namespace std;

    class student{

    private:

    string fname;
    string lname;
    char sex;
    string id;
    char grade[20];
    int year;
    int semester;
    int nocourse;
    string coursename[20];
    int crhr[20];
    int coursecrhr[20];
    int totalcrhr = 0;
    int point[20];
    int totalpoint = 0;
    double cgpa;
    public:

    void acceptdata(){

    cout << "Enter year: " << endl;
    cin >> year;

    cout << "Enter semester: " << endl;
    cin >> semester;

    cout << "Number of course: " << endl;
    cin >> nocourse;

    for (int i = 1; i <= nocourse; i++)
    {

    cout << "Course Name: ";
    cin >> coursename[i];

    cout << "Credit hour: ";
    cin >> crhr[i];


    }

    }

    void studinfo(){
    for (int i = 1; i <= nocourse; i++){

    cout << "Student name: ";
    cin >> fname;

    cout << "Student id: ";
    cin >> id;

    cout << "Student sex: ";
    cin >> sex;
    }
    G:
    for (int i = 1; i <= nocourse; i++){
    cout << "Grade for " << coursename[i] << ":";
    cin >> grade[i];
    if (grade[i] == 'A'){
    point[i] = 4;
    }
    else if (grade[i] == 'B')
    {
    point[i] = 3;
    }
    else if (grade[i] == 'C'){
    point[i] = 2;
    }
    else if (grade[i] == 'D')
    {
    point[i] = 1;
    }
    else if (grade[i] == 'F')
    {
    point[i] = 0;
    }
    else
    {
    cout << "Please enter correct grade in capital letter!" << endl;
    goto G;
    }
    }

    }

    void gradecalc(){
    for (int i = 1; i <= nocourse; i++){
    totalcrhr += crhr[i];
    totalpoint += crhr[i] * point[i];
    }
    cgpa = totalpoint / totalcrhr;
    cout << "______________ _______________ _______________ _______________ _______________ ___" << endl;
    cout << " Jigjiga University " << endl;
    cout << " Name: " << fname;
    cout << " Sex: " << sex;
    cout << " ID: " << id;
    cout << " year: " << year;
    cout << " Semester: " << semester << endl;
    cout << "-----------------------------------------------------------------------------" << endl;
    cout << "Sno \t Course Name \t CrHr \t\t Grade \t\t Point" << endl;
    cout << "-----------------------------------------------------------------------------" << endl;
    for (int i = 1; i <= nocourse; i++){
    cout << i << " \t" << coursename[i] << " \t" << crhr[i] << " \t\t" << grade[i] << " \t\t" << point[i] << endl;
    }
    cout << "______________ _______________ _______________ _______________ _______________ ___" << endl;
    cout << "Total Point: " << totalpoint;
    cout << "\t\t\t\t CGPA: " << cgpa << endl;
    }

    };

    int main()
    {
    student s,s1;

    s.acceptdata();
    s.studinfo();
    s.gradecalc();
    s1.acceptdata() ;
    s1.studinfo();
    s1.gradecalc();

    return 0;

    }
    Last edited by Dizzy; Jan 30 '15, 06:36 PM. Reason: I
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    It works for me.

    However, I had to remove that goto that was stopping your for loop from working.

    goto is an ancient curse from C. It should never appear in a C++ program.

    Comment

    • Dizzy
      New Member
      • Jan 2015
      • 4

      #3
      Thank you now is working me too and please can you show me how to store above information or data into file name "Grade Report" and show me with with simple example.

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Create an fstream object and use the << operator to put data in the file.

        Code:
        fstream myfile("GradeReport.txt");
                myfile << data;
        If you need to read data from the file use the >> operator. However, in this case be sure you have the data in the file in a known format.

        There are a lot of examples on the Internet for this.

        Comment

        Working...