Need help with overload functions

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 43
Reputation: davids2004 is an unknown quantity at this point 
Solved Threads: 0
davids2004 davids2004 is offline Offline
Light Poster

Need help with overload functions

 
0
  #1
Dec 15th, 2008
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.

  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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 43
Reputation: davids2004 is an unknown quantity at this point 
Solved Threads: 0
davids2004 davids2004 is offline Offline
Light Poster

Re: Need help with overload functions

 
0
  #2
Dec 16th, 2008
Got it fixed.

Changed

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

to

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

In the part that display the billing statement

  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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC