#include<iostream.h>
#include<stdio.h>
#include<time.h>
struct datetype{
int day,month,year;
};
class person{
protected:
long int CPRnum;
char name[30];
char address[50];
datetype date_birth;
char gender;
public:
person();
void inputdetails();
long int getCPR();
virtual void display();
datetype age();
};
person:erson(){
CPRnum=0;
name=" ";
address=" ";
date_birth.day=date_birth.month=date_birth.year=0;
gender=' ';
}
void person::inputdetails(){
cout<<"Input the name :\n";
gets(name);
cout<<"Enter CPR number\n";
cin>>CPRnum;
cout<<"Enter the address:\n";
gets(address);
cout<<"Enter date of birh:\n";
cin>>date_birth.day>>date_birth.month>>date_birth. year;
cout<<"Enter the gender(m for male/f for female)\n";
cin>>gender;
}
int person::getCPR(){
return CPRnum;
}
virtual void person::display(){
datetype ff;
ff=age();
cout<<"name: "<<name<<end;
cout<<"CPR number: "<<getCPRnum()<<endl;
cout<<"Address: "<<adrress<<endl;
cout<<"date of birth: "<<date_birth.day<<"/"<<date_birth.month<<"/"<<date_birth.year<<endl;
cout<<"age:"<<ff.day<<"days "<<ff.month<<"months "<<ff.year<<"years"<<endl;
cout<<"gender: "<<gender<<endl;
}
datetype person::age(){
int m1,y1;
int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
datetype D,diff;
struct tm *local;
tm_t t;
t=time(NULL);
local=localtime(&t);
D.day=local->tm_mday;
D.month=local->tm_mon+1;
D.year=local->tm_year+1900;
if(date_birth.day>=D.day){
diff.day=date_birth.day-D.day;
m1=date_birth.month;
}
else{
if((D.month==2)&&(D.year%4==0))
days[2]=29;
diff.day=days[D.month]-D.day+date_birth.day;
m1=date.month-1;
}
if(D.month<=m1){
diff.month=m1-D.month;
y1=date_birth.year;
else{
diff.month=m1+12-D.month;
y1=date_birth.year-1;
}
diff.year=y1-D.year;
return diff;
}
// --------------------------------------------------------------
struct coursetype{
int coursenum;
char coursename[10];
int credit;
float grade;
};
class studentublic person{
private:
long int studentnum;
char major[15];
coursetype courses[6];
float GPA;
public:
void inputstudentdetails();
float calculatGPA();
long getstudentnum();
float getGPA();
void getstudentnum();
void showreselt();
virtual void display(){
char gg[2];
cout<<"Name:";
puts(name);
cout<<endl;
cout<<"CPR #:"<<CPRnum<<endl;
cout<<"Student #"<<getstudentnum()<<endl;
cout<<"Address:"<<address<<endl;
cout<<"Birthday:"<<date_birth.day<<"/"<<date_birth.month<<"/"<<date_birth.year<<endl;
cout<<"gender:"<<gender<<endl;
cout<<" Major:"<<major<<endl;
cout<<"GPA:"<<getGPA()<<endl;
cout<<"course name"<<" credit grade"<<endl;
for(int j=0;j<6;j++){
cout<<"----------------------------------------------\n";
puts(courses[j].coursename);
cout<<courses[j].coursenum<<" "<<courses[j].credit<<" ";
if(courses[j].grade>=90)
gg[j]="A";
else if(courses[j].grade>=87)
gg[j]="A-";
else if(courses[j].grade>=84)
gg[j]="B+";
else if(courses[j].grade>=80)
gg[j]="B";
else if(courses[j].grade>=77)
gg[j]="B-";
else if(courses[j].grade>=74)
gg[j]="C+";
else if(courses[j].grade>=70)
gg[j]="C";
else if(courses[j].grade>=67)
gg[j]="C-";
else if(courses[j].grade>=64)
gg[j]="D+";
else if(courses[j].grade>=60)
gg[j]="D";
else
gg[j]="F";
puts(gg[i]);}
};
void student::inputstudentdetails(){
cout<<"Enter student number:\n";
cin>>studentnum;
cout<<"Enter student major:\n";
gets(major);
cout<<"Enter the courses:\n";
for(int i=0;i<6;i++){
cout<<"Enter course number:\n";
cin>>courses[i].coursenum;
cout>>"Enter course name:\n";
gets(courses[i].coursename);
cout<<"Enter the course credit:\n";
cin>>courses[i].credit;
cout<<"Enter the course grade:\n";
cin>>courses[i].grade;
}
}
float student::calculatGPA(){
float G[6],g=0.0,gpa;
int c=0; for(int i=0;i<6;i++){
if(courses[i].grade>=90)
G[i]=4;
else if(courses[i].grade>=87)
G[i]=3.67;
else if(courses[i].grade>=84)
G[i]=3.33;
else if(courses[i].grade>=80)
G[i]=3;
else if(courses[i].grade>=77)
G[i]=2.67;
else if(courses[i].grade>=74)
G[i]=2.33;
else if(courses[i].grade>=70)
G[i]=2;
else if(courses[i].grade>=67)
G[i]=1.67;
else if(courses[i].grade>=64)
G[i]=1.33;
else if(courses[i].grade>=60)
G[i]=1;
else
G[i]=0;
c+=(courses[i].credit);
g=g+(G[i]*courses[i].credit);
}
gpa=(float)g/c;
return gpa;
}
long student::getstudentnum(){
return studentnum;
}
float student::getGPA(){
return GPA;
}
void student::showreselt(){
cout<<"GPA:"<<getGPA()<<endl;
cout<<"course name"<<" credit grade"<<endl;
for(int j=0;j<6;j++){
cout<<"----------------------------------------------\n";
puts(courses[j].coursename);
cout<<courses[j].coursenum<<" "<<courses[j].credit<<" ";
if(courses[j].grade>=90)
gg[j]="A";
else if(courses[j].grade>=87)
gg[j]="A-";
else if(courses[j].grade>=84)
gg[j]="B+";
else if(courses[j].grade>=80)
gg[j]="B";
else if(courses[j].grade>=77)
gg[j]="B-";
else if(courses[j].grade>=74)
gg[j]="C+";
else if(courses[j].grade>=70)
gg[j]="C";
else if(courses[j].grade>=67)
gg[j]="C-";
else if(courses[j].grade>=64)
gg[j]="D+";
else if(courses[j].grade>=60)
gg[j]="D";
else
gg[j]="F";
puts(gg[j]);}}
//-------------------------------------------------------------------------
int main(){
person pp;
student ss;
int choice=7;
cout<<"Enter your choice number:\n-1-input student details\n-2-input person details\n-3-calculat GPA\n-4-show reselt\n-5-display(-1 to end)\n";
cin>>choice;
while(choice!=-1){
switch(choice){
case 1:ss.inputstudentdetails();break;
case 2p.inputdetails();break;
case 3:ss.calculatGPA();break;
case 4:ss.showreselt();break;
case 5:ss.display();break;
}
cout<<"Enter your choice number:\n-1-input student details\n-2-input person details\n-3-calculat GPA\n-4-show reselt\n-5-display(-1 to end)\n";
cin>>choice;
}
return 0;
}