Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 895|回复: 2
打印 上一主题 下一主题

C++ programming

[复制链接]

10

主题

0

好友

984

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

跳转到指定楼层
1#
发表于 2013-7-3 09:00 PM |只看该作者 |倒序浏览
本帖最后由 nbaball 于 2013-7-3 09:02 PM 编辑

小弟在做着 c++ assignment, 可是现在 stuck 着了,希望有高手可以指教指教
  1. #include<iostream>
  2. #include<string>
  3. #include<iomanip>

  4. using namespace std;

  5. //Class Person
  6. class Person{
  7. private:
  8.    string firstName; //variable to store the first name
  9.    string lastName; //variable to store the last name
  10. public:
  11.         Person(string first = "", string last = "");
  12.        
  13.         void displayName() const;
  14.         void setName(string first, string last);
  15.         string getFirstName() const;
  16.         string getLastName() const;

  17. };

  18. void Person::displayName() const{
  19.   cout << "First Name : " << firstName << endl << "Last Name : " << lastName << endl;
  20. }
  21. void Person::setName(string first, string last){
  22.   firstName = first;
  23.   lastName = last;
  24. }
  25. string Person::getFirstName() const{
  26.   return firstName;
  27. }
  28. string Person::getLastName() const{
  29.   return lastName;
  30. }
  31. //constructor
  32. Person::Person(string first, string last){
  33.   firstName = first;
  34.   lastName = last;
  35. }

  36. //Class Date
  37. class Date{
  38. private:
  39.   int dMonth; //variable to store the month
  40.   int dDay; //variable to store the day
  41.   int dYear; //variable to store the year
  42. public:
  43.   void setDate(int month, int day, int year);
  44.   int getDay() const;
  45.   int getMonth() const;
  46.   int getYear() const;
  47.   void printDate() const;
  48.   Date(int month = 1, int day = 1, int year = 1900);
  49. };

  50. void Date::setDate(int month, int day, int year){
  51. dMonth = month;
  52. dDay = day;
  53. dYear = year;
  54. }

  55. int Date::getDay() const{return dDay;}
  56. int Date::getMonth() const{return dMonth;}
  57. int Date::getYear() const{return dYear;}

  58. void Date::printDate() const{
  59. cout << dMonth << "-" << dDay << "-" << dYear;
  60. }

  61. Date::Date(int month, int day, int year){
  62. dMonth = month;
  63. dDay = day;
  64. dYear = year;
  65. }


  66. //Class Doctor
  67. class Doctor : public Person{
  68. private:
  69.         string speciality,position;
  70. public:
  71.        
  72.         Doctor(string speciality ="",string position = "");
  73.        
  74.         string getSpeciality();
  75.         string getPosition();

  76.         void setSpeciality(string newSpeciality);
  77.         void setPosition(string newPosition);

  78.         void createDoctor();
  79.         void displayDoctorDetail();

  80. };

  81. string Doctor::getSpeciality(){return speciality;}
  82. string Doctor::getPosition(){return position;}

  83. void Doctor::setSpeciality(string newSpeciality){
  84.         speciality = newSpeciality;}
  85. void Doctor::setPosition(string newPosition){
  86.         position = newPosition;}

  87. void Doctor::createDoctor(){

  88.         string firstName, lastName;

  89.         cout << "Please enter the name of the Doctor" << endl;
  90.         cout << "First Name : ";
  91.         cin >> firstName;
  92.         cout << endl;
  93.         cout << "Last Name : ";
  94.         getline(cin,lastName);
  95.         cout << endl;
  96.         setName(firstName, lastName);

  97.         cout << "Speciality : ";
  98.         cin >> speciality;
  99.         cout << endl << "Position : ";
  100.         cin >> position;
  101. }
  102. void Doctor::displayDoctorDetail(){

  103.         displayName();
  104.         cout << "Speciality : " << getSpeciality() << endl;
  105.         cout << "Postion : " << getPosition() << endl;

  106. }


  107. //Class Patient
  108. class Patient:public Person{
  109. private:
  110.         string patientID;
  111.         int patientAge;
  112. public:
  113.         Date dob;
  114.         Date admitted;
  115.         Date discharged;

  116.         int getAge();
  117.         string getID();

  118.         void setAge(int newAge);
  119.         void setID(string newID);

  120.         void newPatient();
  121.         void displayPatient();
  122.        
  123. };

  124. int Patient::getAge(){return patientAge;}
  125. string Patient::getID(){return patientID;}

  126. void Patient::setAge(int newAge){
  127.         patientAge = newAge;}
  128. void Patient::setID(string newID){
  129.         patientID = newID;}

  130. void Patient::newPatient(){

  131.         string firstName,lastName;
  132.         int dobDay,dobMonth,dobYear,admittedDay,admittedMonth,admittedYear,dischargedDay,dischargedMonth,dischargedYear;

  133.         cout << "Please enter the Patient Name" << endl;
  134.         cout << "First Name : ";
  135.         cin >> firstName;
  136.         cout << endl << "Last Name : ";
  137.         getline(cin,lastName);
  138.         setName(firstName,lastName);

  139.         cout << endl << "Please enter the Patient ID" << endl;
  140.         cout << "Patient ID : ";
  141.         cin >> patientID;
  142.         setID(patientID);

  143.         cout << endl << "Please enter the Patient Age" << endl;
  144.         cout << "Patient Age : ";
  145.         cin >> patientAge;
  146.         setAge(patientAge);

  147.         cout << "Please enter date of birthday of the patient" << endl;
  148.         cout << "Day : ";
  149.         cin >> dobDay;
  150.         cout << endl << "Month : ";
  151.         cin >> dobMonth;
  152.         cout << endl << "Year : ";
  153.         cin >> dobYear;
  154.         dob.setDate(dobDay,dobMonth,dobYear);

  155.         cout << "Please enter the admitted date of the patient" << endl;
  156.         cout << "Day : ";
  157.         cin >> admittedDay;
  158.         cout << endl << "Month : ";
  159.         cin >> admittedMonth;
  160.         cout << endl << "Year : ";
  161.         cin >> admittedYear;
  162.         admitted.setDate(admittedDay,admittedMonth,admittedYear);

  163.         cout << "Please enter the discharged date of the patient" << endl;
  164.         cout << "Day : ";
  165.         cin >> dischargedDay;
  166.         cout << endl << "Month : ";
  167.         cin >> dischargedMonth;
  168.         cout << endl << "Year : ";
  169.         cin >> dischargedYear;
  170.         discharged.setDate(dischargedDay,dischargedMonth,dischargedYear);
  171. }
  172. void Patient::displayPatient(){

  173.         displayName();
  174.         cout << "Patient Age : " << getAge() << endl;
  175.         cout << "Patient ID : " << getID() << endl;
  176.         dob.printDate();
  177.         admitted.printDate();
  178.         discharged.printDate();

  179. }

  180. class Bill{
  181. private:
  182.         float charges;
  183.         float medicineFees;
  184.         float doctorFees;
  185.         float roomCharge;
  186. public:

  187.         Bill(float charges = 0, float medicineFees = 0, float doctorFees = 0, float roomCharge = 0);

  188.         Patient p;
  189.         Doctor d;

  190.         float getCharges();
  191.         float getMedicineFees();
  192.         float getDoctorFees();
  193.         float getroomCharge();

  194.         void setCharges(float newCharge);
  195.         void setMedicineFees(float newMedicineFees);
  196.         void setDoctorFees(float newDoctorFees);
  197.         void setRoomCharge(float newRoomCharge);

  198.         void generateBill();
  199.         void displayBill();

  200. };

  201. Bill::Bill(float newCharges,float newMedicineFees,float newDoctorFees,float newRoomCharge){
  202.         charges = newCharges;
  203.         medicineFees = newMedicineFees;
  204.         doctorFees = newDoctorFees;
  205.         roomCharge = newRoomCharge;}

  206. float Bill::getCharges(){return charges;}
  207. float Bill::getMedicineFees(){return medicineFees;}
  208. float Bill::getDoctorFees(){return doctorFees;}
  209. float Bill::getroomCharge(){return roomCharge;}

  210. void Bill::setCharges(float newCharge){
  211.         charges = newCharge;}
  212. void Bill::setMedicineFees(float newMedicineFees){
  213.         medicineFees = newMedicineFees;}
  214. void Bill::setDoctorFees(float newDoctorFees){
  215.         doctorFees = newDoctorFees;}
  216. void Bill::setRoomCharge(float newRoomCharge){
  217.         roomCharge = newRoomCharge;}

  218. void Bill::generateBill(){

  219.         p.newPatient();
  220.         d.createDoctor();

  221. }

  222. void printMenu(){

  223.         cout << "Please select which option you want to select\n"
  224.                  << "1. Create Bill\n";
  225. }

  226. int main(){

  227.         Bill b;
  228.        
  229.         int option;

  230.         do{
  231.         printMenu();
  232.         cin >> option;
  233.         switch(option)
  234.         {
  235.         case 1:
  236.                 b.generateBill();
  237.                 break;
  238.         }
  239.         }while(option != 5);



  240.         cin.get();
  241.         cin.ignore(1,'\n');

  242.         return 0;

  243. }
复制代码
我不可以用 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)'




收藏收藏0

68

主题

9

好友

4021

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

2#
发表于 2013-7-4 09:41 AM |只看该作者
本帖最后由 独爱苹果 于 2013-7-4 09:42 AM 编辑

你Doctor的constructor跑去哪里了,你在class里面那个只是set了default data。
  1. Doctor::Doctor(string speciality, string position)
  2. {
  3.     speciality = " ";
  4.     position = " ";
  5. }
复制代码
加这个下去就行了。


回复

使用道具 举报

10

主题

0

好友

984

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

3#
发表于 2013-7-4 05:10 PM |只看该作者
独爱苹果 发表于 2013-7-4 09:41 AM
你Doctor的constructor跑去哪里了,你在class里面那个只是set了default data。加这个下去就行了。

谢谢你的回复,万分感激。。


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-12-26 03:14 PM , Processed in 0.104563 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部