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
|
// student.cpp
#include "student.h"
// include the interface header file
Student::Student(string last, string first, string dob,
string mat, int cred, double grade)
: lastname(last), firstname(first), birthdate(dob),
matdate(mat), credits(cred), gpa(grade)
{
if(cred < 30) {
standing = "Freshman";
} else if(cred < 60) {
standing = "Sophomore";
} else if(cred < 90) {
standing = "Junior";
} else {
standing = "Senior";
}
// standing is set according to the amount of credits
// the student has. requisite values for these standings
// are according to the definitions listed
// at http://irr.gmu.edu/definitions.cfm
}
Student::Student() : lastname("Doe"), firstname("John"), standing("Freshman"),
birthdate("1/1/1990"), matdate("1/1/2008"), credits(0), gpa(4.0)
{/* intentionally empty body */}
// default constructor initializes preset values for variables
// of the Student object
string Student::getLast() const {return lastname;}
string Student::getFirst() const {return firstname;}
string Student::getStanding() const {return standing;}
string Student::getDOB() const {return birthdate;}
string Student::getMatDate() const {return matdate;}
int Student::getCredits() const {return credits;}
double Student::getGPA() const {return gpa;}
void Student::input() {
string last, first, stand, dob, mat;
int credits;
double grade;
cout << "Last name: ";
cin >> last;
cout << "First name: ";
cin >> first;
cout << "DOB: ";
cin >> dob;
cout << "Matriculation Date: ";
cin >> mat;
cout << "Credits: ";
cin >> credits;
cout << "GPA: ";
cin >> grade;
setLast(last);
setFirst(first);
setDOB(dob);
setMatDate(mat);
setCredits(credits);
setGPA(grade);
// all mutator functions are used by input()
return;
} // input function accepts all vars from the user except standing
void Student::output() const {
cout << "Last name: " << getLast() << endl;
cout << "First name: " << getFirst() << endl;
cout << "Standing: " << getStanding() << endl;
cout << "DOB: " << getDOB() << endl;
cout << "Matriculation Date: " << getMatDate() << endl;
cout << "Credits: " << getCredits() << endl;
cout << "GPA: " << getGPA() << endl;
return;
} // output function prints all vars
void Student::setLast(string name) {
lastname = name;
}
void Student::setFirst(string name) {
firstname = name;
}
void Student::setDOB(string date) {
birthdate = date;
}
void Student::setMatDate(string date) {
matdate = date;
}
void Student::setCredits(int cred) {
credits = cred;
if(cred < 30) {
standing = "Freshman";
} else if(cred < 60) {
standing = "Sophomore";
} else if(cred < 90) {
standing = "Junior";
} else {
standing = "Senior";
}
}
void Student::setGPA(double grade) {
gpa = grade;
}
bool operator ==(Student& s1, Student& s2) {
return (s1.firstname == s2.firstname && s1.lastname == s2.lastname);
}
|