Answer to Question #238692 in C++ for Imran

Question #238692
Write a class marks with three data members to store three marks. Write three
member functions, set_marks() to input marks, sum() to calculate and return the sum
and avg() to calculate and return average marks.
1
Expert's answer
2021-09-17T16:29:29-0400
#include <iostream>

class Marks
{
public:
	void set_marcs() 
	{
		std::cout << "Enter your first mark: ";
		std::cin >> mark_1;
		std::cout << "Enter your second mark: ";
		std::cin >> mark_2;
		std::cout << "Enter your third mark: ";
		std::cin >> mark_3;
	}
	int sum() 
	{
		return mark_1 + mark_2 + mark_3;
	}
	double avg() 
	{
		return sum() / 3.0;
	}


private:
	int mark_1{ 0 };
	int mark_2{ 0 };
	int mark_3{ 0 };
};


int main()
{
	Marks example;
	example.set_marcs();
	std::cout << "Sum of marks: "<<example.sum()<<std::endl;
	std::cout << "Average of marks : " << example.avg() << std::endl;
	return 0;
}

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
APPROVED BY CLIENTS