Computer Doctor


Program Listing

ComputerDoctor.cpp

/************************************************************************
*                                                                       *
*   Program:    Doctor.cpp                                              *
*                                                                       *
*   Purpose:    This program will diagnose a patient's problems, make   *
*               a recommendation, and then bill the patient             *
*                                                                       *
************************************************************************/

#include <iostream>
#include <string>

using namespace std;

int main() {

//  Greet the patient

    cout << "Well, how do you feel today?" << endl;

//  Get the patient's response

    char line[80];
    cin.getline(line, 80);
    string Response = line;

//  Act on the patient's response

    if (Response == "fine") {

    //  Patient is feeling fine

        cout << "Good, I'm glad to hear that." << endl;
        cout << "I guess you don't need a doctor." << endl;
    }
    else if (Response == "ok") {

    //  Patient is feeling ok

        cout << "Just ok?" << endl;
        cout << "Maybe you should take it easy." << endl;
        cout << "If you start feeling bad, come back and see me, ok?" << endl;
    }
    else if (Response == "awful") {

    //  Patient is feeling awful

        cout << "Really?  What seems to be the problem?" << endl;
        cin.getline(line, 80);
        Response = line;
    
    //  Find out exactly what is wrong
    
        if (Response == "I have a headache") {
            cout << "A headache?  You should take some aspirin." << endl;
        }
        else if (Response == "I think I'm going to vomit") {
            cout << "Yikes!  Get a bucket!" << endl;
        }
        else {
            cout << "Well, that's a real shame." << endl;
        }
    }
    else {

    //  Not sure how the patient feels

        cout << "You feel " << Response << '?' << endl;
        cout << "Let me know if it gets any worse, ok?" << endl;
    }

//  Be sure to bill the patient

    cout << "That will be $80.00, please.  Good-bye." << endl;
    
    return 0;
}

Sample Run #1

Well, how do you feel today?
fine
Good, I'm glad to hear that.
I guess you don't need a doctor.
That will be $80.00, please.  Good-bye.

Sample Run #2

Well, how do you feel today?
awful
Really?  What seems to be the problem?
I think I'm going to vomit
Yikes!  Get a bucket!
That will be $80.00, please.  Good-bye.

Sample Run #3

Well, how do you feel today?
pregnant
You feel pregnant?
Let me know if it gets any worse, ok?
That will be $80.00, please.  Good-bye.



Return to Lectures page


e-mail me at robbk@hsc.edu

This page was last modified on Tue Dec 7 16:04:32 1999 .

URL: http://people.hsc.edu/faculty-staff/robbk/Coms261/Examples/ComputerDoctor.html

Return to Coms 261 home page