Q:

C++ program to create class to get and print details of a student

belongs to collection: C++ Classes and Object programs

0

C++ program to create class to get and print details of a student

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Read and print details of a student using class program in C++

 

/*C++ program to create class for a student.*/
#include <iostream>
using namespace std;

class student
{
	private:
		char  name[30];
		int   rollNo;
		int   total;
		float perc;
	public:
		//member function to get student's details
		void getDetails(void);
		//member function to print student's details
		void putDetails(void);
};

//member function definition, outside of the class
void student::getDetails(void){
	cout << "Enter name: " ;
	cin >> name;
	cout << "Enter roll number: ";
	cin >> rollNo;
	cout << "Enter total marks outof 500: ";
	cin >> total;
	
	perc=(float)total/500*100;
}

//member function definition, outside of the class
void student::putDetails(void){
	cout << "Student details:\n";
	cout << "Name:"<< name << ",Roll Number:" << rollNo << ",Total:" << total << ",Percentage:" << perc;
}

int main()
{
	student std;		//object creation
	
	std.getDetails();
	std.putDetails();
	
	return 0;
}

Output

    Enter name: mike
    Enter roll number: 112
    Enter total marks outof 500: 456
    Student details:
    Name:mike,Roll Number:112,Total:456,Percentage:91.2

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Classes and Object programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C++ program to create student class, read and prin... >>
<< C++ program to create a class to read and add two ...