高级语言程序设计第五次作业
-
这个作业要求在哪里: https://edu.cnblogs.com/campus/fzu/2026gjyycxsj/homework/16751
-
学号:0102600136
-
姓名:黄承泉
作业内容
1. 设计一个getchar和putchar联合使用的程序,使得程序遇到空格符时结束。


2. 建立一个in.txt和out.txt,分别使用这两个文件进行重定位代替键盘输入和屏幕输出in.txt存放一些字符小写字符,大写字符,数字字符,程序将这些小写字符转换成大写字符,然后全部输出到out.txt。
2.1 Dev-Cpp编写代码

2.2 创建in.txt并输入字符

2.3 使用cmd

2.4 out.txt打印结果

3.从键盘上输入数据并进行加、减、乘、除四则运算(以“a运算b”的形式输入),判断输入的数据是否可以进行计算,若能计算,则输出计算结果,保留小数点后2位,否则显示“wrong input”。另外,碰到除数为0是能提示“division by zero”。形式参考第八章PPT18页。


4.混合读入字符、数值,形式参考第八章PPT19页。
问题描述: 先读入一个字符,再读入一个整数,最后又读入一个字符;然后分别输出它们
输入格式: n个空格和/或<回车>,一个字符,m个空格和/或<回车>,一个整数,k个空格和/或<回车>,一个字符
输出格式: 字符整数字符


5. 编写并运行书本第8章8.11编程练习题目中的第3~7题。
5.1 编写并运行8.11.3


5.2 编写并运行8.11.4


5.3 编写并运行8.11.5


5.4 编写并运行8.11.6
5.4.1 修改过的get_first()函数

5.4.2 运行结果

5.5 编写并运行8.11.7
#include<stdio.h>
#include<ctype.h>
#define qian300 0.15
#define xu150 0.2
#define yu 0.25
#define WIDTH 80
void starbar();
char get_choice();
char get_first();
void jisuan();
int main()
{
int choice;
double salary;
while((choice=get_choice())!='q')
{
switch(choice)
{
case 'a':salary=8.75;
break;
case 'b':salary=9.33;
break;
case 'c':salary=10.00;
break;
case 'd':salary=11.20;
break;
default:printf("Program error!\n");
break;
}
printf("请输入工作的小时数:");
double a;
scanf("%lf",&a);
while(getchar()!='\n');
jisuan(a,salary);
}
return 0;
}
void starbar(void)
{
int count;
for(count=1;count<=WIDTH;count++)
putchar('*');
putchar('\n');
}
char get_choice(void)
{
int ch;
starbar();
printf("Enter the letter corresponding to the desired pay rate or action:\n");
printf("a. $8.75/hr b. $9.33/hr \n");
printf("c. $10.00/hr d. $11.20/hr\n");
printf("q. quit\n");
starbar();
ch=get_first();
while((ch<'a'||ch>'d')&&ch!='q')
{
printf("Please respond with a,b,c,d,or q.\n");
ch = get_first();
}
return ch;
}
char get_first(void)
{
int ch;
while((ch=getchar())!=EOF&&isspace(ch))
{
continue;
}
return ch;
}
void jisuan(double a,double salary)
{
if(a>40){
a=40+(a-40)*1.5;
}
double sum=a*salary;
double qian=0,xu=0,yuxia=0;
if(sum>450){
yuxia=(sum-450)*yu;
xu=150*xu150;
qian=300*qian300;
}else if(sum>300){
xu=(sum-300)*xu150;
qian=300*qian300;
}else{
qian=sum*qian300;
}
printf("工资总额:%.2f\n",sum);
printf("税金:%.2f\n",qian+xu+yuxia);
printf("净收入:%.2f\n",sum-qian-xu-yuxia);
}

6.编写并运行书本第9章9.11编程练习题目中的第1~4,8,9,11题。
6.1 编写并运行9.11.1


6.2 编写并运行9.11.2


6.3 编写并运行9.11.3


6.4 编写并运行9.11.4


6.5 编写并运行9.11.8


6.6 编写并运行9.11.9


6.7 编写并运行9.11.11


7. 设计一个多源代码文件程序的编译。例如,first.c源代码文件包含主函数和一些头文件(second.h),second.c源代码文件是一些自定义的函数功能实现,second.h文件是一些常量声明和second.c中自定义函数的函数原型声明。
7.1 first.c

7.2 second.h

7.3 second.c

7.4 运行结果

8. 编写一个程序,在该程序中输出主函数内定义的变量的地址,以及函数中定义的同名变量的地址。


-
问题:无
-
思考:无
-
总结:无

浙公网安备 33010602011771号