Assignment
16
Write a C++ program to
create a class Student which contains data members as Roll_Number, Stud_Name,
Marks in five subjects. Write member functions to accept Student information.
Display all details of student along with a percentage and class obtained
depending on percentage. (Use array of objects)
Program Code for run:
#include
<iostream>
using
namespace std;
class
Student
{
private:
int Roll_Number,
Marks[5];
char Stud_Name[80],
Class;
public:
void accept();
void display();
};
void
Student :: accept()
{
cout << ” Accept Student
Roll Number “<< endl;
cin >> Roll_Number;
cout << ” Accept Student
Name”<< endl;
cin >> Stud_Name;
cout << ” Accept Student
Marks “<< endl;
float total = 0;
for( int i = 0; i < 5; i++)
{
cout << ” \t
Subject “<< i << endl;
cin >> Marks[i];
total = total +
Marks[i];
}
total = total / 5; // calculate
Percentage
if(total < 60)
Class=”B”;
if((total >= 60)&&(total
< 70))
Class=”A”;
if(total >= 70)
Class=”O”;
}
void
Student :: display()
{
cout << ” ” <<
Roll_Number << “\t” << Stud_Name << “\t
“;
for( int i = 0; i < 5; i++)
cout<< Marks[i] << “\t”;
cout << Class <<
“\n”;
}
int
main()
{
int n, i;
Student p[20];
cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;
cout << ” \t How many
Student data to enter ” << endl;
cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;
cin >> n;
cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;
cout << ” \t Enter Student
Details ” << endl;
for ( i = 0 ; i < n ; i ++)
{
cout<<” * *
* * * * * * * * * * * * * * * * * * * * * * * * * * ” << endl;
cout<<” \t
Enter Student Details of Student := ” << i << endl;
cout<<” * *
* * * * * * * * * * * * * * * * * * * * * * * * * * ” << endl;
p[i].accept();
}
cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;
cout << ” Display Student
Details ” << endl;
cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;
cout << ” RNO \tSName
\tSub1 \tSub 2 \tSub 3 \tSub4 \tSub 5“;
cout
<< “\t Class”<<endl;
cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;
for ( i = 0 ; i < n ; i ++)
p[i].display();
cout << ” * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * ” << endl;
return 0;
}
Output
of Program:
* * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
How many Student data to enter
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
5
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Enter Student Details
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Enter Student Details of Student := 1
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Accept
Student Roll Number
1
Accept
Student Name
RAM
Accept
Student Marks
Subject 1
54
Subject 2
55
Subject 3
56
Subject 4
57
Subject 5
58
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Enter Student Details of Student := 2
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Accept
Student Roll Number
2
Accept
Student Name
RAJ
Accept
Student Marks
Subject 1
64
Subject 2
65
Subject 3
66
Subject 4
67
Subject 5
68
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Enter Student Details of Student := 3
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Accept
Student Roll Number
3
Accept
Student Name
YOGI
Accept
Student Marks
Subject 1
94
Subject 2
95
Subject 3
96
Subject 4
97
Subject 5
98
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Enter Student Details of Student := 4
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Accept
Student Roll Number
4
Accept
Student Name
KAVYA
Accept
Student Marks
Subject 1
89
Subject 2
92
Subject 3
94
Subject 4
96
Subject 5
98
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Enter Student Details of Student := 5
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Accept
Student Roll Number
5
Accept
Student Name
DEEPA
Accept
Student Marks
Subject 1
67
Subject 2
78
Subject 3
89
Subject 4
99
Subject 5
98
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
Display Student Details
* * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ** * * * * *
RNO SName Sub1 Sub 2 Sub
3 Sub4 Sub 5 Class
* * * * * ** * * * * ** * * * * ** * * * * **
* * * * ** * * * * ** * * * * ** * * *
1 RAM
54 55 56 57 58 B
2 RAJ 64 65 66 67 68 A
3 YOGI
94 95 96 97 98 O
4 KAVYA 89 92 94 96 98 O
5 DEEPA 67 78 89 99 98 O
* * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * ** * * * * ** * * * * *