高级语言程序设计课程第五次个人作业

这个作业属于哪个课程:https://edu.cnblogs.com/campus/fzu/2024C/
这个作业要求在哪里:https://edu.cnblogs.com/campus/fzu/2024C/homework/13298
学号:102300108
姓名:陈茜蕾

8.11编程练习

第1题

第2题

第3题

第4题

第5题

第6题

第7题

#include <stdio.h>
#define OVERTIME 40
#define FIRST 8.75
#define SECOND 9.33
#define THIRD 10.00
#define FOURTH 11.20
#define TAX1 0.15
#define TAX2 0.20
#define TAX3 0.25
#pragma warning (disable:4996)
int main()
{
    double hour = 0;
    char choice;
    double wage = 0;
    double tax = 0;
    printf("Input your working hours per week:");
    scanf("%lf", &hour);
    //加班的时长*1.5
    if (hour > OVERTIME) {
        hour = OVERTIME + (hour - OVERTIME) * 1.5;
    }
    while (1)
    {
        printf("*****************************************************************\n");
        printf("Enter the number corresponding to the desired pay rate or action:\n");
        printf("a) $8.75/hr\t\t\t\tb) $9.33/hr\n");
        printf("c) $10.00/hr\t\t\t\td) $11.20/hr\n");
        printf("q) quit\n");
        printf("*****************************************************************\n");
        choice = getchar(); //吸收空格
        scanf("%c", &choice);
        if (choice == 'q') {
            break;
        }

        switch (choice)
        {
        case 'a':
            wage = FIRST * hour;
            break;
        case 'b':
            wage = SECOND * hour;
            break;
        case 'c':
            wage = THIRD * hour;
            break;
        case 'd':
            wage = FOURTH * hour;
            break;
        default:
            printf("Input false!Please input again in 1~5.\n");
            continue;
        }

        if (wage < 300) {
            tax = wage * TAX1;
        }
        else {
            tax += 300 * TAX1;
            if (wage < 450) {
                tax += (wage - 300) * TAX2;
            }
            else {
                tax += (450 - 300) * TAX2;
                tax += (wage - 450) * TAX3;
            }
        }
        printf("工资总额:%.2f ", wage);
        printf("税金:%.2f ", tax);
        printf("净收入:%.2f\n\n", wage - tax);
    }
    return 0;
}

第8题

#include <stdio.h>
#include <ctype.h>
#pragma warning (disable:4996)
void printMenu() {
	printf("\nEnter the operation of your choice :\n");
	printf("a.add\t\t s.subtract\n");
	printf("m.multiply\t\t d.divide\n");
	printf("q.quit\n");
}
int main() {
	char ch;
	float num1 = 0;
	float num2 = 0;
	while (1) {
		printMenu();
		ch = getchar();
		switch (ch)
		{
		case'a':
			printf("Enter first number:");
			while (scanf("%f", &num1)!=1) {
				printf("This is not an number.\n");
				printf("Please enter a number, such as 2.5, -1.78E8, or 3:");
			}
			printf("Enter second number:");
			while (scanf("%f", &num2) != 1) {
				printf("Please enter a number, such as 2.5, -1.78E8, or 3:");
			}
			printf("%f + %f = %f\n", num1, num2, num1 + num2);
			break;
		case's':
			printf("Enter first number:");
			while (scanf("%f", &num1) != 1) {
				printf("This is not an number.\n");
				printf("Please enter a number, such as 2.5, -1.78E8, or 3:");
			}
			printf("Enter second number:");
			while (scanf("%f", &num2) != 1) {
				printf("This is not an number.\n");
				printf("Please enter a number, such as 2.5, -1.78E8, or 3:");
			}
			printf("%f - %f = %f\n", num1, num2, num1 - num2);
			break;
		case'm':
			printf("Enter first number:");
			while (scanf("%f", &num1) != 1) {
				printf("This is not an number.\n");
				printf("Please enter a number, such as 2.5, -1.78E8, or 3:");
			}
			printf("Enter second number:");
			while (scanf("%f", &num2) != 1) {
				printf("This is not an number.\n");
				printf("Please enter a number, such as 2.5, -1.78E8, or 3:");
			}
			printf("%f * %f = %f\n", num1, num2, num1 * num2);
			break;
		case'd':
			printf("Enter first number:");
			while (scanf("%f", &num1) != 1) {
				printf("This is not an number.\n");
				printf("Please enter a number, such as 2.5, -1.78E8, or 3:");
			}
			printf("Enter second number:");
			while (scanf("%f", &num2) != 1) {
				printf("This is not an number.\n");
				printf("Please enter a number, such as 2.5, -1.78E8, or 3:");
			}
			while (num2 == 0) {
				printf("Enter a number other than 0:");
				scanf("%f", &num2);
			}
			printf("%f / %f = %f\n", num1, num2, num1 / num2);
			break;
		case'q':
			printf("Bye");
			break;
		}
		if (ch == 'q') {
			break;
		}
	}
}

9.11编程练习

第1题

第2题

第3题

第4题

第5题

第6题

#include <stdio.h>
#pragma warning (disable:4996)
void swap(double *a, double *b) {
	double temp = 0;
	temp = *a;
	*a = *b;
	*b = temp;
}
void set(double *x, double *y, double* z){
	if (*x > *y) {
		swap(x, y);
	}
	if (*x > *z) {
		swap(x, z);
	}
	if (*y > *z) {
		swap(y, z);
	}
}
int main(void)
{
	double x = 0;
	double y = 0;
	double z = 0;
	printf("请输入三个数:");
	while (scanf("%lf %lf %lf",&x, &y, &z) == 3)
	{
		set(&x, &y, &z);
		printf("x=%lf y=%lf z=%lf", x, y, z);
	}
	return 0;
}

第7题

第8题

第9题

第10题

第11题

总结

巩固了c语言字符,循环,函数和指针方面的知识,也学习到了更多函数和方法,受益匪浅!

posted @ 2024-11-03 17:07  取个昵称真的好难  阅读(3)  评论(0编辑  收藏  举报