1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include<iostream.h>
class Student
{
public:
Student()
{}
Student(char* Name, char* s1, char* s2, char* s3, int g1, int g2, int g3)
{
name = new char [30];
name=Name;
sub1 = new char [30];
sub1=s1;
sub2 = new char [30];
sub2=s2;
sub3 = new char [30];
sub3=s3;
grade1=g1;
grade2=g2;
grade3=g3;
}
char* name;
char* sub1;
char* sub2;
char* sub3;
int grade1;
int grade2;
int grade3;
void PrintTotal(int x, int y, int z)
{cout<<x+y+z;}
void PrintAvg(int X, int Y, int Z, int n)
{cout<<(X+Y+Z)/n;}
};
main()
{
int n, g1,g2,g3;
char *sName, *sub1, *sub2, *sub3;
cout<<"How many students are there?"<<endl;
cin>>n;
sName = new char [30];
sub1 = new char [30];
sub2 = new char [30];
sub3 = new char [30];
Student *Students = new Student[n];
for (int i = 0 ; i < n ; i++)
{
//taking input.
cout<<"Enter the student name: ";
cin>>sName;
cout<<"Enter the student's first subject: ";
cin>>sub1;
cout<<"Enter the student's second subject: ";
cin>>sub2;
cout<<"Enter the student's third subject: ";
cin>>sub3;
cout<<"Enter the student's grade in "<<sub1<<" :";
cin>>g1;
cout<<"Enter the student's grade in "<<sub2<<" :";
cin>>g2;
cout<<"Enter the student's grade in "<<sub3<<" :";
cin>>g3;
cout<<"-------------------------------------"<<endl;
Student S(sName,sub1,sub2,sub3,g1,g2,g3); //generating object.
Students[i]= S; //storing objects in a pointer.
}
for (i = 0 ; i < n ; i++)
{
//printing out.
cout<<"Name: " <<Students[i].name <<endl;
cout<<"Subject 1: " <<Students[i].sub1;
cout<<" - Grade: " <<Students[i].grade1 <<endl;
cout<<"Subject 2: " <<Students[i].sub2;
cout<<" - Grade: " <<Students[i].grade2 <<endl;
cout<<"Subject 3: " <<Students[i].sub3;
cout<<" - Grade: " <<Students[i].grade3 <<endl;
cout<<"Total = "; Students[i].PrintTotal(Students[i].grade1,Students[i].grade2,Students[i].grade3); cout<<endl;
cout<<"Average = "; Students[i].PrintAvg(Students[i].grade1,Students[i].grade2,Students[i].grade3,n); cout<<endl;
cout<<"-------------------------------------"<<endl;
}
}
|