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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | #include<iostream.h>
#include<conio.h>
#define size 20
class person
{
protected:
char name[size];
int id;
public:
person():id(0) {name[size]=' ';}
virtual void getd();
virtual void putd();
virtual int isoutstanding()=0;
};
class student : public person
{
protected:
float gpa;
public:
student():person(){gpa=0;}
void getd();
void putd();
int isoutstanding();
};
class teacher : public person
{
protected:
int publish;
public:
teacher():person(){publish=0;}
void getd();
void putd();
int isoutstanding();
};
//defineing functions for student class
void student::getd()
{
cout<<"Enter the name of student\n";
cin.get(name,size);
cout<<"Enter ID or REG\n";
cin>>id;
cout<<"Enter gpa\n";
cin>>gpa;
}
void student::putd()
{
int i=0;
cout<<"Name of student is\n";
while(name[i]!='\0')
{
cout<<name[i];
i++;
}
cout<<"Reg or ID is\n";
cout<<id;
cout<<"gpa is\n";
cout<<gpa;
}
int student::isoutstanding()
{
if(gpa>=3.5)
return 1;
else
return 0;
}
//defineing methods of teacher
void teacher::getd()
{
cout<<"Enter the name of teacher\n";
cin.get(name,size);
cout<<"Enter ID or REG\n";
cin>>id;
cout<<"Enter number of publishes\n";
cin>>publish;
}void teacher::putd()
{
int i=0;
cout<<"Name of teacher is\n";
while(name[i]!='\0')
{
cout<<name[i];
i++;
}
cout<<"Reg or ID is\n";
cout<<id;
cout<<"Number of publish is\n";
cout<<publish;
}
int teacher::isoutstanding()
{
if(publish>=5)
return 1;
else
return 0;
}
int main()
{
person *pptr[20];
int n=0;
char choice,reply;
do
{
cout<<"Enter your choice";
cin>>choice;
if(choice=='s')
{
pptr[n] = new student;
}
else
{
pptr[n] = new teacher;
}
pptr[n]->getd();
n++;
cout<<"Do you want to run it again\n";
cin>>reply;
}
while(reply=='y');
getche();
return 0;
}
|
This blog is about my daily programming technologies I explore and work on. It contains data from my University learning materials to my Profession as Software Engineer. Programming in Asp.net, Windows Forms, JavaScript, HTML, OpenGL, Assembly Language, Dynamics CRM 2011.
Feedjit
Articles for you
Tuesday, December 31, 2013
Simplest and Easiest Inheritance in C++: Easy Implementation of Inheritance in C++ Student/Teacher Program in C++
Simplest and Easiest Inheritance in C++: Easy Implementation of Inheritance in C++ Student/Teacher Program in C++
2013-12-31T01:32:00-08:00
Saqib Khan
C++|Computer Science|F09B|Hardware Programming|Islamic University|MASM|nasm|Programming|System Programming|Visual Studio 2012|
Subscribe to:
Post Comments (Atom)