And the third class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
|
//MEDICATION CLASS
#ifndef MEDICATION_H
#define MEDICATION_H
#include <string>
#include "PatientAccount.h"
using namespace std;
class Medication
{
private:
string m1,
m2,
m3,
m4,
m5,
chosenMedication;
double cost1,
cost2,
cost3,
cost4,
cost5,
chargedAmount;
public:
Medication()
{
m1 = "Canabis";
cost1 = 60.25;
m2 = "Xanax";
cost2 = 123.87;
m3 = "Bandages";
cost3 = 12.30;
m4 = "Eye drops";
cost4 = 30.20;
m5 = "Aspirine";
cost5 = 50.27;
chargedAmount = 0;
}
string getMed1() const
{ return m1; }
string getMed2() const
{ return m2; }
string getMed3() const
{ return m3; }
string getMed4() const
{ return m4; }
string getMed5() const
{ return m5; }
string getChosenMed() const
{ return chosenMedication; }
double getCost1() const
{ return cost1; }
double getCost2() const
{ return cost2; }
double getCost3() const
{ return cost3; }
double getCost4() const
{ return cost4; }
double getCost5() const
{ return cost5; }
double getChargedAmount() const
{ return chargedAmount; }
void menu()
{
int choice;
cout << "\n\n\t\t____MEDICATION MENU____\n"
<< "\n Chose in the medications below:\n"
<< "\n 1. " << m1
<< "\n 2. " << m2
<< "\n 3. " << m3
<< "\n 4. " << m4
<< "\n 5. " << m5
<< "\n\n Your choice: ";
cin >> choice;
switch(choice)
{
case 1:
chosenMedication = m1;
chargedAmount = cost1;
cout << "\n Chosen medication : " << chosenMedication
<< "\n Medication Cost : $ " << chargedAmount;
break;
case 2:
chosenMedication = m2;
chargedAmount = cost2;
cout << "\n Chosen medication : " << chosenMedication
<< "\n Medication Cost : $ " << chargedAmount;
break;
case 3:
chosenMedication = m3;
chargedAmount = cost3;
cout << "\n Chosen medication : " << chosenMedication
<< "\n Medication Cost : $ " << chargedAmount;
break;
case 4:
chosenMedication = m4;
chargedAmount = cost4;
cout << "\n Chosen medication : " << chosenMedication
<< "\n Medication Cost : $ " << chargedAmount;
break;
case 5:
chosenMedication = m5;
chargedAmount = cost5;
cout << "\n Chosen medication : " << chosenMedication
<< "\n Medication Cost : $ " << chargedAmount;
break;
default:
break;
}
cout << "\n\n Data saved...\n";
}
void updateCost(PatientAccount p)
{ p.addToTotalCharges(chargedAmount); }
};
#endif
|
This class works the same as the Surgery class except it holds names and costs of medications instead of surgeries.
Here is my program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <iostream>
#include <string>
#include <iomanip>
#include "PatientAccount.h"
#include "Surgery.h"
#include "Medication.h"
using namespace std;
void pause();
int main()
{
PatientAccount patient;
Surgery surgery;
Medication medication;
int choice;
double totalCharges,
extraCharges;
string name;
cout << showpoint << fixed << setprecision(2);
do
{
extraCharges = patient.getExtraCharges();
totalCharges = patient.getTotalCharges();
cout << "\n Total charges: $ " << totalCharges
<< "\n Extra Charges: $ " << extraCharges
<< "\n\n";
cout << "\n\t\t__________HOSPITAL MENU__________\n"
<< "\n 1. Enter Patient's Infrmation."
<< "\n 2. Enter Surgery Information."
<< "\n 3. Enter Medication Information."
<< "\n 4. Patient is Checking Out."
<< "\n 5. Exit Program."
<< "\n"
<< "\n User's Input: ";
cin >> choice;
cout << "\n\n";
cin.sync();
switch(choice)
{
case 1:
patient.getInformation();
patient.calculateTotalCharges();
break;
case 2:
surgery.menu();
surgery.updateCost(patient);
break;
case 3:
medication.menu();
medication.updateCost(patient);
break;
case 4:
name = patient.getName();
totalCharges = patient.getTotalCharges();
cout << "\n\tCHECK OUT\n"
<< "\n Name: " << name
<< "\n Total charges: $ " << totalCharges;
break;
case 5:
cout << "\n\n Exiting Program...";
choice = -1;
break;
default:
cout << "\n\n Exiting Program...";
choice = -1;
break;
};
cout << "\n\n\tDATA HAS BEEN SAVED...\n\n\n";
}
while (choice > 0);
pause();
return(0);
}
void pause()
{
cout << "\n\n\n Press ENTER to continue...";
cin.sync();
cin.get();
cout << "\n\n";
return;
}
|
My problem is: Somehow I dont manage to send the values held by
double chargedAmount
in both
the Surgery and Medication class to the
extraCharges
double in the PatientAccount class.
I do think the the problem lies within the relation between the following functions:
in PatientAccount.h
1 2
|
void addToTotalCharges(double d)
{ extraCharges += d; }
|
in Surgery.h and Medication.h
1 2
|
updateCost(PatientAccount p)
{ p.addToTotalCharges(chargedAmount); }
|
I've tried messing around with the two functions but I haven't managed to solve my problem.
When I run the program and run the first case of the
switch(choice)
function, the
totalCharges
are calculated however the
extraCharges
remain equal to 0 even after I run the other cases of the
switch function.
Any suggestion/advice would be much appreciated.
Thank you in advance,
Have a great day!