请教,急!谢谢了,很急
怎样该才可以使得输入'R'等同于输入1,输入'S'等同于输入2,.....
用switch,代码如下:
#include "menu.h"
/////////////////////////////////////////////////////////////////
//Main for CIS
//Lianyun He for his class CT2400
//if any problem, contact sxoop@yahoo.com
////////////////////////////////////////////////////////////////
int main() {
menu mymenu;
mymenu.select_menu();
return 0;
}
#include "menu.h"
////////////////////////////////////////////////////////////////
// main interface class menu implementation
// developed by Eric He for his class CT 2400
// if any problem, contact sxoop@yahoo.com
////////////////////////////////////////////////////////////////
void menu::print_help() {
cout<<appTitle<<endl;
cout<<" This Clinic Information System(CIS) was developed for XYZ clinic. ";
cout<<"It has implemented the basic requirements of a small clinic in China. ";
cout<<"If u have any problems about this application and our team, please contact us at 86-0510-4567890\n";
}
void menu::print_menu() {
cout<<"1. Registrar a patient.\n";
cout<<"2. See the Doctor.\n";
cout<<"3. Pay the fee.\n";
cout<<"4. Get the medicine.\n";
cout<<"5. Help.\n";
cout<<"6. Quit.\n"<<endl;
for (int i = 0; i<4; i++)
cout<<endl;
cout<<"Make your selection, please!\n\n";
}
void menu::select_menu() {
char quit;
int choice;
do {
cout<<appTitle;
print_menu();
cin>>choice;
switch(choice){
case 1: cout<<"This is an INTERFACE. doing sth about registration here.\a\n";
break;
case 2: cout<<"This is an INTERFACE. doing sth about seeing a doctor here.\a\n";
break;
case 3: cout<<"This is an INTERFACE. doing sth about paying fee here here..\a\n";
break;
case 4: cout<<"This is an INTERFACE. doing sth about getting medicine here. Thank you for your visiting. Take care!\a\n";
break;
case 5: cout<<"\n\a";
print_help();
break;
case 6: cout<<"Are you sure you want to quit?\n\a\aYes or NO, please!\n\a";
cin>>quit;
if (quit == 'Y' ||quit =='y') cout<<"Thank you for using CIS. Good Bye! \a\n";
else choice++;
break;
default: cout<<"invalid selection!\n";
break;
} //switch
} while (choice != 6); //do - while loop
}
#ifndef _MENU_H
#define _MENU_H
#include <iostream>
#include <string>
using namespace std;
////////////////////////////////////////////////////////////////
// main interface class menu definition
// developed by Eric He for his class CT 2400
// if any problems, contact sxoop@yahoo.com
////////////////////////////////////////////////////////////////
class menu{
string appTitle;
public:
menu(){
appTitle = "\n\n SYU-Lambton CIS developed by Zhang 3 and his group.\n\n";
}
void print_menu();
void select_menu();
void print_help();
};
#endif