Banner 468

Facebook
RSS

C++ programme using a class student to calculate the percentage of marks obtained, percentage Code, How to calculatet percentage in C++

-
Unknown

C++ programme using a class student to calculate the percentage of marks obtained by him, Calculate percentage in C++ with simple code.


//--Student Name--//
//--Muhammad Idrees--//
#include<iostream.h>
#include<conio.h>

class student
{
               int roll_no;
               char name[20];
               char class_st[8];
               int marks[5];
               float percentage;
               float calculate();
               public:
               void readmarks();
               void displaymarks();
};


float student::calculate()
{
               percentage=0;
               for(int i=0;i<5;i++)
                              percentage+=marks[i];
               percentage=(percentage/5);
               return percentage;
}


void student::readmarks()
{
               cout<<"Enter the roll no.:";
               cin>>roll_no;
               cout<<"Enter the name:";
               cin>>name;
               cout<<"Enter the class studing in:";
               cin>>class_st;
               cout<<"Enter the marks:"<<endl;
               for(int j=0;j<5;j++){
                              cout<<"\tEnter mark "<<j+1<<":";
                              cin>>marks[j];
               }
}

//-----display marks of student---//
void student::displaymarks()
{
               cout<<"Roll no:"<<roll_no<<endl;
               cout<<"Name:"<<name<<endl;
               cout<<"Class:"<<class_st<<endl;
               cout<<"Percentage:"<<calculate()<<endl;
}

//-----enter student details-----//
int main()
{
               student s1;
               s1.readmarks();
               s1.displaymarks();
               return 0;
}
//------Output---------//
OUTPUT:

Enter the roll no.:12
Enter the name:Muhammad Idrees                                                          
Enter the class studing in:M.sc Computer sciences                                                  
Enter the marks:                                                               
        Enter mark 1:99                                                         
        Enter mark 2:95                                                        
        Enter mark 3:90                                                        
        Enter mark 4:80                                                         
        Enter mark 5:99                                                        

Roll no:12                                                                     
Name:Muhammad Idrees                                                                    
Class:12                                                                       
Percentage:92.59

return 0;
end of program.


Leave a Reply