Husna Dental is a personal dental clinic that recently operated on 1st January 2015. The payment for
dentistry services at Husna Dental is different based on the type of treatment and patient status.
Types of Treatment and Price
Patient Status Restoration(1) Extraction(2) Scaling(3)
Children(C) RM6.00 RM15.50 RM4.00
Adult(A) RM7.50 RM18.00 RM5.00
Due to the opening ceremony, the discount of 20% will be given for children’s treatment and 15%
discount for adult’s treatment.
Write a C++ program that performs the following.
· Reads the patient's name, patient status, and type of treatment.
· Displays the appropriate message when the user enters an invalid status.
· Calculates the payment before and after discount.
· At the end of the program, displays receipt that contain patient’s name and her/his total
payment after discount.
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;
int main() {
string name;
int treatment;
char status;
double payment, discount, tot_payment;
cout << "Enter a client's name: ";
getline(cin, name);
do {
cout << "Enter client status Children or Adult: ";
cin >> status;
status = toupper(status);
if (status != 'A' && status != 'C') {
cout << "Incorrect input, status should be A or C" << endl;
}
} while (status != 'A' && status != 'C');
cout << "Enter a treatment" << endl;
do {
cout << "Restoration(1) Extraction(2) Scaling(3): ";
cin >> treatment;
if (treatment < 1 || treatment > 3) {
cout << "Incorrect input, treatment must be 1, 2, or 3" << endl;
}
} while (treatment < 1 || treatment > 3);
if (treatment == 1) {
payment = (status == 'C') ? 6.0 : 7.5;
}
else if (treatment == 2) {
payment = (status == 'C') ? 15.5 : 18.0;
}
else {
payment = (status == 'C') ? 4.0 : 5.0;
}
discount = (status == 'C') ? 0.2 : 0.15;
tot_payment = payment * (1 - discount);
cout << endl;
cout << "============ Hasna Dental ============" << endl;
cout << "Patient: " << name << " (" << status << ")" <<endl;
cout << "Treatment: ";
if (treatment == 1) {
cout << "Restoration" << endl;
}
else if (treatment == 2) {
cout << "Extraction" << endl;
}
else {
cout << "Scaling" << endl;
}
cout << "Payment: RM" << setprecision(2) << fixed << payment << endl;
cout << "Discount: " << setprecision(0) << discount*100 << "%" << endl;
cout << "Total: RM" << tot_payment << endl;
cout << "======================================" << endl;
}
Comments
Leave a comment