请教,急!谢谢了,很急

lingjunbin 2004-11-09 09:11:10
怎样该才可以使得输入'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
...全文
86 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhangfjj 2004-11-09
  • 打赏
  • 举报
回复
^_^
lingjunbin 2004-11-09
  • 打赏
  • 举报
回复
谢谢
zhangfjj 2004-11-09
  • 打赏
  • 举报
回复
那就再加一句
case 'R':
case 'r':
case '1':cout<<"This is an INTERFACE. doing sth about registration here.\a\n";
break;
不就行了,以下同!
zhangfjj 2004-11-09
  • 打赏
  • 举报
回复
void menu::select_menu(){
char quit='N';
char choice;
do {
cout<<appTitle;
print_menu();
cin.get();//加一句用以“吃掉”上次输入的回车符
cin>>choice;
switch(choice){
case 'R':
case 'r': cout<<"This is an INTERFACE. doing sth about registration here.\a\n";
break;
case 'S':
case 's': cout<<"This is an INTERFACE. doing sth about seeing a doctor here.\a\n";
break;
case 'P':
case 'p': cout<<"This is an INTERFACE. doing sth about paying fee here here..\a\n";
break;
case 'G':
case 'g': cout<<"This is an INTERFACE. doing sth about getting medicine here. Thank you for your visiting. Take care!\a\n";
break;
case 'H':
case 'h': cout<<"\n\a";
print_help();
break;
case 'Q':
case 'q':cout<<"Are you sure you want to quit?\n\a\aYes or NO, please!\n\a";
cin.get();
cin>>quit;
if (quit == 'Y' ||quit =='y')
cout<<"Thank you for using CIS. Good Bye! \a\n";
break;//这里也改了一下
default: cout<<"invalid selection!\n";
break;
}/switch
}while (quit=='N'||quit=='n'); //do - while loop,这一句还要改一下,先改错了!^_^

}


lingjunbin 2004-11-09
  • 打赏
  • 举报
回复
我的意思是输入R和输入1都要可以
kobefly 2004-11-09
  • 打赏
  • 举报
回复
楼上正解
zhangfjj 2004-11-09
  • 打赏
  • 举报
回复
do {
cout<<appTitle;
print_menu();
cin.get();//加一句用以“吃掉”上次输入的回车符
cin>>choice;
switch(choice){
case 'R':
case 'r': cout<<"This is an INTERFACE. doing sth about registration here.\a\n";
break;
case 'S':
case 's': cout<<"This is an INTERFACE. doing sth about seeing a doctor here.\a\n";
break;
case 'P':
case 'p': cout<<"This is an INTERFACE. doing sth about paying fee here here..\a\n";
break;
case 'G':
case 'g': cout<<"This is an INTERFACE. doing sth about getting medicine here. Thank you for your visiting. Take care!\a\n";
break;
case 'H':
case 'h': cout<<"\n\a";
print_help();
break;
case 'Q':
case 'q': 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 (1); //do - while loop,这一句还要改一下,^_^
zhangfjj 2004-11-09
  • 打赏
  • 举报
回复
也就是
do {
cout<<appTitle;
print_menu();
cin.get();//加一句用以“吃掉”上次输入的回车符
cin>>choice;
switch(choice){
case 'R':
case 'r': cout<<"This is an INTERFACE. doing sth about registration here.\a\n";
break;
case 'S':
case 's': cout<<"This is an INTERFACE. doing sth about seeing a doctor here.\a\n";
break;
case 'P':
case 'p': cout<<"This is an INTERFACE. doing sth about paying fee here here..\a\n";
break;
case 'G':
case 'g': cout<<"This is an INTERFACE. doing sth about getting medicine here. Thank you for your visiting. Take care!\a\n";
break;
case 'H':
case 'h': cout<<"\n\a";
print_help();
break;
case 'Q':
case 'q': 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
zhangfjj 2004-11-09
  • 打赏
  • 举报
回复
switch(choice)
{
case 'R':
case 'r': //调用你的处理registrar a patient.的函数;
break;
case 'S':
case 's'://....
break;
case 'P':
case 'p';//....
}

64,639

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧