Answer to Question #192563 in C++ for ale

Question #192563

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.


Restoration(1). Extraction(2) Scaling(3)

Children(C) RM6.00 RM15.50 RM4.00

Adult(A) RM7.50 RM18.00 RM5.00


       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.

· · · ·

a) Reads the patient's name, patient status, and type of treatment.


b) Displays the appropriate message when the user enters an invalid status.


c) Calculates the payment before and after discount.


d) At the end of the program, displays receipt that contain patient’s name and her/his total payment after discount.


1
Expert's answer
2021-05-12T10:50:53-0400
#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
using namespace std;

int main() {
    string name;
    int treatment;
    char status;
    double payment, discount, tot_paiment;


    cout << "Enter a client's name: ";
    getline(cin, name);

    while (true) {
        cout << "Enter client status Children or Adult: ";
        cin >> status;
        status = toupper(status);
        if (status == 'A' || status == 'C') {
            break;
        }
        cout << "Incorrect input, enter A or C" << endl;
    }
    
    cout << "Enter a treatment" << endl;
    while (true) {
        cout << "Restoration(1) Extraction(2) Scaling(3): ";
        cin >> treatment;
        if (treatment >=1 && treatment <= 3) {
            break;
        }
        cout << "Incorrect input";
    }
    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_paiment = payment * (1 - discount);

    cout << endl;
    cout << "=======================================" << endl;
    cout << "Patioent:  " << name << 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 
         << tot_paiment << endl;
    cout << "=======================================" << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment