实验2 控制结构.doc

  1. 1、本文档共21页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
实验2 控制结构

实验实验目的1、掌握if、switch选择语句的使用嵌套使用 2、掌握用while语句、了解转向语句的使用。 学习循环结构的嵌套使用。 (注:90分以上:为A,80一 89分为B,70一79分为C,60一69分为D,60分以下为E。)要求:该程序能正确处理任何数据。当输人数据大于:100或小于0的数据通知用户“输人数据错”,结束程序。 #includeiostream using namespace std; int main() { float score; coutEeter the score:endl; cinscore; if(100=scorescore=0) {if(score=90) coutThe degree is Aendl; else if(score=80) coutThe degree is Bendl; else if(score=70) coutThe degree is Cendl; else if(score=60) coutThe degree is Dendl; else coutThe degree is Eendl;} else coutYour input is Wrong!endl; return 0; } 2、输入一个年份,判断是否为闰年。(提示:闰年应该是能被4整除不能被100整除,或者能被400整除的年份) #includeiostream using namespace std; void main() { int year; coutPlease input the year:endl; cinyear; if((year%4==0year%100!=0)||(year%400==0)) coutyear is a leap year!endl; else coutyear is not a leap year!endl; } (截图程序在上面) 3、某商店五一购物打折。每位顾客一次购物: 满1000元,打九折; ????满2000元,打八折; ????满3000元,打七折; 满4000元,打六折; 5000元,打五折;编写程序,输入购物款,输出实收款。#includeiostream.h int main() { int money; coutPlase input money=; cinmoney; if(money=1000) switch(money/1000) { case 1: coutmoney=money*0.9endl; break; case 2: coutmoney=money*0.8endl; break; case 3: coutmoney=money*0.7endl; break; case 4: coutmoney=money*0.6endl; break; default: coutmoney=money*0.5endl; } else coutmoney=moneyendl; return 0; } 4. 运输公司对用户计算运费。路程(s)越远,每公里运费越低。标准如下: s<250km 没有折扣 250≤s<500 2%折扣 500≤s<1000 5%折扣 1000≤s<2000 8%折扣 2000≤s<3000 10%折扣 3000≤s 15%折扣 p(price的缩写),货物重为w(wright的缩写),距离为s,折扣为d(discount的缩写),则总运费f(freight的缩写)的计算公式为: f = p * w * s * (1 - d)。 编程输入基本运费、货物重输出#includeiostream using namespace std; void main() { float p,w,s,f; cout请输入基本费用,货物重和托运距离

文档评论(0)

wyjy + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档