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
|
#ifndef Person_H
#define Person_H
#include <iostream>
#include <string>
#include < fstream>
using namespace std;
class Person
{
string lname;
string fname;
char dept;
int id;
public:
Person();
Person(string L, string F, char D, int N);
void setL(string L);
void setF(string F);
void setD(char D);
void setN(int N);
string getL();
string getF();
char getD();
int getN();
void print();
};
class Employee:public Person
{
float hour;
float rate;
public:
Employee();
Employee(string L, string F, char D, int N, float hour, float rate);
void setH(float h);
void setR(float r);
float getH();
float getR();
virtual float cal_salary();
void print();
};
class Student:public Person // I WANT TO USE THIS ONE (IS IT CORRECT???)
{
double gpa;
float credit;
public:
Student(string L, string F, float credit, int i = 0, double g = 0.0)
void print()
#endif
#include "Person.h"
Person::Person()
{
}
Person::Person(string L, string F, char D, int N)
{
lname = L;
fname = F;
dept = D;
id = N;
}
void Person::setF(string F) { fname = F; }
void Person::setL(string L) { lname = L; }
void Person::setD(char D) { dept = D; }
void Person::setN(int N) { id = N; }
string Person::getL() {return lname;}
string Person::getF() {return fname;}
char Person::getD() {return dept;}
int Person::getN() {return id;}
void Person::print()
{
cout << fname <<" "<< lname <<" "<< dept <<" "<< id;
}
Employee::Employee()
{
}
Employee::Employee(string L, string F, char D, int N, float hour, float rate)
{
lname = L;
fname = F;
dept = D;
id = N;
hour = H;
rate = R;
}
void Employee::setH(float H) { hour = H; }
void Employee::setR(float R) { rate = R; }
string Employee::getH() {return H;}
string Employee::getR() {return R;}
void Employee::print()
{
Person::print();
cout<<" "<<
}
float Employee::cal_salary()
{
if (hour > 40)
return 40*rate + (hour-40)*rate*1.5;
else
hour *rate;
}
Student::Student()
{
}
Student::Student(string L, string F, int i = 0, double g = 0.0) : Person(L, F, i), gpa(g) {}
{
lname = L;
fname = F;
dept = D;
id = N;
credit = C;
}
void Student::setC(float C) { credit = C; }
float Student::getC() { return C; }
void Student::print()
{
Person::print();
cout << "GPA: " << gpa << endl; }
};
#include "Person.h"
void main()
{
const int STUDENTS = 3; // Try changing this value
Student aStudent[STUDENTS]; // Array of students 0..STUDENTS-1
char aString[80]; // Temporary variable to store name
double aDouble; // Temporary variable to store GPA
// Ask user for student data...
for (int i=0; i < STUDENTS; i++)
{
cout << "\n\nStudent " << i+1 << endl;
cout << "Enter Name: ";
cin >> aString;
aStudent[i].setFirstName(aString);
cin >> aString;
aStudent[i].setLastName(aString);
cout << "Enter GPA : ";
cin >> aDouble;
aStudent[i].setGPA(aDouble);
// ** Input and set additional variables here **
}
// Output all student data
cout << "\n\nHere's all the data:\n";
for (int j=0; j < STUDENTS; j++)
{
cout << "\n\nStudent " << j+1 << endl;
aStudent[j].showInfo();
}
cout << "\nGOODBYE!\n";
return 0;
}
|