To write a C++ program to implement classes with arrays as data members.




Algorithm:
Step 1: Start the program.
Step 2: Create a class student which contains primitive data members and constant data members.
Step 3: Create the object for the class to access the member function.
Step 4: Call the appropriate member function and display the result.
Step 5: Stop the program.

Program Code:
#include<iostream.h>
#include<conio.h>
class student
{
int rno;
char name[10];
int marks[3];
int total;
float avg;
const float no;
public:
void get()
{
cout<<"Enter the name:";
cin>>name;
cout<<"Enter the Roll no:";
cin>>rno;
cout<<"Enter three subject marks:";
for(int i=0;i<3;i++)
{
cin>>marks[i];
}
void display()
{
cout<<"\nName:"<<name;
cout<<"\nRoll No:"<<rno;
cout<<"\n Marks:";
for(int i=0;i<3;i++)
{
cout<<marks[i]<<"\t";
total+=marks[i];
}
cout<<"\nTotal:"<<total;
cout<<"\nAverage:"<<total/no ;
}
};
void main()
{
student s;
clrscr();
s.get();
s.display();
getch();
}




Output:
Enter the name:
Ram
Enter the Roll No:
17
Enter three subject marks:
89 68 88
Name:Ram
Roll No:17
Marks:89 68 88
Total:245
Average:81.666664
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: