Answer to Question #203729 in C++ for python

Question #203729

Define a class student with the following specification. Note for user understanding purposes you

should write comment with each line of code.

Private members of class student

admno integer

sname 20 character

eng. math, science float

total float

ctotal() a function to calculate eng + math + science with float return type.


Public member function of class student

Takedata() Function to accept values for admno, sname, eng, science and invoke

ctotal() to calculate total.

Showdata() Function to display all the data members on the screen.


1
Expert's answer
2021-06-06T08:54:34-0400
#include <iostream>




using namespace std;


class Student {
private:
	int admno;
	char sname[20];
	float eng;
	float math;
	float science;
	float total;


	float ctotal() {
		return eng + math + science;
	}


public:


	void Takedata(int admno, char sname[20], float eng, float math, float science) {
		this->admno = admno;
		strcpy(this->sname, sname);
		this->eng = eng;
		this->math = math;
		this->science = science;
		this->total = ctotal();
	}
	void Showdata() {
		cout<<"\nAdmno: " <<admno<<"\n";
		cout<<"Name: " <<sname<<"\n";
		cout<<"Eng: " <<eng <<"\n";
		cout<<"Math: " <<math <<"\n";
		cout<<"Science: " <<science <<"\n";
		cout<<"Total: " <<total <<"\n";
	}
};
//The start point of the program
int main(){
	Student st;
	int admno;
	char sname[20];
	float eng;
	float math;
	float science;
	cout<<"Enter admno: ";
	cin>>admno;
	cin.ignore();
	cout<<"Enter sname: ";
	gets(sname);
	cout<<"Enter eng: ";
	cin>>eng;
	cout<<"Enter math: ";
	cin>>math;
	cout<<"Enter science: ";
	cin>>science;
	st.Takedata(admno, sname, eng, math, science);
	st.Showdata();
	cout<<"\n\n";


	system("pause");
	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

Merri Chow
16.02.23, 04:53

Hi assignmentexpert.com administrator, Your posts are always well-received by the community.

Leave a comment

LATEST TUTORIALS
New on Blog