943,547 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1073
  • C++ RSS
Dec 15th, 2008
0

Need help with overload functions

Expand Post »
Ok I have everything pretty much working except for one small detail. When I do inpatient I need to display the room charges as well as the medication and labs and services. It only displays the medication and labs and services charges but in the total includes the room charges, but is not showing them.

Thanks.

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. // Function prototypes
  6. char getChoice();
  7. double patientCharges(int, double, double, double); // In-patient
  8. double patientCharges(double, double); // Out-patient
  9.  
  10. int main()
  11. {
  12. char patientType; // I=in-patient, O=out-patient
  13. int days; // Number of days of hospital stay
  14. double roomRate, // Daily room rate
  15. medication, // Total medication charges
  16. services, // Total for tests and other services
  17. totalCharges; // Total of all charges
  18.  
  19. // Input and validate patient type
  20. cout << "This program will compute patient hospital charges.\n";
  21. cout << "Enter I for in-patient or O for out-patient: ";
  22. patientType=getChoice();
  23.  
  24.  
  25. //Process the menu selection
  26. switch (patientType)
  27. {
  28. //Inpatient
  29. case 'I':
  30. case 'i': cout << "The number of days spent in the hospital: ";
  31. cin >> days;
  32. cout << "The daily rate: ";
  33. cin >> roomRate;
  34. cout << "Charges for hospital service: ";
  35. cin >> services;
  36. cout << "Hospital medicaion charges; ";
  37. cin >> medication;
  38. cout << patientCharges (days, roomRate, services, medication) << endl;
  39. totalCharges=(days*roomRate) + services + medication;
  40. break;
  41.  
  42. //Outpatient
  43. case 'O':
  44. case 'o': cout << "Charges for hospital services: ";
  45. cin >> services;
  46. cout << "Hospital medication charges: ";
  47. cin >> medication;
  48. cout << patientCharges (services, medication) << endl;
  49. totalCharges= services + medication;
  50. }
  51.  
  52.  
  53.  
  54. // Display the billing statment
  55. cout << fixed << showpoint << setprecision(2) << endl << endl;
  56. cout << "******************************\n";
  57. if (patientType == 'I' && patientType == 'i')
  58. cout << "Room charges $" << setw(8) << days*roomRate << endl;
  59. if (services > 0.0)
  60. cout << "Lab & Services $" << setw(8) << services << endl;
  61. if (medication > 0.0)
  62. cout << "Medication $" << setw(8) << medication << endl;
  63. cout << "Total charges $" << setw(8) << totalCharges << endl;
  64. cout << "******************************\n";
  65.  
  66.  
  67.  
  68. return 0;
  69. }// End of main function
  70.  
  71. //***********************************************************
  72. // Definition of function getChoice *
  73. // Accepts and returns user's validated menu choice. *
  74. //***********************************************************
  75. char getChoice()
  76. {
  77. char letter; // Holds user's letter choice
  78.  
  79. // Get the user's choice
  80. cin >> letter;
  81.  
  82. // Validate the choice
  83. while (letter != 'I' && letter != 'i'
  84. && letter != 'O' && letter != 'o')
  85. {
  86. cout << "Enter I or O: ";
  87. cin >> letter;
  88. }
  89. // Return the choice
  90. return letter;
  91. }
  92.  
  93. /*************************************************************
  94. * patientCharge *
  95. * This function is called by main to calculate and return *
  96. * total patient charges for in-patients *
  97. *************************************************************/
  98. double patientCharges(int days, double rate, double med, double serv)
  99. {
  100.  
  101. return (days*rate) + med + serv;
  102.  
  103.  
  104. }// end overload function patientCharges
  105.  
  106. /*************************************************************
  107. * patientCharge *
  108. * This function is called by main to calculate and return *
  109. * total patient charges for out-patients *
  110. *************************************************************/
  111. double patientCharges(double med, double serv)
  112. {
  113.  
  114. return med + serv;
  115.  
  116. }// end overload function patientCharges
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
davids2004 is offline Offline
43 posts
since Nov 2008
Dec 16th, 2008
0

Re: Need help with overload functions

Got it fixed.

Changed

if (patientType == 'I' && patientType == 'i')

to

if (patientType == 'I' || patientType == 'i')

In the part that display the billing statement

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. // Function prototypes
  6. char getChoice();
  7. double patientCharges(int, double, double, double); // In-patient
  8. double patientCharges(double, double); // Out-patient
  9.  
  10. int main()
  11. {
  12. char patientType; // I=in-patient, O=out-patient
  13. int days; // Number of days of hospital stay
  14. double roomRate, // Daily room rate
  15. medication, // Total medication charges
  16. services, // Total for tests and other services
  17. totalCharges; // Total of all charges
  18.  
  19. // Input and validate patient type
  20. cout << "This program will compute patient hospital charges.\n";
  21. cout << "Enter I for in-patient or O for out-patient: ";
  22. patientType=getChoice();
  23.  
  24.  
  25. //Process the menu selection
  26. switch (patientType)
  27. {
  28. //Inpatient
  29. case 'I':
  30. case 'i': cout << "The number of days spent in the hospital: ";
  31. cin >> days;
  32. cout << "The daily rate: ";
  33. cin >> roomRate;
  34. cout << "Charges for hospital service: ";
  35. cin >> services;
  36. cout << "Hospital medicaion charges; ";
  37. cin >> medication;
  38. cout << patientCharges (days, roomRate, services, medication) << endl;
  39. totalCharges=(days*roomRate) + services + medication;
  40. break;
  41.  
  42. //Outpatient
  43. case 'O':
  44. case 'o': cout << "Charges for hospital services: ";
  45. cin >> services;
  46. cout << "Hospital medication charges: ";
  47. cin >> medication;
  48. cout << patientCharges (services, medication) << endl;
  49. totalCharges= services + medication;
  50. }
  51.  
  52.  
  53.  
  54. // Display the billing statment
  55. cout << fixed << showpoint << setprecision(2) << endl << endl;
  56. cout << "******************************\n";
  57. if (patientType == 'I' || patientType == 'i')
  58. cout << "Room charges $" << setw(8) << days*roomRate << endl;
  59. if (services > 0.0)
  60. cout << "Lab & Services $" << setw(8) << services << endl;
  61. if (medication > 0.0)
  62. cout << "Medication $" << setw(8) << medication << endl;
  63. cout << "Total charges $" << setw(8) << totalCharges << endl;
  64. cout << "******************************\n";
  65.  
  66.  
  67.  
  68. return 0;
  69. }// End of main function
  70.  
  71. //***********************************************************
  72. // Definition of function getChoice *
  73. // Accepts and returns user's validated menu choice. *
  74. //***********************************************************
  75. char getChoice()
  76. {
  77. char letter; // Holds user's letter choice
  78.  
  79. // Get the user's choice
  80. cin >> letter;
  81.  
  82. // Validate the choice
  83. while (letter != 'I' && letter != 'i'
  84. && letter != 'O' && letter != 'o')
  85. {
  86. cout << "Enter I or O: ";
  87. cin >> letter;
  88. }
  89. // Return the choice
  90. return letter;
  91. }
  92.  
  93. /*************************************************************
  94. * patientCharge *
  95. * This function is called by main to calculate and return *
  96. * total patient charges for in-patients *
  97. *************************************************************/
  98. double patientCharges(int days, double rate, double med, double serv)
  99. {
  100.  
  101. return (days*rate) + med + serv;
  102.  
  103.  
  104. }// end overload function patientCharges
  105.  
  106. /*************************************************************
  107. * patientCharge *
  108. * This function is called by main to calculate and return *
  109. * total patient charges for out-patients *
  110. *************************************************************/
  111. double patientCharges(double med, double serv)
  112. {
  113.  
  114. return med + serv;
  115.  
  116. }// end overload function patientCharges
Last edited by davids2004; Dec 16th, 2008 at 12:52 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
davids2004 is offline Offline
43 posts
since Nov 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: wxwidgets App: how to get external socket input?
Next Thread in C++ Forum Timeline: Why this simple Stack does not work with string?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC