用c+写一个学生考勤信息记录系统,要包含,学生姓名,学生桌号,学生电话号码
时间: 2023-05-31 22:06:46 浏览: 81
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 100
struct student {
char name[50];
int desk_number;
char phone_number[20];
} students[MAX_STUDENTS];
int num_students = 0;
int main() {
int choice = 0;
while (1) {
printf("1. Add student record\n");
printf("2. Print all student records\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
if (num_students < MAX_STUDENTS) {
printf("Enter student name: ");
scanf("%s", students[num_students].name);
printf("Enter desk number: ");
scanf("%d", &students[num_students].desk_number);
printf("Enter phone number: ");
scanf("%s", students[num_students].phone_number);
num_students++;
} else {
printf("Maximum number of students reached.\n");
}
break;
case 2:
printf("Name\tDesk Number\tPhone Number\n");
for (int i = 0; i < num_students; i++) {
printf("%s\t%d\t\t%s\n", students[i].name, students[i].desk_number, students[i].phone_number);
}
break;
case 3:
return 0;
default:
printf("Invalid choice.\n");
break;
}
}
}
阅读全文