A Typical Homework(学生信息管理系统)
A Typical Homework(a.k.a Shi Xiong Bang Bang Mang)
Hi, I am an undergraduate student in institute of foreign languages. As you know, C programming is a required course in our university, even if his/her major is far from computer science. I don‘t like this course at all, as I am not good at computer and I don‘t wanna even have a try of any programming!! But I have to do the homework in order to pass :( Sh... Could you help me with it? Please keep secret!! I know that you won‘t say NO to a poor little girl, boy. :)
Task
Write a Student Performance Management System (SPMS).
Concepts
In the SPMS, there will be at most 100 students, each has an SID, a CID, a name and four scores (Chinese, Mathematics, English and Programming).
- SID (student ID) is a 10-digit number
- CID (class ID) is a positive integer not greater than 20.
- Name is a string of no more than 10 letters and digits, beginning with a capital letter. Note that a name cannot contain space characters inside.
- Each score is a non-negative integer not greater than 100.
Main Menu
When you enter the SPMS, the main menu should be shown like this:
Welcome to Student Performance Management System (SPMS). 1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit
Adding a Student
If you choose 1 from the main menu, the following message should be printed on the screen:
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Then your program should wait for user input. The input lines are always valid (no invalid SID, CID, or name, exactly four scores etc), but the SID may already exist. In that case, simply ignore this line and print the following:
Duplicated SID.
On the other hand, multiple students can have the same name. You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.
Removing a Student
If you choose 2 from the main menu, the following message should be printed on the screen:
Please enter SID or name. Enter 0 to finish.
Then your program should wait for user input, and remove all the students matching the SID or name in the database, and print the following message (it‘s possible xx=0):
xx student(s) removed.
You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.
Querying Students
If you choose 3 from the main menu, the following message should be printed on the screen:
Please enter SID or name. Enter 0 to finish.
Then your program should wait for user input. If no student matches the SID or name, simply do nothing, otherwise print out all the matching students, in the same order they‘re added to the database. The format is similar to the input format for "adding a student", but 3 more columns are added: rank (1st column), total score and average score (last two columns). The student with highest total score (considering all classes) received rank-1, and if there are two rank-2 students, the next one would be rank-4. You should keep printing the message above until the user inputs a single zero. After that the main menu is printed again.
Showing the Ranklist
If you choose 4 from the main menu, the following message should be printed on the screen:
Showing the ranklist hurts students‘ self-esteem. Don‘t do that.
Then the main menu is printed again.
Showing Statistics
If you choose 5 from the main menu, show the statistics, in the following format:
Please enter class ID, 0 for the whole statistics.
When a class ID is entered, print the following statistics. Note that "passed" means to have a score of at least 60.
Chinese
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx Mathematics
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx English
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx Programming
Average Score: xx.xx
Number of passed students: xx
Number of failed students: xx Overall:
Number of students who passed all subjects: xx
Number of students who passed 3 or more subjects: xx
Number of students who passed 2 or more subjects: xx
Number of students who passed 1 or more subjects: xx
Number of students who failed all subjects: xx Then, the main menu is printed again.
Exiting SPMS
If you choose 0 from the main menu, the program should terminate. Note that course scores and total score should be formatted as integers,
but average scores should be formatted as a real number with exactly two digits after the decimal point.
Input
There will be a single test case, ending with a zero entered in the main menu screen. The entire input will be valid. The size of input does not exceed 10KB.
Output
Print out everything as stated in the problem description. You should be able to play around this little program in your machine,
with a keyboard and a screen. However, both the input and output may look silly when they‘re not mixed, as in the keyboard-screen case.
Sample Input
1
0011223344 1 John 79 98 91 100
0022334455 1 Tom 59 72 60 81
0011223344 2 Alice 100 100 100 100
2423475629 2 John 60 80 30 99
0
3
0022334455
John
0
5
1
2
0011223344
0
5
0
4
0
Output for the Sample Input
Welcome to Student Performance Management System (SPMS). 1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Duplicated SID.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Please enter the SID, CID, name and four scores. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS). 1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit Please enter SID or name. Enter 0 to finish.
2 0022334455 1 Tom 59 72 60 81 272 68.00
Please enter SID or name. Enter 0 to finish.
1 0011223344 1 John 79 98 91 100 368 92.00
3 2423475629 2 John 60 80 30 99 269 67.25
Please enter SID or name. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS). 1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit Please enter class ID, 0 for the whole statistics.
Chinese
Average Score: 69.00
Number of passed students: 1
Number of failed students: 1 Mathematics
Average Score: 85.00
Number of passed students: 2
Number of failed students: 0 English
Average Score: 75.50
Number of passed students: 2
Number of failed students: 0 Programming
Average Score: 90.50
Number of passed students: 2
Number of failed students: 0 Overall:
Number of students who passed all subjects: 1
Number of students who passed 3 or more subjects: 2
Number of students who passed 2 or more subjects: 2
Number of students who passed 1 or more subjects: 2
Number of students who failed all subjects: 0 Welcome to Student Performance Management System (SPMS). 1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit Please enter SID or name. Enter 0 to finish.
1 student(s) removed.
Please enter SID or name. Enter 0 to finish.
Welcome to Student Performance Management System (SPMS). 1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit Please enter class ID, 0 for the whole statistics.
Chinese
Average Score: 59.50
Number of passed students: 1
Number of failed students: 1 Mathematics
Average Score: 76.00
Number of passed students: 2
Number of failed students: 0 English
Average Score: 45.00
Number of passed students: 1
Number of failed students: 1 Programming
Average Score: 90.00
Number of passed students: 2
Number of failed students: 0 Overall:
Number of students who passed all subjects: 0
Number of students who passed 3 or more subjects: 2
Number of students who passed 2 or more subjects: 2
Number of students who passed 1 or more subjects: 2
Number of students who failed all subjects: 0 Welcome to Student Performance Management System (SPMS). 1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit Showing the ranklist hurts students‘ self-esteem. Don‘t do that.
Welcome to Student Performance Management System (SPMS). 1 - Add
2 - Remove
3 - Query
4 - Show ranking
5 - Show Statistics
0 - Exit 题意做一个学生管理系统
结合李汝佳代码的一部分写出来的代码,注意处理小细节和各个操作之间的关系
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std; #define maxn 1000
#define maxl 100
#define ESP 1e-5 int n = ;
char sid[maxn][maxl]; //学生编号
int cid[maxn]; //班级编号
char name[maxn][maxl];
int score[maxn][]; //四科成绩加平均成绩
int removed[maxn]; //记录名单中的学生是否被删除,删除了值为1 const char* course_name[] = {"Chinese", "Mathematics", "English", "Programming"}; void print_menu(void)
{
printf("Welcome to Student Performance Management System (SPMS).\
\n\n1 - Add\n2 - Remove\n3 - Query\n4 - Show ranking\n5 - Show Statistics\n0 - Exit\n");
} int ranki(int k)
{
int r=;
for(int i=;i<n;i++){
if(removed[i]==&&score[i][]>score[k][])r++;
}
return r;
} void DQ(int isq)
{
char s[maxl];
for(;;){
printf("Please enter SID or name. Enter 0 to finish.\n");
scanf("%s",s);
if(strcmp(s,"")==)break;
int r=;
for(int i=;i<n;i++)if(!removed[i]){
if(strcmp(sid[i],s)==||strcmp(name[i],s)==){
if(isq)printf("%d %s %d %s %d %d %d %d %d %.2f\n",
ranki(i),sid[i],cid[i],name[i],score[i][],score[i][],
score[i][],score[i][],score[i][],score[i][]/4.0+ESP);
else{
removed[i]=;
r++;
}
}
}
if(!isq)printf("%d student(s) removed.\n",r);
}
} void add()
{
int flag;
for(;;){
flag=true;
printf("Please enter the SID, CID, name and four scores. Enter 0 to finish.\n");
scanf("%s",sid[n]);
if(strcmp(sid[n],"")==)break;
scanf("%d%s%d%d%d%d",&cid[n],name[n],&score[n][],&score[n][],&score[n][],&score[n][]);
score[n][]=score[n][]+score[n][]+score[n][]+score[n][];
removed[n]=;
for(int i=;i<n;i++){
if(removed[i]==&&strcmp(sid[n],sid[i])==){
flag=false;
printf("Duplicated SID.\n");
}
}
if(flag)n++;
}
} double get_class(int p,int q,int& passed,int& failed)
{
double sc=;
for(int i=;i<n;i++){
if(removed[i]==){
if(p==){
sc+=score[i][q];
if(score[i][q]>=)passed++;
else failed++;
}
else if(cid[i]==p){
sc+=score[i][q];
if(score[i][q]>=)passed++;
else failed++;
}
}
}
sc/=(passed+failed);
return sc;
} void get_overall(int p)
{
int a=,b=,c=,d=,e=,co;
for(int i=;i<n;i++){
co=;
if(removed[i]==){
if(p==){
if(score[i][]>=)co++;
if(score[i][]>=)co++;
if(score[i][]>=)co++;
if(score[i][]>=)co++;
if(co>=)a++;
if(co>=)b++;
if(co>=)c++;
if(co==)d++;
else if(co==)e++;
}
else if(cid[i]==p){
if(score[i][]>=)co++;
if(score[i][]>=)co++;
if(score[i][]>=)co++;
if(score[i][]>=)co++;
if(co>=)a++;
if(co>=)b++;
if(co>=)c++;
if(co==)d++;
else if(co==)e++;
}
}
}
printf("Overall:\n");
printf("Number of students who passed all subjects: %d\n",d);
printf("Number of students who passed 3 or more subjects: %d\n",c);
printf("Number of students who passed 2 or more subjects: %d\n",b);
printf("Number of students who passed 1 or more subjects: %d\n",a);
printf("Number of students who failed all subjects: %d\n",e); } void stat()
{
int p; //班级,0代表全年级
printf("Please enter class ID, 0 for the whole statistics.\n");
scanf("%d",&p);
for(int i=;i<;i++){
int passed=,failed=;
double average;
average=get_class(p,i,passed,failed);
printf("%s\n",course_name[i]);
printf("Average Scored: %.2f\n",average);
printf("Number of passed students: %d\n",passed);
printf("Number of failed students: %d\n\n",failed);
}
get_overall(p); }
/*void f(){
for(int i=0;i<n;i++){
if(removed[i]==0)
printf("%d %s %d %s %d %d %d %d %d %.2f*******\n",\
ranki(i),sid[i],cid[i],name[i],score[i][0],score[i][1],\
score[i][2],score[i][3],score[i][4],score[i][4]/4.0+ESP);
}
}*/
int main()
{
for(;;){
int choice;
print_menu();
scanf("%d",&choice);
if(choice==)break;
if(choice==)add();
if(choice==)DQ();
if(choice==)DQ();
if(choice==)printf("Showing the ranklist hurts students' self-esteem.Don't do that.\n");
if(choice==)stat();
// f();
}
//system("pause");
return ;
}
A Typical Homework(学生信息管理系统)的更多相关文章
- 基于数据库MySQL的简易学生信息管理系统
通过这几天学习Mysql数据库,对其也有了基本的了解,为了加深印象,于是就写了一个最简易的学生信息管理系统. 一:基本要求 1.通过已知用户名和密码进行登录: 2.可以显示菜单: 3.可以随时插入学生 ...
- C++ 简单的学生信息管理系统
// // main.cpp // 2013-7-17作业1 // // Created by 丁小未 on 13-7-17. // Copyright (c) 2013年 dingxiaowei. ...
- 学生信息管理系统v1.0
昨天一个教师朋友找到我,告诉我现在学期末他工作比较忙.需要统计处理很多学生信息,想让我帮他做一个管理系统.实现的功能就是把WPS表格转化成Word文档,将每一个学生的信息都能够分开,并且要根据名字找到 ...
- Java 实现学生信息管理系统
编写一个简单的学生管理信息系统. 在oracle中设计一张学生表,以学号作为关键字. 其他学生信息有:姓名.手机号. 在进入系统时,显示如下菜单: ************************** ...
- 学生信息管理系统应用ios源码iPad版
学生信息管理系统应用iPad版,该应用源码比较完整的,而且也很详细,这也是一款学校用的学生和老师管理系统,里面涉及到了很多ipad常用的控件,操作和数据存储. <ignore_js_op> ...
- PHP实现简单的学生信息管理系统(web版)
(∩_∩) 1.概述 学了php的一些基础,包括HTML,php,pdo,mysql操作等,一直都没有将它们有机结合.最近写了一个简单的网页版学生信息管理系统,前台用HTML,脚本用到了JavaScr ...
- 大一C语言结课设计之《学生信息管理系统》
第一次写这么长的程序,代码仅供參考,有问题请留言. /* ** 学生信息管理系统 ** IDE:Dev-Cpp 4.9.9.2 ** 2014-6-15 */ #include <stdio.h ...
- struts2学生信息管理系统篇章①
最近在看java1234分享的一个Struts2的学生信息管理系统的知识.因为本身java没什么底子.所以就没有什么好的技术去解决问题.一直在百度,不懂就百度.这样子下来其实也能学到一些东西,过阵子等 ...
- Android(java)学习笔记195:学生信息管理系统案例(SQLite + ListView)
1.首先说明一个知识点,通常我们显示布局文件xml都是如下: setContentView(R.layout.activity_main): 其实每一个xml布局文件就好像一个气球,我们可以使用Vie ...
随机推荐
- POJ 1011 - Sticks DFS+剪枝
POJ 1011 - Sticks 题意: 一把等长的木段被随机砍成 n 条小木条 已知他们各自的长度,问原来这些木段可能的最小长度是多少 分析: 1. 该长度必能被总长整除 ...
- Apache配置多个监听端口和不同的网站目录的简单方法(转)
转自http://www.waaqi.com/archives/707.html 由于开发的多项目,每个项目又要独立,要用根目录地址. 所以这时候我们需要配置多个不同目录的Apache,如果是外部网可 ...
- HDFS配置文件内容解释
配置概述 hadoop-env.sh 一个可由hadoop脚本调用的bourne shell文件,它制定hadoop要用的JDK环境变量.守护进程JDK选项.pid文件和log文件夹 core-sit ...
- jquery取元素值
var j = 1; if (rows.length > 0) { for (var i = 0; i < rows.length; i++) { var row = rows[i]; i ...
- 使用filter统一设置编码
1.写一个类EncodingFilter.java,实现javax.servlet.Filter(文件命名做到见名知意) package com.filter; import java.io.IOEx ...
- The JRE could not be found.Edit the server and change the JRE location.
之前更改了了一个较低的jdk的版本看了看一个项目的代码,不知所云,然后再改回来, 混乱之中只要启动Tomcat就出现这种错误,还是无法找到JRE,最后如此解决: 在Windows->Prefer ...
- qt之窗口换肤(一个qss的坑:当类属性发现变化时需要重置qss,使用rcc资源文件)
1.相关文章 Qt 资源系统qt的moc,uic,rcc命令的使用 2.概要 毕业两年了,一直使用的是qt界面库来开发程序,使用过vs08.10.13等开发工具,并安装了qt的插件,最近在做客户 ...
- PowerShell为什么强大
PowerShell为什么强大 本文索引 [隐藏] 5.1举例介绍 1破天荒的方便 2面向对象 3绑上.NET这棵大树 4强大的兼容性 5基于平台的可扩展性 微软是一个很”低调”的公司,取名为微软,感 ...
- 通过实现Comparable接口结合TreeSet来对对象自动排序
经过会遇到这样的情况,对于某个对象数组或者链表要按照一定的规则进行排序,那么我们该怎么做呢? 如遇到这样的需求: 1.需求1 对于学生对象按照年龄进行排序,年龄小的排在前面. 单单看到这样的需求,实现 ...
- linux svn用法
创建一个版本库.项目目录. 创建一个版本库: svnadmin create ~/SVNTestRepo 创建一个项目目录: svn mkdir file:///home/lsf/SVNTestRep ...