- 分享
- 0
- 人气
- 0
- 主题
- 10
- 帖子
- 533
- UID
- 356583
- 积分
- 984
- 阅读权限
- 17
- 注册时间
- 2010-10-5
- 最后登录
- 2018-9-5
- 在线时间
- 12821 小时
|
本帖最后由 nbaball 于 2013-7-3 09:02 PM 编辑
小弟在做着 c++ assignment, 可是现在 stuck 着了,希望有高手可以指教指教- #include<iostream>
- #include<string>
- #include<iomanip>
- using namespace std;
- //Class Person
- class Person{
- private:
- string firstName; //variable to store the first name
- string lastName; //variable to store the last name
- public:
- Person(string first = "", string last = "");
-
- void displayName() const;
- void setName(string first, string last);
- string getFirstName() const;
- string getLastName() const;
- };
- void Person::displayName() const{
- cout << "First Name : " << firstName << endl << "Last Name : " << lastName << endl;
- }
- void Person::setName(string first, string last){
- firstName = first;
- lastName = last;
- }
- string Person::getFirstName() const{
- return firstName;
- }
- string Person::getLastName() const{
- return lastName;
- }
- //constructor
- Person::Person(string first, string last){
- firstName = first;
- lastName = last;
- }
- //Class Date
- class Date{
- private:
- int dMonth; //variable to store the month
- int dDay; //variable to store the day
- int dYear; //variable to store the year
- public:
- void setDate(int month, int day, int year);
- int getDay() const;
- int getMonth() const;
- int getYear() const;
- void printDate() const;
- Date(int month = 1, int day = 1, int year = 1900);
- };
- void Date::setDate(int month, int day, int year){
- dMonth = month;
- dDay = day;
- dYear = year;
- }
- int Date::getDay() const{return dDay;}
- int Date::getMonth() const{return dMonth;}
- int Date::getYear() const{return dYear;}
- void Date::printDate() const{
- cout << dMonth << "-" << dDay << "-" << dYear;
- }
- Date::Date(int month, int day, int year){
- dMonth = month;
- dDay = day;
- dYear = year;
- }
- //Class Doctor
- class Doctor : public Person{
- private:
- string speciality,position;
- public:
-
- Doctor(string speciality ="",string position = "");
-
- string getSpeciality();
- string getPosition();
- void setSpeciality(string newSpeciality);
- void setPosition(string newPosition);
- void createDoctor();
- void displayDoctorDetail();
- };
- string Doctor::getSpeciality(){return speciality;}
- string Doctor::getPosition(){return position;}
- void Doctor::setSpeciality(string newSpeciality){
- speciality = newSpeciality;}
- void Doctor::setPosition(string newPosition){
- position = newPosition;}
- void Doctor::createDoctor(){
- string firstName, lastName;
- cout << "Please enter the name of the Doctor" << endl;
- cout << "First Name : ";
- cin >> firstName;
- cout << endl;
- cout << "Last Name : ";
- getline(cin,lastName);
- cout << endl;
- setName(firstName, lastName);
- cout << "Speciality : ";
- cin >> speciality;
- cout << endl << "Position : ";
- cin >> position;
- }
- void Doctor::displayDoctorDetail(){
- displayName();
- cout << "Speciality : " << getSpeciality() << endl;
- cout << "Postion : " << getPosition() << endl;
- }
- //Class Patient
- class Patient:public Person{
- private:
- string patientID;
- int patientAge;
- public:
- Date dob;
- Date admitted;
- Date discharged;
- int getAge();
- string getID();
- void setAge(int newAge);
- void setID(string newID);
- void newPatient();
- void displayPatient();
-
- };
- int Patient::getAge(){return patientAge;}
- string Patient::getID(){return patientID;}
- void Patient::setAge(int newAge){
- patientAge = newAge;}
- void Patient::setID(string newID){
- patientID = newID;}
- void Patient::newPatient(){
- string firstName,lastName;
- int dobDay,dobMonth,dobYear,admittedDay,admittedMonth,admittedYear,dischargedDay,dischargedMonth,dischargedYear;
- cout << "Please enter the Patient Name" << endl;
- cout << "First Name : ";
- cin >> firstName;
- cout << endl << "Last Name : ";
- getline(cin,lastName);
- setName(firstName,lastName);
- cout << endl << "Please enter the Patient ID" << endl;
- cout << "Patient ID : ";
- cin >> patientID;
- setID(patientID);
- cout << endl << "Please enter the Patient Age" << endl;
- cout << "Patient Age : ";
- cin >> patientAge;
- setAge(patientAge);
- cout << "Please enter date of birthday of the patient" << endl;
- cout << "Day : ";
- cin >> dobDay;
- cout << endl << "Month : ";
- cin >> dobMonth;
- cout << endl << "Year : ";
- cin >> dobYear;
- dob.setDate(dobDay,dobMonth,dobYear);
- cout << "Please enter the admitted date of the patient" << endl;
- cout << "Day : ";
- cin >> admittedDay;
- cout << endl << "Month : ";
- cin >> admittedMonth;
- cout << endl << "Year : ";
- cin >> admittedYear;
- admitted.setDate(admittedDay,admittedMonth,admittedYear);
- cout << "Please enter the discharged date of the patient" << endl;
- cout << "Day : ";
- cin >> dischargedDay;
- cout << endl << "Month : ";
- cin >> dischargedMonth;
- cout << endl << "Year : ";
- cin >> dischargedYear;
- discharged.setDate(dischargedDay,dischargedMonth,dischargedYear);
- }
- void Patient::displayPatient(){
- displayName();
- cout << "Patient Age : " << getAge() << endl;
- cout << "Patient ID : " << getID() << endl;
- dob.printDate();
- admitted.printDate();
- discharged.printDate();
- }
- class Bill{
- private:
- float charges;
- float medicineFees;
- float doctorFees;
- float roomCharge;
- public:
- Bill(float charges = 0, float medicineFees = 0, float doctorFees = 0, float roomCharge = 0);
- Patient p;
- Doctor d;
- float getCharges();
- float getMedicineFees();
- float getDoctorFees();
- float getroomCharge();
- void setCharges(float newCharge);
- void setMedicineFees(float newMedicineFees);
- void setDoctorFees(float newDoctorFees);
- void setRoomCharge(float newRoomCharge);
- void generateBill();
- void displayBill();
- };
- Bill::Bill(float newCharges,float newMedicineFees,float newDoctorFees,float newRoomCharge){
- charges = newCharges;
- medicineFees = newMedicineFees;
- doctorFees = newDoctorFees;
- roomCharge = newRoomCharge;}
- float Bill::getCharges(){return charges;}
- float Bill::getMedicineFees(){return medicineFees;}
- float Bill::getDoctorFees(){return doctorFees;}
- float Bill::getroomCharge(){return roomCharge;}
- void Bill::setCharges(float newCharge){
- charges = newCharge;}
- void Bill::setMedicineFees(float newMedicineFees){
- medicineFees = newMedicineFees;}
- void Bill::setDoctorFees(float newDoctorFees){
- doctorFees = newDoctorFees;}
- void Bill::setRoomCharge(float newRoomCharge){
- roomCharge = newRoomCharge;}
- void Bill::generateBill(){
- p.newPatient();
- d.createDoctor();
- }
- void printMenu(){
- cout << "Please select which option you want to select\n"
- << "1. Create Bill\n";
- }
- int main(){
- Bill b;
-
- int option;
- do{
- printMenu();
- cin >> option;
- switch(option)
- {
- case 1:
- b.generateBill();
- break;
- }
- }while(option != 5);
- cin.get();
- cin.ignore(1,'\n');
- return 0;
- }
复制代码 我不可以用 Doctor 和 Patient class 来做一个variable,请问是哪里出问题了?
Output Error
In function `Bill::Bill(float, float, float, float)':
undefined reference to `Doctor:octor(std::string, std::string)'
In function `Bill::Bill(float, float, float, float)':
undefined reference to `Doctor:octor(std::string, std::string)' |
|