C++ Program to Store Name Roll and Marks In 5 Subject

Create a class which stores name, roll number and store marks in 5 subjects. Calculate the total marks and percentage of a student





#include<iostream>
using namespace std;
class student
{
    char name[30];
    int roll;
    float mark[5], total,percent;
    public:
        void getdata()
        {
            int i;
            cout<<"Enter your name"<<endl;
            cin>>name;
            cout<<"Enter your roll"<<endl;
            cin>>roll;
            cout<<"Enter mark of 5 subject"<<endl;
            for(i=0;i<5;i++)
                cin>>mark[i];
        }
        void showdata()
        {
            int i;
            cout<<"Name:"<<name<<endl;
            cout<<"Roll no:"<<roll<<endl;
            total = 0;
            for(i=0;i<5;i++)
                total = total + mark[i];
            cout<<"Total mark:"<<total<<endl;
            percent = total/5;
            cout<<"Percent:"<<percent<<endl;
        }
};
int main()
{
    student s;
    s.getdata();
    s.showdata();
    return 0;
}

OUTPUT


Enter your name
ABCD
Enter your roll
21
Enter mark of 5 subject
87
90
99
87
90
Name:ABCD     
Roll no:21    
Total mark:453
Percent:90.6

Admin

Hi This is the Admin of CodingSoln. Currently Pursuing B. Tech Computer Science and Engineering form KIIT University India

Post a Comment

Previous Post Next Post