Back To C++ Classes
in the code given below getdata() member function inputs data from user, calculate() member function calculates total and percentage of student and showdata() function displays the data with total and percentage of student
//program to demonstrate example of class student with array marks having 3 integer elements as a datamember of the class (datamembers total and percentage are calculated using member function calculate) #include
#include
class student { int rollno; char name[20]; int clas; float marks[3]; float total; float percentage; public: void getdata(); void showdata(); void calculate(); }; void student::getdata() { int i; cout<<"\nenter rollno of student "; cin>>rollno; cout<<"\nenter name of student "; cin>>name; cout<<"\nenter class of student "; cin>>clas; for(i=0;i<3;i++) { cout<<"\nenter marks of student in subject "<
>marks[i]; } } void student::showdata() { int i; cout<<"\nrollno of student is "<