C++ Program to Input Marks and Find Grade and CGPA

Input Marks and Find Grade and CGPA

A class has four papers in one term. Write a program that will read in a student’s score in four papers as integer and output the student’s average and grade according to the following table.

Average marks >= 80 are A Average marks >= 60 are B Average marks >= 50 are C Average marks >= 40 are D If the student scores less than 40 in any paper the grade will fail.

Use the Switch Statement to display the grade.

Source Code:

#include<iostream.h>
#include<conio.h>
void main()
{
    int ch;
    cout<<“1. Average or Grade”<<endl;
    cout<<“2. Exit”<<endl;
    cin>>ch;
    switch(ch)
    {
        case 1:
          int tot, avg, oop, dsa, mp, psy;
          cout<<“Enter Marks:”<<endl;
          cin>>oop>>dsa>>mp>>psy;
            tot=avg+oop+dsa+mp+psy;
            avg=tot/4;
              if(avg>=80)
                cout<<“A”;
              else if(avg>=60)
                cout<<“B”;
              else if(avg>=50)
                cout<<“C”;
              else if(avg>=40)
                cout<<“D”;
              else
                cout<<“Fail”;
              break;
          case 2:
              exit(0);
          default:
             cout<<“Wrong Choice”;
              exit(0);
    }
    getch();
}

Output:

1. Average or Grade
2. Exit

Enter Your Choice: 1
Enter Marks:

98
89
87
89

                           A

TutsMaster.org

Tutsmaster.org provides tutorials related to tech and programmings. We are also setting up a community for the users and students.