题目要求:
学生信息管理系统
struct studentInfo
{
int id;
char name[128];
int age;
char sex;
int c_score;
int cpp_score;
int oc_scpre;
};
struct StudentInfo Arr[100]={};
int count=0;
show
1. 插入用户信息
scnaf("%s%d", Arr[count].age);
count++;
2. 显示用户信息
(1)输入id,按id显示信息
(2)输入name,按name显示信息
3. 显示所有用户信息
4. 删除用户信息
(1)输入id,按id删除信息
(2)输入name,按name删除信息
5. 统计
c-score 平均值
cpp-score-平均值
oc-score平均值
平均值成绩最高分
input: 1-6
switch()
{
}
我的代码:
#include <stdio.h> #include <string.h> typedef struct studentInfo{ int id; char name[128]; int age; char sex; int c_score; int cpp_score; int oc_score; }Student; Student student[1000]; int pos; void print_info(int p){ printf("%d %s %d %c %d %d %d ", student[p].id, student[p].name, student[p].age, student[p].sex, student[p].c_score, student[p].cpp_score, student[p].oc_score); } void input(); void show(){ printf(" "); printf("-----------------管理信息系统--------------------------- "); printf("| | "); printf("| | "); printf("| 1.插入用户信息 | "); printf("| 2.显示用户信息 | "); printf("| 3.显示所有用户信息 | "); printf("| 4.删除用户信息 | "); printf("| 5.统计信息 | "); printf("| 6.退出系统 | "); printf("| | "); printf("--------------------------------------------------------| "); printf("请输入数字:(1-6) "); input(); } void insert(){ char name[128]; int i = 0; ++pos; printf("Please input user id : "); scanf("%d", &student[pos].id); printf("Please input user name : "); scanf("%s", name); strcpy(student[pos].name, name); printf("Please input user age : "); scanf("%d", &student[pos].age); printf("Please input user sex : "); scanf(" %c", &student[pos].sex); printf("Please input user C语言分数 : "); scanf("%d", &student[pos].c_score); printf("Please input user C++分数 : "); scanf("%d", &student[pos].cpp_score); printf("Please input user objective-c 分数 : "); scanf("%d", &student[pos].oc_score); printf("插入成功! "); show(); } void showuser(){ printf("1>输入id, 按ID显示信息 "); printf("2>输入name, 按name显示信息 "); printf("请输入序号:(1-2) "); int i, id, num; char name[128]; scanf("%d", &num); if(num == 1){ printf("请输出ID: "); scanf("%d", &id); for(i=1;i<=pos;++i) if(id == student[i].id){ printf("ID 名字 年龄 性别 C C++ OC "); print_info(i); } } if(num == 2){ printf("请输入用户名字: "); scanf("%s", name); for(i=1;i<=pos;++i) if(!strcmp(name, student[i].name)){ printf("ID 名字 年龄 性别 C C++ OC "); print_info(i); } } printf("按任意键返回菜单 "); getchar(); getchar(); show(); } void showalluser(){ int i = 0; printf("ID 名字 年龄 性别 C C++ OC "); for(i=1;i<=pos;++i){ if(student[i].id == 0) continue; print_info(i); } show(); } void delete(){ printf("1>输入id, 按ID删除信息 "); printf("2>输入name, 按name删除信息 "); printf("请输入序号:(1-2) "); int i, id, num; char name[128]; scanf("%d", &num); if(num == 1){ printf("请输入ID "); scanf("%d", &id); for(i=1;i<=pos;++i) if(id == student[i].id){ student[i].id = 0; printf("删除成功! "); } } if(num == 2){ printf("请输入用户名字: "); scanf("%s", name); for(i=1;i<=pos;++i) if(!strcmp(name, student[i].name)){ student[i].id = 0; printf("删除成功! "); } } show(); } void sum(){ printf("1>输入C语言分数的平均值信息 "); printf("2>输入C++语言分数的平均值信息 "); printf("3>输入objective-C语言分数的平均值信息 "); printf("请输入序号:(1-3) "); int num, i, sum, cnt; scanf("%d", &num); if(num == 1){ cnt = 0; sum = 0; for(i=1;i<=pos;++i){ if(student[i].id == 0) continue; cnt++; sum+=student[i].c_score; } printf("C语言评分分数 :%g ", sum/(cnt*1.0)); } if(num == 2){ cnt = 0; sum = 0; for(i=1;i<=pos;++i){ if(student[i].id == 0) continue; cnt++; sum+=student[i].cpp_score; } printf("C++语言评分分数 :%g ", sum/(cnt*1.0)); } if(num == 3){ cnt = 0; sum = 0; for(i=1;i<=pos;++i){ if(student[i].id == 0) continue; cnt++; sum+=student[i].oc_score; } printf("objective-C语言评分分数 :%g ", sum/(cnt*1.0)); } if(num == 4){ cnt = 0; sum = 0; for(i=1;i<=pos;++i){ if(student[i].id == 0) continue; cnt++; sum+=student[i].oc_score; } printf("objective-C语言评分分数 :%f ", sum/(cnt*1.0)); } show(); } void _quit(){} void input(){ int num; scanf("%d", &num); switch(num){ case 1: insert(); break; case 2: showuser(); break; case 3: showalluser(); break; case 4: delete(); break; case 5: sum(); break; case 6: _quit(); break; } } int main(){ pos = 0; show(); return 0; }
运行结果 截图: