c语言大作业菜单管理,C语言大作业:编写菜单控制猜商品价格程序
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
改写猜价格游戏的程序(见下),实现对这个游戏的一些管理功能,可以根据菜单对商品进行添加、删除、查找、浏览等操作,根据模块间数据传递的方式分析各个模块的函数原型及调用关系,并完成程序编写。商品价格要求在限定范围内取随机值。
如有兴趣可以完成更多功能(不属于作业要求内容),如:
使用链表存储商品(需要对链表进行操作的一些工具函数);
商品类型中加入商品个数信息,增加统计功能;
对用户进行分类(如管理员看到的界面和普通用户看到的界面应该是不同的);
增加文件存储功能等等。
#include
#include
#include
#include
#define MAXNUMOFGOODS 5
#define MAXNUMOFGUESS 6
struct GOODSTYPE
{
char name[20];
int price;
int lb;
int ub; };
void Begin( struct GOODSTYPE goods[], int size, struct GOODSTYPE* pchoice );
void Play( struct GOODSTYPE* pgoods );
int CheckNewGame();
void ListGoods( struct GOODSTYPE goods[], int size );
struct GOODSTYPE Select( struct GOODSTYPE goods[], int size );
int GuessPrice( struct GOODSTYPE* pgoods );
int Judge( struct GOODSTYPE* pgoods, int price );
int main()
{ struct GOODSTYPE goods[ MAXNUMOFGOODS ] = { { "Book", 61, 20, 120 },
{ "Radio", 177, 100, 300 },
{ "Electric Cooker", 395, 200, 500 },
{ "Microwave Oven", 988, 500, 1500 },
{ "Television", 2199, 1000, 3000 } };
struct GOODSTYPE choice; clrscr();
while( 1 )
{
Begin( goods, MAXNUMOFGOODS, &choice );
Play( &choice );
if( !CheckNewGame() )
{
printf( "Thank you!\nBye!\n" );
break;
}
}
return 0;
}
void Begin( struct GOODSTYPE goods[], int size, struct GOODSTYPE* pchoice )
{
/* 列出全部商品 */
ListGoods( goods, size );
*pchoice = Select( goods, size );
}
void Play( struct GOODSTYPE* pgoods )
{
int i, price, judge;
for( i = 0; i
{
price = GuessPrice( pgoods );
judge = Judge( pgoods, price );
switch( judge )
{
case -1:
printf( "Low. %d opportunities left.\n", MAXNUMOFGUESS - i - 1 );
break;
case 0:
printf( "Congratulations! You win the %s!\n", pgoods->name );
break;
case 1:
printf( "High. %d opportunities left.\n", MAXNUMOFGUESS - i - 1 );
break;
}
if( judge == 0 ) break;
}
if( price != pgoods->price )
printf( "\n+++ You lose! +++\n+++ The price is %d +++\n", pgoods->price );
}
int CheckNewGame()
{
static char replay[2] = "N";
printf( "\nDo you want to play another game ( Y | N )? " );
gets( replay );
if( toupper( replay[0] ) == 'Y' )
return 1;
else
return 0;
}
void ListGoods( struct GOODSTYPE goods[], int size )
{
int i;
printf( "++++++++++++++++ Welcome! ++++++++++++++\n\n" );
printf( "Choose one from the list. You'll get it if you can\n" );
printf( "tell the price within %d times.\n\n", MAXNUMOFGUESS );
printf( "++++++++++++++++++++++++++++++++++++++++++++++++++++\n" );
for( i = 0; i
printf( "%d. %-20s(price : %d-%d)\n", i + 1, goods[i].name,
goods[i].lb, goods[i].ub );
printf( "++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n" );
}
struct GOODSTYPE Select( struct GOODSTYPE goods[], int size )
{
int sel;
printf( "Input your choice (%d-%d), Others to quit the game: ",
1, size );
scanf( "%d", &sel );
if( sel size )
exit( 0 );
return( goods[ sel - 1 ] );
}
int GuessPrice( struct GOODSTYPE* pgoods )
{
int price;
while( 1 )
{
printf( "Input your price between %d and %d: ",
pgoods->lb, pgoods->ub );
scanf( "%d", &price );
getchar();
if( ( price >= pgoods->lb ) && ( price <= pgoods->ub ) )
break;
else
printf( "Out of range, please input a price between %d and %d.\n",
pgoods->lb, pgoods->ub );
}
return price;
}
int Judge( struct GOODSTYPE* pgoods, int price )
{
if( price == pgoods->price )
return 0;
else if( price price )
return -1;
else
return 1;
}
c语言大作业菜单管理,C语言大作业:编写菜单控制猜商品价格程序相关推荐
- c语言大作业菜单,C语言大作业:编写菜单控制猜商品价格程序
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 改写猜价格游戏的程序(见下),实现对这个游戏的一些管理功能,可以根据菜单对商品进行添加.删除.查找.浏览等操作,根据模块间数据传递的方式分析各个模块的函数 ...
- 程序猜价格c语言,C语言大作业:编写菜单控制猜商品价格程序
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 改写猜价格游戏的程序(见下),实现对这个游戏的一些管理功能,可以根据菜单对商品进行添加.删除.查找.浏览等操作,根据模块间数据传递的方式分析各个模块的函数 ...
- C语言与JAVA内存管理_C语言内存管理
本章将介绍C语言动态内存管理. C语言编程语言提供了多种功能的内存分配和管理.这些函数可以在头文件中找到. S.N. 函数与说明 1 void *calloc(int num, int size); ...
- c语言编程模拟进程管理,C语言如何模拟进程管理?
C语言如何模拟进程管理? 发布日期:2016-01-04 09:15 来源: 标签: 编程语言 C教程 C语言模拟进程 C语言模拟进程管理 本章我们主要学习C语言如何模拟进程管理,下面我们就做一下具体 ...
- c语言课程设计歌曲管理,C语言课程设计-歌曲信息管理系统.doc
C语言课程设计实习报告 专 业: 学 号: 班级序号: 姓 名: 指导教师: C语言程序设计报告 (实习日期: 2010-8至2010-9) 一.C语言课程设计的目的:? 高级语言课程设计是学习完&l ...
- C语言与JAVA内存管理_C语言动态内存管理和动态内存分配
动态内存管理同时还具有一个优点:当程序在具有更多内存的系统上需要处理更多数据时,不需要重写程序.标准库提供以下四个函数用于动态内存管理: (1) malloc().calloc() 分配新的内存区域. ...
- c语言程序设计学生籍贯管理,c语言编程,将若干名学生的学号、姓名、专业、年级、籍贯等信息保存到名为“xueshenginfo...
满意答案 fac02 2013.06.24 采纳率:54% 等级:12 已帮助:13365人 #include #include #include struct student { long n ...
- php菜单管理样式模板,php – SilverStripe Fluent菜单模板
SilverStripe Fluent模块具有现成的模板,可在前端显示简单的语言切换菜单. > $Title.XML 当它循环"Locales"时它在技术上是什么循环?没有名 ...
- C语言函数星阵用star,求一个汇编语言编写的动态五角星的程序
满意答案 liqiin18 2013.11.26 采纳率:57% 等级:11 已帮助:7752人 DATA SEGMENT BIN1 DW 78B8H DEC1 DB 5 DUP(0) BCD1 ...
最新文章
- 极速理解设计模式系列:23.装饰器模式(Decorator Pattern)
- Python基本语法_文件操作_读写函数详解
- spring事务的传播特性
- IDEA 真牛逼,900行 又臭又长 的类重构,几分钟搞定
- php在函数内使用全局变量
- 第五章 Response(JavaTM Servlet 规范3.1 )
- python单向链表和双向链表的图示代码说明
- vfp操作excel排序_中招计算机信息技术考试训练|Excel操作题一|排序和筛选
- linux 窗口管理器_您最喜欢的Linux窗口管理器是什么?
- vivo S10系列官方渲染图公布 外壳太好看了!
- 2019 年被“杀”死的那些技术!
- Visual Studio 2005 重置设置
- Repeater双重绑定(子菜单前台代码:)
- linux软链接删除重新创显示,Linux 下如何创建 /删除软连接
- python六大数据类型的定义_python六大类标准数据类型和数据类型转换
- 小白也会用的SQL优化工具推荐
- 码上致富(APP+H5+小程序)淘宝客APP源码导购APP源码代理淘客APP源码
- kotlin遍历数据同时删除之利用kotlin迭代器安全删除
- vue + openlayers鼠标移动获取地图经纬度格式化的两种方式
- 基于寒武纪CNCodec 做视频编解码遇到的一些问题