(a) Write a program which calculates and displays the obtained marks, percentage in six subjects and assigns grades based on percentage obtained by a student.
i. if the percentage is above 90, assign grade A
ii. if the percentage is above 75, assign grade B+
iii. if the percentage is above 70, assign grade B
iv. if the percentage is above 65, assign grade C+
v. if the percentage is above 60, assign grade C
vi. if the percentage is above 55, assign grade D+
vii. if the percentage is less than 50, assign grade F
(Hint: using logical operators)
c++ programming

Respuesta :

Answer:

The program in C++ is as follows:

#include <iostream>

using namespace std;

int main(){

   int scores[6];

   int sum =0;

   string grade;

   for(int i =0; i < 6; i++){

       cin>>scores[i];

       sum+=scores[i];    }

   double percent = sum/6.0;

   if(percent > 90){        grade ="A";    }

   else if(percent>75){        grade ="B+";    }

   else if(percent>70){        grade ="B";    }

   else if(percent>65){        grade ="C+";    }

   else if(percent>60){        grade ="C";    }

   else if(percent>55){        grade ="D+";    }

   else if(percent<50){        grade ="F";    }

   cout<<grade;

   return 0;

}

Explanation:

This declares the 6 scores using an array

   int scores[6];

This initializes the sum of all scores to 0

   int sum =0;

This declares the grade as string

   string grade;

This iterates through the scores

   for(int i =0; i < 6; i++){

This gets input for each score

       cin>>scores[i];

This adds up the scores

       sum+=scores[i];    }

This calculates the percentage

   double percent = sum/6.0;

The following if statements determine the grade

   if(percent > 90){        grade ="A";    }

   else if(percent>75){        grade ="B+";    }

   else if(percent>70){        grade ="B";    }

   else if(percent>65){        grade ="C+";    }

   else if(percent>60){        grade ="C";    }

   else if(percent>55){        grade ="D+";    }

   else if(percent<50){        grade ="F";    }

This prints the grade

   cout<<grade;