Answer to Question #234988 in C++ for SOM

Question #234988

Create a class which stores name, roll number and total marks for a student.Input the data for a student and display it.


1
Expert's answer
2021-09-13T18:37:05-0400
#include <iostream>
using namespace std;
class student
{
	private:
		char  name[20];
		int   roll_No;
		int   total_marks;
		float percentage;
	public:
		void getDetails(void);
		void outputDetails(void);
};
void student::getDetails(void){
	cout << "Enter name: " ;
	cin >> name;
	cout << "Enter roll number: ";
	cin >> roll_No;
	cout << "Enter total marks out of 500: ";
	cin >> total_marks;
	
	percentage=(float)total_marks/500*100;
}
void student::outputDetails(void){
	cout << "Student details are:\n";
	cout << "Name:"<< name << ",Roll Number:" << roll_No << ",Total:" << total_marks << ",Percentage:" << percentage;
}


int main()
{
	student details;	
	
	details.getDetails();
	details.outputDetails();
	
	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