| | |
Need help with overload functions
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 43
Reputation:
Solved Threads: 0
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.
Thanks.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> using namespace std; // Function prototypes char getChoice(); double patientCharges(int, double, double, double); // In-patient double patientCharges(double, double); // Out-patient int main() { char patientType; // I=in-patient, O=out-patient int days; // Number of days of hospital stay double roomRate, // Daily room rate medication, // Total medication charges services, // Total for tests and other services totalCharges; // Total of all charges // Input and validate patient type cout << "This program will compute patient hospital charges.\n"; cout << "Enter I for in-patient or O for out-patient: "; patientType=getChoice(); //Process the menu selection switch (patientType) { //Inpatient case 'I': case 'i': cout << "The number of days spent in the hospital: "; cin >> days; cout << "The daily rate: "; cin >> roomRate; cout << "Charges for hospital service: "; cin >> services; cout << "Hospital medicaion charges; "; cin >> medication; cout << patientCharges (days, roomRate, services, medication) << endl; totalCharges=(days*roomRate) + services + medication; break; //Outpatient case 'O': case 'o': cout << "Charges for hospital services: "; cin >> services; cout << "Hospital medication charges: "; cin >> medication; cout << patientCharges (services, medication) << endl; totalCharges= services + medication; } // Display the billing statment cout << fixed << showpoint << setprecision(2) << endl << endl; cout << "******************************\n"; if (patientType == 'I' && patientType == 'i') cout << "Room charges $" << setw(8) << days*roomRate << endl; if (services > 0.0) cout << "Lab & Services $" << setw(8) << services << endl; if (medication > 0.0) cout << "Medication $" << setw(8) << medication << endl; cout << "Total charges $" << setw(8) << totalCharges << endl; cout << "******************************\n"; return 0; }// End of main function //*********************************************************** // Definition of function getChoice * // Accepts and returns user's validated menu choice. * //*********************************************************** char getChoice() { char letter; // Holds user's letter choice // Get the user's choice cin >> letter; // Validate the choice while (letter != 'I' && letter != 'i' && letter != 'O' && letter != 'o') { cout << "Enter I or O: "; cin >> letter; } // Return the choice return letter; } /************************************************************* * patientCharge * * This function is called by main to calculate and return * * total patient charges for in-patients * *************************************************************/ double patientCharges(int days, double rate, double med, double serv) { return (days*rate) + med + serv; }// end overload function patientCharges /************************************************************* * patientCharge * * This function is called by main to calculate and return * * total patient charges for out-patients * *************************************************************/ double patientCharges(double med, double serv) { return med + serv; }// end overload function patientCharges
•
•
Join Date: Nov 2008
Posts: 43
Reputation:
Solved Threads: 0
Got it fixed.
Changed
if (patientType == 'I' && patientType == 'i')
to
if (patientType == 'I' || patientType == 'i')
In the part that display the billing statement
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)
#include <iostream> #include <iomanip> using namespace std; // Function prototypes char getChoice(); double patientCharges(int, double, double, double); // In-patient double patientCharges(double, double); // Out-patient int main() { char patientType; // I=in-patient, O=out-patient int days; // Number of days of hospital stay double roomRate, // Daily room rate medication, // Total medication charges services, // Total for tests and other services totalCharges; // Total of all charges // Input and validate patient type cout << "This program will compute patient hospital charges.\n"; cout << "Enter I for in-patient or O for out-patient: "; patientType=getChoice(); //Process the menu selection switch (patientType) { //Inpatient case 'I': case 'i': cout << "The number of days spent in the hospital: "; cin >> days; cout << "The daily rate: "; cin >> roomRate; cout << "Charges for hospital service: "; cin >> services; cout << "Hospital medicaion charges; "; cin >> medication; cout << patientCharges (days, roomRate, services, medication) << endl; totalCharges=(days*roomRate) + services + medication; break; //Outpatient case 'O': case 'o': cout << "Charges for hospital services: "; cin >> services; cout << "Hospital medication charges: "; cin >> medication; cout << patientCharges (services, medication) << endl; totalCharges= services + medication; } // Display the billing statment cout << fixed << showpoint << setprecision(2) << endl << endl; cout << "******************************\n"; if (patientType == 'I' || patientType == 'i') cout << "Room charges $" << setw(8) << days*roomRate << endl; if (services > 0.0) cout << "Lab & Services $" << setw(8) << services << endl; if (medication > 0.0) cout << "Medication $" << setw(8) << medication << endl; cout << "Total charges $" << setw(8) << totalCharges << endl; cout << "******************************\n"; return 0; }// End of main function //*********************************************************** // Definition of function getChoice * // Accepts and returns user's validated menu choice. * //*********************************************************** char getChoice() { char letter; // Holds user's letter choice // Get the user's choice cin >> letter; // Validate the choice while (letter != 'I' && letter != 'i' && letter != 'O' && letter != 'o') { cout << "Enter I or O: "; cin >> letter; } // Return the choice return letter; } /************************************************************* * patientCharge * * This function is called by main to calculate and return * * total patient charges for in-patients * *************************************************************/ double patientCharges(int days, double rate, double med, double serv) { return (days*rate) + med + serv; }// end overload function patientCharges /************************************************************* * patientCharge * * This function is called by main to calculate and return * * total patient charges for out-patients * *************************************************************/ double patientCharges(double med, double serv) { return med + serv; }// end overload function patientCharges
Last edited by davids2004; Dec 16th, 2008 at 12:52 am.
![]() |
Similar Threads
- Overloading PHP Functions (PHP)
- copy constructor & assignment operator overload problems (C++)
- need help overloading =, >>, << (C++)
- overload functions (C++)
- Trying to overload + for class to add to string 'is illegal' (C)
- Need to know hwo to go about this (classes/accessor functions) (C++)
- How to write FNVAL functions (Java)
Other Threads in the C++ Forum
- Previous Thread: wxwidgets App: how to get external socket input?
- Next Thread: Why this simple Stack does not work with string?
| Thread Tools | Search this Thread |
api array based beginner bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project python random read recursion recursive return sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





