用C语言编写一个学生可以查询、修改个人信息,查看是实习信息(要求显示:学生名称、实习名称、地点、实习岗位)的代码。
时间: 2023-06-15 12:07:49 浏览: 223
学生信息进行录入、查询、查看和修改
以下是一个简单的学生信息管理系统,包括了学生个人信息和实习信息的查询和修改功能。代码中使用了结构体来存储学生信息和实习信息。
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_STUDENT 100
// 学生结构体
typedef struct student {
char name[30]; // 学生姓名
char id[20]; // 学生学号
char major[30]; // 学生专业
char phone[20]; // 学生电话
} Student;
// 实习信息结构体
typedef struct internship {
char name[30]; // 实习名称
char location[30]; // 实习地点
char position[30]; // 实习岗位
} Internship;
// 学生实习信息结构体
typedef struct student_internship {
Student student; // 学生信息
Internship intern; // 实习信息
} StudentInternship;
// 学生数组
Student students[MAX_STUDENT];
int student_count = 0;
// 实习信息数组
Internship internships[MAX_STUDENT];
int internship_count = 0;
// 学生实习信息数组
StudentInternship student_internships[MAX_STUDENT];
int student_internship_count = 0;
// 显示菜单
void show_menu() {
printf("1. 添加学生信息\n");
printf("2. 添加实习信息\n");
printf("3. 添加学生实习信息\n");
printf("4. 查询学生信息\n");
printf("5. 修改学生信息\n");
printf("6. 查询实习信息\n");
printf("7. 修改实习信息\n");
printf("8. 查询学生实习信息\n");
printf("9. 修改学生实习信息\n");
printf("0. 退出程序\n");
}
// 添加学生信息
void add_student() {
if (student_count == MAX_STUDENT) {
printf("学生信息已满,无法添加!\n");
return;
}
Student student;
printf("请输入学生姓名:");
scanf("%s", student.name);
printf("请输入学生学号:");
scanf("%s", student.id);
printf("请输入学生专业:");
scanf("%s", student.major);
printf("请输入学生电话:");
scanf("%s", student.phone);
students[student_count] = student;
student_count++;
printf("添加学生信息成功!\n");
}
// 添加实习信息
void add_internship() {
if (internship_count == MAX_STUDENT) {
printf("实习信息已满,无法添加!\n");
return;
}
Internship internship;
printf("请输入实习名称:");
scanf("%s", internship.name);
printf("请输入实习地点:");
scanf("%s", internship.location);
printf("请输入实习岗位:");
scanf("%s", internship.position);
internships[internship_count] = internship;
internship_count++;
printf("添加实习信息成功!\n");
}
// 添加学生实习信息
void add_student_internship() {
if (student_internship_count == MAX_STUDENT) {
printf("学生实习信息已满,无法添加!\n");
return;
}
StudentInternship student_internship;
printf("请输入学生姓名:");
scanf("%s", student_internship.student.name);
printf("请输入学生学号:");
scanf("%s", student_internship.student.id);
printf("请输入学生专业:");
scanf("%s", student_internship.student.major);
printf("请输入学生电话:");
scanf("%s", student_internship.student.phone);
printf("请输入实习名称:");
scanf("%s", student_internship.intern.name);
printf("请输入实习地点:");
scanf("%s", student_internship.intern.location);
printf("请输入实习岗位:");
scanf("%s", student_internship.intern.position);
student_internships[student_internship_count] = student_internship;
student_internship_count++;
printf("添加学生实习信息成功!\n");
}
// 查询学生信息
void query_student() {
char id[20];
printf("请输入要查询学生的学号:");
scanf("%s", id);
int found = 0;
for (int i = 0; i < student_count; i++) {
if (strcmp(students[i].id, id) == 0) {
printf("姓名:%s\n", students[i].name);
printf("学号:%s\n", students[i].id);
printf("专业:%s\n", students[i].major);
printf("电话:%s\n", students[i].phone);
found = 1;
break;
}
}
if (!found) {
printf("未找到该学生信息!\n");
}
}
// 修改学生信息
void modify_student() {
char id[20];
printf("请输入要修改学生的学号:");
scanf("%s", id);
int found = 0;
for (int i = 0; i < student_count; i++) {
if (strcmp(students[i].id, id) == 0) {
printf("请输入学生姓名:");
scanf("%s", students[i].name);
printf("请输入学生学号:");
scanf("%s", students[i].id);
printf("请输入学生专业:");
scanf("%s", students[i].major);
printf("请输入学生电话:");
scanf("%s", students[i].phone);
found = 1;
break;
}
}
if (!found) {
printf("未找到该学生信息!\n");
} else {
printf("修改学生信息成功!\n");
}
}
// 查询实习信息
void query_internship() {
char name[30];
printf("请输入要查询实习的名称:");
scanf("%s", name);
int found = 0;
for (int i = 0; i < internship_count; i++) {
if (strcmp(internships[i].name, name) == 0) {
printf("实习名称:%s\n", internships[i].name);
printf("实习地点:%s\n", internships[i].location);
printf("实习岗位:%s\n", internships[i].position);
found = 1;
break;
}
}
if (!found) {
printf("未找到该实习信息!\n");
}
}
// 修改实习信息
void modify_internship() {
char name[30];
printf("请输入要修改实习的名称:");
scanf("%s", name);
int found = 0;
for (int i = 0; i < internship_count; i++) {
if (strcmp(internships[i].name, name) == 0) {
printf("请输入实习名称:");
scanf("%s", internships[i].name);
printf("请输入实习地点:");
scanf("%s", internships[i].location);
printf("请输入实习岗位:");
scanf("%s", internships[i].position);
found = 1;
break;
}
}
if (!found) {
printf("未找到该实习信息!\n");
} else {
printf("修改实习信息成功!\n");
}
}
// 查询学生实习信息
void query_student_internship() {
char id[20];
printf("请输入要查询学生实习信息的学号:");
scanf("%s", id);
int found = 0;
for (int i = 0; i < student_internship_count; i++) {
if (strcmp(student_internships[i].student.id, id) == 0) {
printf("学生姓名:%s\n", student_internships[i].student.name);
printf("学生学号:%s\n", student_internships[i].student.id);
printf("学生专业:%s\n", student_internships[i].student.major);
printf("学生电话:%s\n", student_internships[i].student.phone);
printf("实习名称:%s\n", student_internships[i].intern.name);
printf("实习地点:%s\n", student_internships[i].intern.location);
printf("实习岗位:%s\n", student_internships[i].intern.position);
found = 1;
break;
}
}
if (!found) {
printf("未找到该学生实习信息!\n");
}
}
// 修改学生实习信息
void modify_student_internship() {
char id[20];
printf("请输入要修改学生实习信息的学号:");
scanf("%s", id);
int found = 0;
for (int i = 0; i < student_internship_count; i++) {
if (strcmp(student_internships[i].student.id, id) == 0) {
printf("请输入学生姓名:");
scanf("%s", student_internships[i].student.name);
printf("请输入学生学号:");
scanf("%s", student_internships[i].student.id);
printf("请输入学生专业:");
scanf("%s", student_internships[i].student.major);
printf("请输入学生电话:");
scanf("%s", student_internships[i].student.phone);
printf("请输入实习名称:");
scanf("%s", student_internships[i].intern.name);
printf("请输入实习地点:");
scanf("%s", student_internships[i].intern.location);
printf("请输入实习岗位:");
scanf("%s", student_internships[i].intern.position);
found = 1;
break;
}
}
if (!found) {
printf("未找到该学生实习信息!\n");
} else {
printf("修改学生实习信息成功!\n");
}
}
int main() {
int choice;
do {
show_menu();
printf("请输入您的选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
add_student();
break;
case 2:
add_internship();
break;
case 3:
add_student_internship();
break;
case 4:
query_student();
break;
case 5:
modify_student();
break;
case 6:
query_internship();
break;
case 7:
modify_internship();
break;
case 8:
query_student_internship();
break;
case 9:
modify_student_internship();
break;
case 0:
printf("退出程序!\n");
break;
default:
printf("无效的选择,请重新选择!\n");
break;
}
} while (choice != 0);
return 0;
}
```
阅读全文