第六周作业

要求二:

1.题目7-1 高速公路超速处罚

a.实验代码

 1 #include <stdio.h>
 2 int main()
 3 {
 4     int a,b;
 5     float m;
 6     scanf("%d %d",&a,&b);
 7     m = (float)(a - b)*100/b;
 8     if (m>=10&&m<50)
 9     {
10         printf("Exceed %.0f%%. Ticket 200",m);
11     }
12     else if (m>=50) 
13     {
14         printf("Exceed %.0f%%. License Revoked",m);
15     } 
16      else 
17      { 
18           printf("OK");
19       } 
20     return 0;
21  } 

b.设计思路


查看输入格式以及输出格式,理解题意,列出公式,利用if else 语句表达出结果。

 

c.流程图

d.问题:

解决方案:if条件后不应有;号,去掉后即可编译。

 

2.题目7-2 计算油费

a.实验代码

 1 #include <stdio.h>
 2 int main()
 3 {
 4     double x,y,s;
 5     int a,b;
 6     char c;
 7     s=0;
 8     scanf("%d %d %c",&a,&b,&c);
 9     switch(b)
10     {
11         case 90:x=6.95;break;
12         case 93:x=7.44;break;
13         case 97:x=7.93;break;
14     }
15     switch(c)
16     {
17         case 'e':y=0.97;break;
18         case 'm':y=0.95;break;
19     }
20     s=x*y*a;
21     printf("%.2f",s);
22     return 0;
23 }

b.设计思路

审清题意,找出有关数据变量,输入应用公式,因为题意中有输入字符的形式,所以利用swich语法计算本题。

 

c.流程图

d.问题:

当b=30 c=‘e'时一直不通过。

解决方案:开始以为是程序错误后来把float换成double时就成功了。

 

3.题目7-3 比较大小

a.代码

#include <stdio.h>
int main()
{
    int a,b,c,d;
    scanf("%d %d %d",&a,&b,&c);
    if (a>b){
      d=a;
      a=b;
      b=d;}
    if (a>c){
      d=a;
      a=c;
      c=d;}
    if (b>c){
      d=b;
      b=c;
      c=d;}
      printf("%d->%d->%d",a,b,c);
      return 0;
 }

b.设计思路
运用if else 语句,三个变量两两比较,增加一个变量作为替换,输出程序。

c.流程图

 

d.问题:本题为多次if语句的运用,较简单,没有问题。

 

4.题目7-4 两个数的简单计算器

a.代码

 1 #include <stdio.h>
 2 int main()
 3 {
 4   int a,b;
 5   char c;
 6   scanf("%d %c %d",&a,&c,&b);
 7   switch(c)
 8   {
 9     case '+':printf("%d",a+b);break;
10     case '-':printf("%d",a-b);break;
11     case '*':printf("%d",a*b);break;
12     case '/':printf("%d",a/b);break;
13     case '%':printf("%d",a%b);break;
14     default :printf("ERROR\n");break;
15   }
16   return 0;
17 }

 

b.设计思路

找出变量的类型,运用switch语法链接。

 

c.流程图

d.问题:本题只要用switch语句就较为简单,无问题。

要求三:

git地址:https://git.coding.net/haidongaa/test.git

截图:

 

要求四:

个人总结:本周复习了if-else嵌套语句,新学习了switch语句。

学习难点:刚开始还不能接受switch语句,但是经过反复琢磨后明白了。

 

要求五:

表格:

折线图:

 

欢迎大家点评我的作业,我也会去点评你们的作业!!

 

posted @ 2017-11-09 19:55  金海东123  阅读(306)  评论(5编辑  收藏  举报