Answer to Question #262970 in C++ for Maulik

Question #262970

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.

1
Expert's answer
2021-11-08T17:33:32-0500
#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;
}

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