0
点赞
收藏
分享

微信扫一扫

内网服务器(不通外网)访问高德在线地图服务的方法

color_小浣熊 2023-11-02 阅读 40

C++-实现一个简单的菜单程序

1,if-else语句实现

1.1,代码实现
  	# include <iostream>
	# include <cstdlib> 
  	using namespace std;
  	
  	int main()
{
	char	choice, c;
	while(1)
	{
		cout << "Menu: A(dd) D(delete) S(ort) Q(uit), Select one:";
		cin  >> c;
		choice	= toupper(c);	// 输入字符 
		if(choice == 'A')
		{
			cout	<< "数据已经增加." 	<< endl;
			continue;
		}
		else if(choice == 'D')
		{
			cout 	<< "数据已经删除."	<< endl;
			continue;
		}
		else if(choice == 'S')
		{
			cout	<< "数据已经排序."	<< endl;
			continue;
		}
		else if(choice == 'Q')
			break;
		
	}
	return 0;

}
	    	
1.2,功能检测

在这里插入图片描述

2,switch语句实现

2.1,代码实现
#include	<iostream>
#include	<cstdlib>
using namespace std;

int main()
{
	char	choice;
	while(1)
	{
		cout	<< "menu: A(dd) D(elete) S(ort) Q(uit), Select one:";
		cin		>> choice;
		switch(toupper(choice))		//	输入字符,不分大小写 
		{
			case	'A':
				cout	<< "数据已经增加."	<<	endl;
				break;
			case	'D':
				cout	<<	"数据已经减少."	<<	endl;
				break;
			case	'S':
				cout	<<	"数据已经排序."	<<	endl;
				break;
			case	'Q':
				exit(0);
				break;
			default:
				;
		}
	}
	
return	0;	
}


2.2,功能检测

在这里插入图片描述

举报

相关推荐

0 条评论