Create class Student which contains database of rollNo, name, height, weight & percentage using
constructor and also display this database of 3 student using a method called display(). Then destroy the
objects when they are no longer needed.
#include <iostream>
#define max 3
using namespace std;
class student{
private:
char name[30];
int rollNo,weight,height,marks;
float perc;
public:
void getDetails(void);
void displayDetails(void);
};
void student::getDetails(void){
cout<<"Enter name: ";
cin>>name;
cout<<"Enter roll number: ";
cin>>rollNo;
cout<<"Enter height: ";
cin>>height;
cout<<"Enter wight: ";
cin>>weight;
cout<<"Enter marks: ";
cin>>marks;
perc=(float)marks/100*100;
}
void student ::displayDetails(void){
cout<<"student details: \n";
cout<<"Name:"<<name<<",Roll number:"<<rollNo<<",Height:"<<height<<",weight:"<<weight<<",Percentage:"<<perc<<endl;
}
int main()
{
student std[max];
int n,loop;
cout << "Enter total number of students: " << endl;
cin>>n;
for (loop=0;loop<n;loop++){
cout<<"Enter details of students"<<loop+1<<":\n";
std[loop].getDetails();
}
cout<<endl;
for (loop=0;loop<n;loop++){
cout<<"Details of students "<<(loop+1)<<":\n";
std[loop].displayDetails();
}
return 0;
}
Comments
Leave a comment