139k views
4 votes
Write a C++ Program that contains one user defined function cal_grades().  In main() function: o Prompt user to enter obtained(0 - 100) marks for one subject. o Call cal_grades(marks_subject). o Print the corresponding Grade with respect to Marks.  In user defined function: o Perform conditioning with else if statement return char value. o Function must return value.

User Dalyons
by
6.6k points

1 Answer

5 votes

Answer:

# include <iostream>

#include<conio.h>

using namespace std;

char grade(int marks);

main()

{

int subject 1, subject 2, subject 3, subject 4, subject 5, sum, percentage;

char G;

cout<<"enter marks of subject 1";

cin>>subject 1;

cout<<"enter marks of subject 2";

cin>>subject 2;

cout<<"enter marks of subject 3";

cin>>subject 3;

cout<<"enter marks of subject 4";

cin>>subject 4;

cout<<"enter marks of subject 5";

cin>>subject 5;

G = grade (subject 1);

cout<<"Grade of Subject 1"<< G;

G = grade (subject 2);

cout<<"Grade of Subject 2"<< G;

G = grade (subject 3);

cout<<"Grade of Subject 3"<< G;

G = grade (subject 4);

cout<<"Grade of Subject 4"<< G;

G = grade (subject 5);

cout<<"Grade of Subject 5"<< G;

sum = Subject 1 +Subject 2 +Subject 3 +Subject 4 + Subject 5;

Percentage = sum/500*100;

G = grade (percentage);

cout<<"Overall Grade"<< G;

getch();

}

char grade(int marks)

{

int marks;

char 'A', 'B' , 'C' , 'D' , 'F';

if (marks >80)

{

return 'A';

}

else

if (marks >70 && marks< 80 )

{

return 'B';

}

else

if (marks >60 && marks< 70 )

{

return 'C';

}

else

if (marks >50 && marks< 60 )

{

return 'D';

}

else

return 'F';

}

The program will compute the percentage of the marks obtained, then with the help of this percentage score the output will be determined by function named as Grade.

User Bids
by
6.4k points