该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

改写猜价格游戏的程序(见下),实现对这个游戏的一些管理功能,可以根据菜单对商品进行添加、删除、查找、浏览等操作,根据模块间数据传递的方式分析各个模块的函数原型及调用关系,并完成程序编写。商品价格要求在限定范围内取随机值。

如有兴趣可以完成更多功能(不属于作业要求内容),如:

使用链表存储商品(需要对链表进行操作的一些工具函数);

商品类型中加入商品个数信息,增加统计功能;

对用户进行分类(如管理员看到的界面和普通用户看到的界面应该是不同的);

增加文件存储功能等等。

#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语言大作业:编写菜单控制猜商品价格程序相关推荐

  1. c语言大作业菜单管理,C语言大作业:编写菜单控制猜商品价格程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 改写猜价格游戏的程序(见下),实现对这个游戏的一些管理功能,可以根据菜单对商品进行添加.删除.查找.浏览等操作,根据模块间数据传递的方式分析各个模块的函数 ...

  2. 程序猜价格c语言,C语言大作业:编写菜单控制猜商品价格程序

    该楼层疑似违规已被系统折叠 隐藏此楼查看此楼 改写猜价格游戏的程序(见下),实现对这个游戏的一些管理功能,可以根据菜单对商品进行添加.删除.查找.浏览等操作,根据模块间数据传递的方式分析各个模块的函数 ...

  3. linux多级菜单脚本教程,linux shell 编写菜单脚本事例

    menu2文件代码: --- #!/bin/sh #menu2 #Main menu script #ignore ctrl-c and QUIT interrupts trap "&quo ...

  4. c语言作业帮,少训练大功课C语言

    紧急分配C语言. C语言分配,很紧急. 急C语言作业. //1. #include#includeintmain(void){&nbsp C语言作业,请设计一种算法来完成两个超长正整数的加法运 ...

  5. 吉大21c语言在线作业,21春吉大《脚本语言和互动网页设计》在线作业二参考

    吉大<脚本语言和互动网页设计>在线作业二' S3 X# M4 O& r 1.[单选题] 下面哪项不是application对象的方法() ; A* b$ f- `7 [4 u; B ...

  6. 川大c语言程序设计第二次作业答案,川大《C语言程序设计0008》19春在线作业1

    <C语言程序设计0008>19春在线作业2 7 _9 S7 n$ a& |( {  g/ o" R奥鹏作业答案可以联系QQ 761296021- T; u: w( [&a ...

  7. 川大c程序设计语言1在线作业,川大《C语言程序设计0008》19春在线作业1

    <C语言程序设计0008>19春在线作业2 - b: R2 o5 d+ h; y' r+ s8 D奥鹏作业答案可以联系QQ 761296021 1 s* f! ~6 @- S1 o) v1 ...

  8. c语言实验报告大作业答案,C语言实验报告摘要(共6篇)

    C语言实验报告摘要(共6篇) 第一部分: C语言实验经验 C语言实验经验 随着科学技术的飞速发展,计算机在人们中的作用越来越突出. C语言作为一种计算机语言,对其进行学习将有助于我们更好地理解计算机并 ...

  9. c语言中数组大小10000,C语言,怎么存一个很大的数,比方说10000的阶乘

    C语言,如何存一个很大的数,比方说10000的阶乘 我们使用最大的long double 来定义,可是还是撑不下这么大的数,那么该怎么做? long double sum = 1; int i = 1 ...

最新文章

  1. 重磅直播|结构光之相移法+格雷码技术详解
  2. windows node.js 安装
  3. img下面的png图片 vs 读不出来_VUX中XImg组件加载图片不正确,BusPlugin不好使,求解...
  4. 【阿里云域名】我都有服务器了,为什么还要购买域名?
  5. 比较好的php源码,目前市面上能拿到的最好的PHP跑F分源码下载
  6. Jquery 全选、反选问题解析
  7. 【渝粤教育】广东开放大学 人工智能 形成性考核 (55)
  8. 景色宜人的openeim001
  9. Exchange2010与Office365混合部署升级到Exchange2016混合部署——Ex2016运行Office365混合配置向导...
  10. Bailian4095 打字员【文本】
  11. unity 特效shader下载_Unity shader消融特效——(1)逻辑节点篇
  12. Epub,Mobi,Azw3电子书格式的区别,Mac上有什么好用的epub阅读器
  13. 删除远程桌面登录的记录(mstsc)
  14. Codeforces 633H. Fibonacci-ish II【莫队+线段树+公式】
  15. 智能名片识别系统源码
  16. 使用思维导图进行产品需求分析
  17. Android 操作系统的进程回收机制
  18. 超全的 100 个 Pandas 函数汇总,建议收藏
  19. 服务器定时执行js脚本
  20. APP新用户注册、手机号绑定、用户登录验证新方式——一键登录(免密登录)验证方式新趋势

热门文章

  1. 关于网络蜘蛛以及搜索蜘蛛爬行
  2. C# Owin 创建与测试自己的中间件Middleware
  3. c# SerialPort会出现“已关闭 Safe handle”的错误
  4. javaweb学习总结(四十二)——Filter(过滤器)学习
  5. 使用NPOI将数据库里信息导出Excel表格并提示用户下载
  6. Microsoft Visual Studio 正忙
  7. C# Socket编程
  8. 十分钟搞懂JSON(JSON对象---JSON字符串---对象 之间的区别)
  9. restful api接口规范_如何理解RESTful API设计规范?
  10. mysql 排序后 下一条记录_Mysql如何使用order by工作