mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
【实践课内】16.结构体2
This commit is contained in:
parent
01c7825e24
commit
f4a8b739f9
22
【实践课内】16.结构体2/7-1 计算职工工资.c
Normal file
22
【实践课内】16.结构体2/7-1 计算职工工资.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
struct person {
|
||||
char name[10];
|
||||
double basic, floating, outlay;
|
||||
};
|
||||
|
||||
int n;
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
struct person p;
|
||||
|
||||
scanf("%s %lf %lf %lf", p.name, &p.basic, &p.floating, &p.outlay);
|
||||
|
||||
printf("%s %.2lf\n", p.name, p.basic + p.floating - p.outlay);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课内】16.结构体2/7-1 计算职工工资.jpg
Normal file
BIN
【实践课内】16.结构体2/7-1 计算职工工资.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 372 KiB |
32
【实践课内】16.结构体2/7-2 计算平均成绩.c
Normal file
32
【实践课内】16.结构体2/7-2 计算平均成绩.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
|
||||
struct student {
|
||||
char id[10], name[10];
|
||||
int score;
|
||||
};
|
||||
|
||||
int n;
|
||||
double avg;
|
||||
struct student stu[10];
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%s %s %d", stu[i].id, stu[i].name, &stu[i].score);
|
||||
|
||||
avg += stu[i].score;
|
||||
}
|
||||
|
||||
avg /= n;
|
||||
|
||||
printf("%.2lf\n", avg);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (stu[i].score < avg) {
|
||||
printf("%s %s\n", stu[i].name, stu[i].id);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课内】16.结构体2/7-2 计算平均成绩.jpg
Normal file
BIN
【实践课内】16.结构体2/7-2 计算平均成绩.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 382 KiB |
34
【实践课内】16.结构体2/7-3 找出总分最高的学生.c
Normal file
34
【实践课内】16.结构体2/7-3 找出总分最高的学生.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
|
||||
struct student {
|
||||
char id[10], name[10];
|
||||
int score[3];
|
||||
int sum_score;
|
||||
};
|
||||
|
||||
int n, max_id;
|
||||
struct student stu[10];
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%s %s", stu[i].id, stu[i].name);
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
scanf("%d", &stu[i].score[j]);
|
||||
|
||||
stu[i].sum_score += stu[i].score[j];
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < n; i++) {
|
||||
if (stu[i].sum_score > stu[max_id].sum_score) {
|
||||
max_id = i;
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s %s %d\n", stu[max_id].name, stu[max_id].id, stu[max_id].sum_score);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课内】16.结构体2/7-3 找出总分最高的学生.jpg
Normal file
BIN
【实践课内】16.结构体2/7-3 找出总分最高的学生.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 387 KiB |
34
【实践课内】16.结构体2/7-4 通讯录的录入与显示.c
Normal file
34
【实践课内】16.结构体2/7-4 通讯录的录入与显示.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include <stdio.h>
|
||||
|
||||
struct contact {
|
||||
char name[15], birthday[15], gender, tel[20], phone[20];
|
||||
};
|
||||
|
||||
int n, k;
|
||||
struct contact contacts[15];
|
||||
|
||||
int main() {
|
||||
scanf("%d", &n);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%s %s %c %s %s\n", contacts[i].name, contacts[i].birthday, &contacts[i].gender, contacts[i].tel, contacts[i].phone);
|
||||
}
|
||||
|
||||
scanf("%d", &k);
|
||||
|
||||
for (int i = 0; i < k; i++) {
|
||||
int x;
|
||||
|
||||
scanf("%d", &x);
|
||||
|
||||
if (x < 0 || x >= n) {
|
||||
printf("Not Found\n");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
printf("%s %s %s %c %s\n", contacts[x].name, contacts[x].tel, contacts[x].phone, contacts[x].gender, contacts[x].birthday);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
【实践课内】16.结构体2/7-4 通讯录的录入与显示.jpg
Normal file
BIN
【实践课内】16.结构体2/7-4 通讯录的录入与显示.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 536 KiB |
Loading…
Reference in New Issue
Block a user