Answer to Question #40162 in C++ for Rohit Kumar Srivastava

Question #40162
write a program in C++ to read & display information about institute (Base class) and pupil (Sub-class). using the functions take and display data along with calculating the following:

VARIABLE DATA TYPE MODE CLASS
Name char private base
Regno unsigned long private base
Class char private base
Section char private base
Grade char private base
Phy_mrk int protected base
Che_mrk int protected base
Math_mrk int protected base
Avg_mrk long private sub
Total long private sub
1
Expert's answer
2014-03-24T11:19:00-0400
#include<iostream> // cout, cin
#include <cstdlib> // system
#include <stdio.h > // getchar

#define MAX_LENGHTH 255

using namespace std;

void CopyString(char *s, char *t);


class Institute
{
private:
char Name[MAX_LENGHTH];
unsigned long Regno;
char Class[MAX_LENGHTH];
char Section[MAX_LENGHTH];
char Grade[MAX_LENGHTH];
protected:
int Phy_mrk;
int Che_mrk;
int Math_mrk;
public:

Institute(char Name[], unsigned long Regno, char Class[], char Section[], char Grade[], int Phy_mrk, int Che_mrk, int Math_mrk)
{

CopyString(&this->Name[0], Name);
this->Regno = Regno;
CopyString(&this->Class[0], Class);
CopyString(&this->Section[0], Section);
CopyString(&this->Grade[0], Grade);
this->Class[0] = '\0';
this->Section[0] = '\0';
this->Grade[0] = '\0';
this->Phy_mrk = Phy_mrk;
this->Che_mrk = Che_mrk;
this->Math_mrk = Math_mrk;
}
Institute(void)
{
this->Name[0] = '\0';
this->Regno = 0;
this->Class[0] = '\0';
this->Section[0] = '\0';
this->Grade[0] = '\0';
this->Phy_mrk = 0;
this->Che_mrk = 0;
this->Math_mrk = 0;
}

void Display(void);
void InputData(void);

};
class Pupil : public Institute
{
public:
Pupil(char Name[],
unsigned long Regno,
char Class[],
char Section[],
char Grade[],
int Phy_mrk,
int Che_mrk,
int Math_mrk
): Institute(Name, Regno, Class,Section, Grade, Phy_mrk, Che_mrk, Math_mrk)
{
Avg_mrk = (Phy_mrk + Che_mrk + Math_mrk) /3;
Total = Phy_mrk + Che_mrk + Math_mrk;
}
Pupil(void)
{
InputData();
Avg_mrk = (Phy_mrk + Che_mrk + Math_mrk) /3;
Total = Phy_mrk + Che_mrk + Math_mrk;
}
void DisplayPupil(void)
{
Display();
cout<<"Avg_mrk : "<<this->Avg_mrk<<endl;
cout<<"Total : "<<this->Total<<endl;
}
private:
long Avg_mrk;
long Total;
};

int main()
{
Pupil pul;
pul.DisplayPupil();
system("pause");
return 0;
}



void Institute::Display(void)
{
system("cls");
cout<<"Name : "<<&this->Name[0]<<endl;
cout<<"Class : "<<&this->Class[0]<<endl;
cout<<"Section : "<<&this->Section[0]<<endl;
cout<<"Grade : "<<&this->Grade[0]<<endl;
cout<<"Regno : "<<this->Regno<<endl;
cout<<"Phy_mrk : "<<this->Phy_mrk<<endl;
cout<<"Che_mrk : "<<this->Che_mrk<<endl;
cout<<"Math_mrk: "<<this->Math_mrk<<endl;
}


void Institute::InputData(void)
{
char c; int i = 0;
cout<<"Enter Name :"<<endl;
while ((c = getchar())!= '\n')
{
this->Name[i] = c;
i++;
}
this->Name[i] = '\0'; i = 0;
system("cls");
cout<<"Enter Class"<<endl;
while ((c = getchar())!= '\n')
{
this->Class[i] = c;
i++;
}
this->Class[i] = '\0'; i = 0;
system("cls");
cout<<"Enter Section"<<endl;
while ((c = getchar())!= '\n')
{
this->Section[i] = c;
i++;
}
this->Section[i] = '\0'; i = 0;
system("cls");
cout<<"Enter Grade"<<endl;
while ((c = getchar())!= '\n')
{
this->Grade[i] = c;
i++;
}
this->Grade[i] = '\0'; i = 0;
system("cls");
cout<<"Enter Regno"<<endl;
cin>>this->Regno;
system("cls");
cout<<"Enter Phy_mrk"<<endl;
cin>>this->Phy_mrk;
system("cls");
cout<<"Che_mrk"<<endl;
cin>>this->Che_mrk;
system("cls");
cout<<"Math_mrk"<<endl;
cin>>this->Math_mrk;
}

void CopyString (char *s, char *t)
{
while ((*s = *t) != '\0')
{
s++;
t++;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS