Code: Select all
#include<iostream>
#include<stdio.h>
using namespace std;
class Person{
protected:
unsigned long int ssn;
char name[30];
public:
Person():ssn(1){strcpy(name,"hi");}
Person(int ssln, char n[]):ssn(ssln){strcpy(name,n);}
~Person(){}
char* get_name(){return name;}
int get_ssn(){return ssn;}
};
class Student: public Person{
private:
float g1,g2,g3,g4,avg;
public:
Student():Person(),g1(1),g2(1),g3(1),g4(1){}
Student(int ssln, char n[], float grade1, float grade2, float grade3, float grade4):Person(ssln,n),g1(grade1),g2(grade2),g3(grade3),g4(grade4){}
~Student(){}
void set_ssn(){int ssln;cout<<"\nEnter your Social Security number\n";cin>>ssln;ssn=ssln;}
void set_name(){char na[30];cout<<"\nEnter your name\n";getchar();gets(na);strcpy(name, na);}
void set_g1(){float grade1;cout<<"\nEnter grade 1\n";cin>>grade1;g1=grade1;}
void set_g2(){float grade2;cout<<"\nEnter grade 2\n";cin>>grade2;g2=grade2;}
void set_g3(){float grade3;cout<<"\nEnter grade 3\n";cin>>grade3;g3=grade3;}
void set_g4(){float grade4;cout<<"\nEnter grade 4\n";cin>>grade4;g4=grade4;}
void set_ssn(unsigned long int ssln){ssn=ssln;}
void set_name(const char* n){strcpy(name,n);}
void set_g1(float gr1){g1=gr1;}
void set_g2(float gr2){g2=gr2;}
void set_g3(float gr3){g3=gr3;}
void set_g4(float gr4){g4=gr4;}
void set_avg(float avgtmp){avg=avgtmp;}
float get_g1(){return g1;}
float get_g2(){return g2;}
float get_g3(){return g3;}
float get_g4(){return g4;}
void set_avg(){avg=((g1+g2+g3+g4)/4);}
float get_avg(){return avg;}
void printall(){cout<<"\nName: "<<name<<"\nSSN: "<<ssn<<"\nGrade Average: "<<avg<<"\n";}
};
class Teacher: public Person{
private:
float gsal,netsal;
public:
Teacher():Person(),gsal(1){}
Teacher(int ssln, char n[], float grssal):Person(ssln,n),gsal(grssal){}
~Teacher(){}
void set_ssn(){unsigned long int ssln;cout<<"\nEnter Social Security Number\n";cin>>ssln;ssn=ssln;}
void set_name(){char na[30];cout<<"\nEnter your name\n";getchar();gets(na);strcpy(name, na);}
void set_name(const char* x){strcpy(name,x);}
void set_ssn(unsigned long int ssln){ssn=ssln;}
void set_gsal(){float grssal;cout<<"\nEnter your teacher's gross salary\n";cin>>grssal;gsal=grssal;}
void set_gsal(float x){gsal=x;}
void set_netsal()
{
int x=1;
while(x==1)
{
if(gsal>=50000)
{
netsal=(gsal-(gsal*.3));
x=0;
}
else if(gsal<50000&&gsal>=30000)
{
netsal=(gsal-(gsal*.2));
x=0;
}
else if(gsal<=30000&&gsal>=0)
{
netsal=(gsal-(gsal*.15));
cout<<"\n";
x=0;
}
else
x=1;
}
}
void set_netsal(int ha){netsal=ha;}
float get_netsal(){return netsal;}
float get_gsal(){return gsal;}
void printall(){cout<<"\nName: "<<name<<"\nSSN: "<<ssn<<"\nNet Salary"<<netsal<<"\n";}
};
int main(void)
{
int o=1,ssln[50],studcnt=0,tchcnt=0,sslntemp[500],array[50],u=1;
char * n[30];
float grade1[20],grade2[20],grade3[20],grade4[20],grssal[8];
int x=1;
Student newstud[20];
Teacher newteach[20];
while(x==1)
{
cout<<"\n1)Add Student\n2)Add Teacher\n3)Display all students in ascending alphabetical order\n4)Display all students from highest to lowest average\n5)Display all taechers in ascending alphabetical order\n6)Display all teachers by net salary (highest to lowest)\n7)Delete a student\n8)Delete a teacher\n9)Exit\n";
int y;
cin>>y;
switch(y)
{
//add student
case 1:
o++;
n[o] = new char[30];
cout<<"\nInput student's information. 0 to quit\n";
newstud[o].set_ssn();
newstud[o].set_name();
newstud[o].set_g1();
newstud[o].set_g2();
newstud[o].set_g3();
newstud[o].set_g4();
newstud[o].set_avg();
if(newstud[o].get_ssn()!=0&&newstud[o].get_name()!=0&&newstud[o].get_g1()!=0&&newstud[o].get_g2()!=0&&newstud[o].get_g3()!=0&&newstud[o].get_g4()!=0){
studcnt++;
cout<<"broken";}
else
break;
break;
//add teacher
case 2:
cout<<"\nInput teacher's information. 0 to quit;\n";
u++;
newteach[u].set_ssn();
newteach[u].set_name();
newteach[u].set_gsal();
newteach[u].set_netsal();
if(newteach[u].get_ssn()!=0&&newteach[u].get_name()!=0&&newteach[u].get_gsal()!=0)
{tchcnt++;}
else
{break;}
break;
//display students ascending alpha order
case 3:
for(int h=0;h<4;h++)
for(int g=h+1;g<5;g++)
if(strcmp(newstud[g].get_name(),newstud[h].get_name())<0)
{
float avgtmp;
unsigned long int ssntemp;
float g1temp,g2temp,g3temp,g4temp,avg;
char meaningful[30];
strcpy(meaningful,newstud[g].get_name());
ssntemp=newstud[g].get_ssn();
g1temp=newstud[g].get_g1();
g2temp=newstud[g].get_g2();
g3temp=newstud[g].get_g3();
g4temp=newstud[g].get_g4();
avgtmp=newstud[g].get_avg();
newstud[g].set_name(newstud[h].get_name());
newstud[g].set_ssn(newstud[h].get_ssn());
newstud[g].set_g1(newstud[h].get_g1());
newstud[g].set_g2(newstud[h].get_g2());
newstud[g].set_g3(newstud[h].get_g3());
newstud[g].set_g4(newstud[h].get_g4());
newstud[g].set_avg(newstud[h].get_avg());
newstud[h].set_name(meaningful);
newstud[h].set_ssn(ssntemp);
newstud[h].set_g1(g1temp);
newstud[h].set_g2(g2temp);
newstud[h].set_g3(g3temp);
newstud[h].set_g4(g4temp);
newstud[h].set_avg(avgtmp);
}
for(int f=0;f<studcnt;f++)
newstud[f].printall();
break;
//display students highest to lowest average
case 4:
break;
//display teachers ascending alpha order
case 5:
for(int d=0;d<4;d++)
for(int e=e+1;e<5;e++)
if(strcmp(newstud[e].get_name(),newstud[d].get_name())<0)
{
char meaningful[30];
unsigned long int ssntemp;
float gstemp;
float nettemp;
strcpy(meaningful,newteach[e].get_name());
ssntemp=newteach[e].get_ssn();
gstemp=newteach[e].get_gsal();
nettemp=newteach[e].get_netsal();
newteach[e].set_name(newstud[d].get_name());
newteach[e].set_ssn(newteach[d].get_ssn());
newteach[e].set_gsal(newteach[d].get_gsal());
newteach[e].set_netsal(newteach[d].get_netsal());
newstud[d].set_name(meaningful);
newstud[d].set_ssn(ssntemp);
newteach[d].set_gsal(gstemp);
newteach[d].set_netsal(nettemp);
}
for(int c=0;c<tchcnt;c++)
newteach[c].printall();
break;
//display teachers highest to lowest net salary
case 6:
int Swap;
for(int i=tchcnt;i>0;i--)
{
array[i]=newteach[i].get_ssn();
}
for(int p=tchcnt;p>0;p--)
{
for(int pp=tchcnt;pp>0;pp--)
{
if(array[pp]>array[pp+1])
{
Swap=array[pp];
array[pp]=array[pp+1];
array[pp+1]=Swap;
}
}
}
for(int z=tchcnt;z>0;z--)
{
cout<<"\n"<<newteach[z].get_name();
}
break;
//delete student
case 7:
cout<<"\nSpecify the social security number of the student you want to delete.\n";
int hi;
cin>>hi;
for(int q=studcnt;q>=0;q--)
{
if(hi==newstud[q].get_ssn()){
/*delete newstud[q];*/break;}
else break;
}
break;
//delete teacher
case 8:
cout<<"\nSpecify the social security number of the teacher you want to delete.\n";
int bye;
cin>>bye;
for(int q=tchcnt;q>=0;q--)
{
if(bye==newteach[q].get_ssn()){
/*delete newteach[q]*/;break;}
else continue;
}
break;
//quit program
case 9: x=0;break;
default: x=0;break;
}
}
return 0;
}