C语言练习-学生信息管理系统

题目要求:

学生信息管理系统
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\t%s\t%d\t%c\t%d\t%d\t%d\n",
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("\n\n\n");
printf("-----------------管理信息系统---------------------------\n");
printf("| |\n");
printf("| |\n");
printf("| 1.插入用户信息 |\n");
printf("| 2.显示用户信息 |\n");
printf("| 3.显示所有用户信息 |\n");
printf("| 4.删除用户信息 |\n");
printf("| 5.统计信息 |\n");
printf("| 6.退出系统 |\n");
printf("| |\n");
printf("--------------------------------------------------------|\n");
printf("请输入数字:(1-6)\n");
input();
} void insert(){
char name[128];
int i = 0;
++pos;
printf("Please input user id :\n");
scanf("%d", &student[pos].id);
printf("Please input user name :\n");
scanf("%s", name);
strcpy(student[pos].name, name);
printf("Please input user age :\n");
scanf("%d", &student[pos].age);
printf("Please input user sex :\n");
scanf(" %c", &student[pos].sex);
printf("Please input user C语言分数 :\n");
scanf("%d", &student[pos].c_score);
printf("Please input user C++分数 :\n");
scanf("%d", &student[pos].cpp_score);
printf("Please input user objective-c 分数 :\n");
scanf("%d", &student[pos].oc_score);
printf("插入成功!\n");
show();
} void showuser(){
printf("1>输入id, 按ID显示信息\n");
printf("2>输入name, 按name显示信息\n");
printf("请输入序号:(1-2)\n");
int i, id, num;
char name[128];
scanf("%d", &num);
if(num == 1){
printf("请输出ID:\n");
scanf("%d", &id);
for(i=1;i<=pos;++i)
if(id == student[i].id){
printf("ID\t名字\t年龄\t性别\tC\tC++\tOC\n");
print_info(i);
}
}
if(num == 2){
printf("请输入用户名字:\n");
scanf("%s", name);
for(i=1;i<=pos;++i)
if(!strcmp(name, student[i].name)){
printf("ID\t名字\t年龄\t性别\tC\tC++\tOC\n");
print_info(i);
}
}
printf("按任意键返回菜单\n");
getchar();
getchar();
show();
} void showalluser(){
int i = 0;
printf("ID\t名字\t年龄\t性别\tC\tC++\tOC\n");
for(i=1;i<=pos;++i){
if(student[i].id == 0) continue;
print_info(i);
}
show();
} void delete(){
printf("1>输入id, 按ID删除信息\n");
printf("2>输入name, 按name删除信息\n");
printf("请输入序号:(1-2)\n");
int i, id, num;
char name[128];
scanf("%d", &num);
if(num == 1){
printf("请输入ID\n");
scanf("%d", &id);
for(i=1;i<=pos;++i)
if(id == student[i].id){
student[i].id = 0;
printf("删除成功!\n");
}
}
if(num == 2){
printf("请输入用户名字:\n");
scanf("%s", name);
for(i=1;i<=pos;++i)
if(!strcmp(name, student[i].name)){
student[i].id = 0;
printf("删除成功!\n");
}
}
show();
} void sum(){
printf("1>输入C语言分数的平均值信息\n");
printf("2>输入C++语言分数的平均值信息\n");
printf("3>输入objective-C语言分数的平均值信息\n");
printf("请输入序号:(1-3)\n");
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\n", 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\n", 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\n", 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\n", 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;
}

  

运行结果 截图:

C语言练习-学生信息管理系统

上一篇:phpmyadmin安装教程及配置设置


下一篇:js 实现二叉树