G
Guest
Hello,
I do not understand why the func getName() does not receive any data
(actually, none of the get__receive any data.
The class I am using as an almost exact example (the exception being that
there are no strings involved only ints) has setFunctions (mutators)
activate first, then the getFunctions (inspectors), then the constructor.
Any thoughts will be appreciated.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Patient
{
public:
Patient();
Patient(string fName, string lName, string idString, int bYear);
string getName() const;
int getAge() const;
string getID() const;
void setFirstName (string fname);
void setLastName (string lname);
void setID(string idString);
void setBirthYear(int bYear);
private:
string firstName;
string lastName;
string ID;
int birthYear;
};
Patient:atient() {
setFirstName("First");
setLastName("Last");
setID("123456789");
setBirthYear(9999);
}
Patient:atient(string fName, string lName, string idString, int bYear) {
setFirstName(fName);
setLastName(lName);
setID(idString);
setBirthYear(bYear);
}
string Patient::getName() const {
return lastName + ", " + firstName;
}
int Patient::getAge() const {
return birthYear;
}
string Patient::getID() const {
return ID;
}
void Patient::setFirstName(string fName) {
cout <<"In setFirstName, fName = " <<fName <<endl;
firstName = fName;
cout <<"In setFirstName, firstName = " <<firstName <<endl;
}
void Patient::setLastName(string lName) {
lastName = lName;
}
void Patient::setID(string idString) {
ID = idString;
}
void Patient::setBirthYear(int Age) {
birthYear = 2003 - Age;
}
int main()
{
cout<<"Enter patient's first name: ";
string first;
cin >> first;
cout<<"Enter patient's last name: ";
string last;
cin >> last;
cout<<"Enter SSN, no dashes: ";
string id;
cin >> id;
cout <<"Enter year of birth: ";
int birth;
cin >>birth;
Patient P(first, last, id, birth);
cout<<setw(25) <<setiosflags(ios::left)<<"Patient Name" <<setw(20)
<<setiosflags(ios::left)<<"Patient ID" <<setw(15)
<<setiosflags(ios::left)<<"Year of Birth"<<endl;
cout <<setw(25)<<setiosflags(ios::left)<<P.getName <<setw(20)
<<setiosflags(ios::left)<<P.getID <<setw(15)
<<setiosflags(ios::left)<<P.getAge<<endl;
return 0;
}
I do not understand why the func getName() does not receive any data
(actually, none of the get__receive any data.
The class I am using as an almost exact example (the exception being that
there are no strings involved only ints) has setFunctions (mutators)
activate first, then the getFunctions (inspectors), then the constructor.
Any thoughts will be appreciated.
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Patient
{
public:
Patient();
Patient(string fName, string lName, string idString, int bYear);
string getName() const;
int getAge() const;
string getID() const;
void setFirstName (string fname);
void setLastName (string lname);
void setID(string idString);
void setBirthYear(int bYear);
private:
string firstName;
string lastName;
string ID;
int birthYear;
};
Patient:atient() {
setFirstName("First");
setLastName("Last");
setID("123456789");
setBirthYear(9999);
}
Patient:atient(string fName, string lName, string idString, int bYear) {
setFirstName(fName);
setLastName(lName);
setID(idString);
setBirthYear(bYear);
}
string Patient::getName() const {
return lastName + ", " + firstName;
}
int Patient::getAge() const {
return birthYear;
}
string Patient::getID() const {
return ID;
}
void Patient::setFirstName(string fName) {
cout <<"In setFirstName, fName = " <<fName <<endl;
firstName = fName;
cout <<"In setFirstName, firstName = " <<firstName <<endl;
}
void Patient::setLastName(string lName) {
lastName = lName;
}
void Patient::setID(string idString) {
ID = idString;
}
void Patient::setBirthYear(int Age) {
birthYear = 2003 - Age;
}
int main()
{
cout<<"Enter patient's first name: ";
string first;
cin >> first;
cout<<"Enter patient's last name: ";
string last;
cin >> last;
cout<<"Enter SSN, no dashes: ";
string id;
cin >> id;
cout <<"Enter year of birth: ";
int birth;
cin >>birth;
Patient P(first, last, id, birth);
cout<<setw(25) <<setiosflags(ios::left)<<"Patient Name" <<setw(20)
<<setiosflags(ios::left)<<"Patient ID" <<setw(15)
<<setiosflags(ios::left)<<"Year of Birth"<<endl;
cout <<setw(25)<<setiosflags(ios::left)<<P.getName <<setw(20)
<<setiosflags(ios::left)<<P.getID <<setw(15)
<<setiosflags(ios::left)<<P.getAge<<endl;
return 0;
}