Create a class which stores name, roll number and total marks for a student.Input the data for a student and display it.
#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;
}
Comments
Leave a comment