Answer to Question #284252 in C++ for Mehtab

Question #284252

Create a class GradeBook that maintains the course name as a data member so that it can be used


or modified at any time during a program's execution. The class contains member functions


setCourseName, getCourseName and displayMessage. Member function setCourseName stores a


course name in a GradeBook data member, member function getCourseName obtains a


GradeBook's course name from that data member. Member function displayMessage which now


specifies no parameters but displays a welcome message that includes the course name.


The class should also take input for student name (string) and student marks (float). The


number of students for which grades are to be entered should be specified by the user. The


program should also calculate and print the grades for students.

1
Expert's answer
2022-01-04T05:50:49-0500
#include <iostream> 
#include<string>

using namespace std;

class GradeBook
{
	string courName;
public:
	GradeBook(){}
	void setCourseName()
	{
		cout<<"Please, enter the course name: ";
		getline(cin,courName,'\n');
	}
	string getCourseName()
	{
		return courName;
	}
	void displayMessage()
	{
		cout<<"\n\t\tYou are welcome!\n";
		cout<<"You are on course "<<courName;
	}
	void CalcGrades()
	{
		int num;
		cout<<"\nEnter the number of students to "
			<<"calculate grades: ";
		cin>>num;
		for(int i=0;i<num;i++)
		{
			float grade;
			float sumGrade=0;
			int j=0;
			cout<<"\nEnter grades of student "<<i+1<<" (-1 - exit): ";
			do
			{
				cin>>grade;
				if(grade==-1)break;
				sumGrade+=grade;
				j++;
			}while(true);
			cout<<"Result grade of student "<<i+1<<" is "<<(float)sumGrade/j;	
		}
	}
};

int main()
{
	GradeBook gb;
	gb.setCourseName();
	cout<<"\nYou course: "<<gb.getCourseName();
	gb.displayMessage();
	gb.CalcGrades();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog