To write a program in C++ to prepare a student Record using class and object.

Algorithm to solve the above problem:
1. Start
2. Create a class record.
3. Read the name, Rollno ,mark1, mark2, mark3 of the student.
4. Calculate the average of mark as Avg = (mark1 + mark2 + mark3) / 3
5. Display the student record.
6. Stop.


Implementation of the above problem in C++:
#include<iostream>
using namespace std;
class record
{
public:
char name[20];
int rollno;
int m1,m2,m3;
float avg;
void getdata()
{
cout<<"\n Enter the name: " ;
cin>>name;
cout<<"Enter the rollno: ";
cin>>rollno;
cout<<"enter the m1,m2,m3: \n";
cin>>m1>>m2>>m3;
}
void calculate()
{
avg=(m1+m2+m3)/3;
}
void display()
{
cout<<"\nName: "<<name;
cout<<"\nRollno: "<<rollno;
cout<<"\nMark1: "<<m1;
cout<<"\nMark2: "<<m2;
cout<<"\nMark3: "<<m3;
cout<<"\nAvg: "<<avg;
}
};

void main()
{
record r;
r.getdata();
r.calculate();
r.display();
return 0;
}

The output of the above program is tested on www.jdoodle.com
Output:
Enter the name: Mukesh
Enter the rollno: 101
enter the m1,m2,m3: 34 65 78
Name: Mukesh
Rollno: 101
Mark1: 34
Mark2: 65
Mark3: 78
Avg: 59


Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: