学生成绩管理系统

《面向对象程序设计》课程实验报告

 

学生成绩管理系统

 

班级  计算机应用091 姓名唐俊驰    学号  2009052023   日期  2010-12-26              

 

一、        需求分析

1.  程序的功能:学生数据的录入、添加、修改与删除;成绩统计并排名;学生数据的读取与存储等基本功能。

2.  输入输出的要求:输入学生的成绩及处理要求;输出自己想得到的结果

3.  测试数据。  zhang       123  58    69    74

wang       456  78    96    58

yang           789  89    68    59

二、        详细设计

1.  程序框架设计:

设置了添加、修改、删除、查找、排序和对数据的读取、保存等功能。

2.  程序详细设计

添加:创建一个新的分类,用输入的变量初始化这个类,并用指针链接上一个对象。

修改:先通过链表找到要修改的对象,在输入要修改的值,利用类内函数对值进行修改。

删除:根据输入的条件找到要删除的对象,将此对象的next指针赋值给上一个对象的next值。

查找:按照学号或者姓名按链表查找对象,找到后输出该对象的基本信息。

排序:利用比较法,按照要求的标准进行排序。

数据的读取和保存:文件的打开和关闭,并按照存储的格式读取。

三、        调试分析

1.  调试中遇到的问题及对问题的解决方法

 

四、        使用说明及测试结果

1.  系统配置:Windows XP SP3;VC 6.0

2.  系统运行效果图

                       

 

 

 

 

 

 

五、        源程序(带注释)

1.程序代码

/*stu.cpp*/

#include<iostream>

 

#include ".\ClassHead.h"

 

using namespace std;

void main() {

   char c;

   cla a;

   do {

          cout<<"\n score systerm:\n"; 

          cout<<" 1……add \n";

          cout<<" 2……delete \n";

          cout<<" 3……change \n";

          cout<<" 4……look for\n";

          cout<<" 5……paixu\n";

          cout<<" 6……save \n";

          cout<<" 7……read \n";

          cout<<" 8……back \n"; 

          cout<<"choose(1-8):";

          cin>>c;

          switch(c) {

          case '1':

                 a.sadd();

                 break;

          case '2':

                 a.sremove();

                 break;

          case '3':

                 a.samend();

                 break;

          case '4':

                 a.ssearch();

                 break;

          case '5':

                 a.staxis();

                 break;

          case '6':

                 a.ssave();

                 break;

          case '7':

                 a.sload();

                 break;

          }

         

   }while(c!='8');

}

 

/*类的定义及其成员函数的实现*/

#ifndef _CLASSHEAD_H

#define _CLASSHEAD_H

#include<iomanip>

#include<fstream>

#include<string>

#define max 80;

using namespace std;

 

class student {

public:

       student *next;

public:

       string name;

       long num;

       int x,y,z;

       int AA;

       void play() {

              cout << name << "student's numbers" << num << ",math:" << x

                     << ",language:" << y << ",english:" << z << ",in total:" << AA << endl;

       };

       student(string sname,long snum,int sx,int sy,int sz) {

              name = sname;

              num = snum;

              x = sx;

              y = sy;

              z = sz;

       }

};

 

 

class cla {

public:

       cla() {

              stu = 0;

              sload();

       }

       ~cla() {

              student *p;

              p = stu;

              while(p) {

                     p = p->next;

                     delete stu;

                     stu = p;

              }

              stu = 0;

       }

       void sadd(); 

       void sremove(); 

       void samend(); 

       void ssearch(); 

       void staxis(); 

       void ssave(); 

       void sload();

      

       void pxh();

       void psx();

       void pyw();

       void pyy();

       void pAA();

private:

       student *stu; 

};

 

void cla::sadd() {

       student *q;

       string name1;

       long num1;

       int x1,y1,z1;

      

      

      

       system("cls");

       cout << "\n **add student** \n" << endl;

       cout << "please input:" << endl;

       cout << "name\tnumber\tmath\tlanguage\tenglish:" << endl;

       cin >> name1 >> num1 >> x1 >> y1 >> z1;

      

       q = new student(name1,num1,x1,y1,z1);

       q->next = 0;

       q->AA = x1 + y1 + z1;

      

       if(stu) {

              student *t;

              t = stu;

              if(t->num == num1) {

                     cout << "number has already been recorded,please input again" << endl;

                     return;

              }

              while(t->next) {

                     if(t->num == num1) {

                            cout << "number has already been recorded,please input again" << endl;

                            return;

                     }

                     t = t->next;

              }

              t->next = q;

       }

       else {

              stu = q;

       }

       cout << "down" << endl;

}

 

void cla::sremove() {

       system("cls");

       int num1;

       cout << "\n** delete **\n";

       cout << "please input the number you want to delete:";

       cin >> num1;

      

       student *p1,*p2;

       p1 = stu;

       while(p1) {

              if(p1->num == num1)

                     break;

              else {

                     p2 = p1;

                     p1 = p1->next;

              }

       }

      

       if(p1 != NULL) {

              p1->play();

              cout << "[Y/N]" << endl;

              char c;

              cin >> c;

              if(toupper(c)!='Y')

                     return;

             

              if(p1==stu) {

                     stu = p1->next;

                     delete p1;

              }

              else {

                     p2->next = p1->next;

                     delete p1;

              }

              cout << "find the number is:" << num1 << "  delete\n";

       }

       else

              cout << "there's no information about that!\n";

}

 

void cla::samend() {

       system("cls");

       long num1;

       cout << "\n** change the student number**\n";

       cout << "input the changing number";

       cin >> num1;

      

       student *p1,*p2;

       p1 = stu;

       while(p1) {

              if(p1->num == num1)

                     break;

              else {

                     p2 = p1;

                     p1 = p1->next;

              }

       }

       if(p1!=NULL) {

              cout << "the number is" << num1 << "'information" << endl;

              cout << "name "<<p1->name<<"math"<<p1->x<<"language"<<p1->y<<"english"<<p1->z<<endl;

              cout<<"please the changing information:name math language english"<<endl;

              cin>>p1->name>>p1->x>>p1->y>>p1->z;

              p1->AA=p1->x+p1->y+p1->z;

              cout<<"change suceed"<<endl;

       }

       else

              cout<<"no found!\n";

}

 

void cla::ssearch() {

       system("cls");

       cout<<"\n** look for **\n"<<endl;

       cout<<"please input the way:"<<endl;

       cout<<"1.number"<<endl;

       cout<<"2.name"<<endl;

       cout<<"3.return"<<endl;

       char c;

       cin>>c;

       switch (c) {

       case '1':

              {

                     long num1;

                     cout<<"the number"<<endl;

                     cin>>num1;

                    

                     student *p1,*p2;

                     p1=stu;

                     while(p1) {

                            if(p1->num==num1)

                                   break;

                            else {

                                   p2=p1;

                                   p1=p1->next;

                            }

                     }

                    

                     if(p1!=NULL) {

                            cout<<"muber is"<<num1<<" information"<<endl;

                            cout<<"name:"<<p1->name<<" math:"<<p1->x<<" language:"<<p1->y<<" english:"<<p1->z<<endl;

                            cout<<"down";

                     }

                     else

                            cout<<"no foud!\n";

                     break;

              }

       case '2':

              {

                     string name1;

                     cout<<"the name"<<endl;

                     cin>>name1;

                    

                     student *p1,*p2;

                     p1=stu;

                     while(p1) {

                            if(p1->name==name1)

                                   break;

                            else {

                                   p2=p1;

                                   p1=p1->next;

                            }

                     }

                    

                     if(p1!=NULL) {

                            cout<<name1<<"information"<<endl;

                            cout<<"number:"<<p1->num<<" math:"<<p1->x<<" language:"<<p1->y<<" english:"<<p1->z<<endl;

                            cout<<"down...";

                     }

                     else

                            cout<<"no foud!\n";

                     break;

              }

       case '3':

              return;

       }

      

}

 

void cla::pxh() {

       student *p1,*p2;

       int n;

       p1=stu;

       n=1;

       while(p1->next) {

              n++;

              p1=p1->next;

       }

       cout<<"have"<<n<<"message..."<<endl;

       int i;

       p1=stu;

       for(i=1;i<n;i++) {

              p1=stu;

              if (p1->num>p1->next->num) {

                     p2=p1->next;

                     p1->next=p1->next->next;

                     p2->next=p1;

                     stu=p2;

              }

              p1=stu;

              while(p1->next->next) {

                     p2=p1;

                     p1=p1->next;

                     if(p1->num>p1->next->num) {

                            p2->next=p1->next;

                            p1->next=p1->next->next;

                            p2->next->next=p1;

                            p1=p2->next;

                     }

              }

       }

      

       p1=stu;

       do {

              p1->play();

              p1=p1->next;

       }while(p1);

}

 

void cla::psx() {

       student *p1,*p2;

       int n;

       p1=stu;

       n=1;

       while(p1->next) {

              n++;

              p1=p1->next;

       }

       cout<<"have"<<n<<"message..."<<endl;

       int i;

       p1=stu;

       for(i=1;i<n;i++) {

              p1=stu;

              if (p1->x>p1->next->x) {

                     p2=p1->next;

                     p1->next=p1->next->next;

                     p2->next=p1;

                     stu=p2;

              }

              p1=stu;

              while(p1->next->next) {

                     p2=p1;

                     p1=p1->next;

                     if(p1->x>p1->next->x) {

                            p2->next=p1->next;

                            p1->next=p1->next->next;

                            p2->next->next=p1;

                            p1=p2->next;

                     }    

              }

       }

       p1=stu;

       do {

              p1->play();

              p1=p1->next;

       }while(p1);

}

 

 

void cla::pyw() {

       student *p1,*p2;

       int n;

       p1=stu;

       n=1;

       while(p1->next) {

              n++;

              p1=p1->next;

       }

       cout<<"have"<<n<<"message..."<<endl;

       int i;

       p1=stu;

       for(i=1;i<n;i++) {

              p1=stu;

              if (p1->y>p1->next->y) {

                     p2=p1->next;

                     p1->next=p1->next->next;

                     p2->next=p1;

                     stu=p2;

              }

              p1=stu;

              while(p1->next->next) {

                     p2=p1;

                     p1=p1->next;

                     if(p1->y>p1->next->y) {

                            p2->next=p1->next;

                            p1->next=p1->next->next;

                            p2->next->next=p1;

                            p1=p2->next;

                     }

              }

       }

       p1=stu;

       do {

              p1->play();

              p1=p1->next;

       }while(p1);

}

 

void cla::pyy() {

       student *p1,*p2;

       int n;

       p1=stu;

       n=1;

       while(p1->next) {

              n++;

              p1=p1->next;

       }

       cout<<"have"<<n<<"message..."<<endl;

       int i;

       p1=stu;

       for(i=1;i<n;i++) {

              p1=stu;

              if (p1->z>p1->next->z) {

                     p2=p1->next;

                     p1->next=p1->next->next;

                     p2->next=p1; 

                     stu=p2;

              }

              p1=stu;

              while(p1->next->next) {

                     p2=p1;

                     p1=p1->next;

                     if(p1->z>p1->next->z) {

                            p2->next=p1->next;

                            p1->next=p1->next->next;

                            p2->next->next=p1;

                            p1=p2->next; 

                     }

              }

       }

       p1=stu;

       do {

              p1->play();

              p1=p1->next;

       }while(p1);

}

 

void cla::pAA() {

       student *p1,*p2;

       int n;

       p1=stu;

       n=1;

       while(p1->next) {

              n++;

              p1=p1->next;

       }

       cout<<"have"<<n<<"message..."<<endl;

       int i;

       p1=stu;

       for(i=1;i<n;i++) {

              p1=stu;

              if (p1->AA>p1->next->AA) {

                     p2=p1->next;

                     p1->next=p1->next->next;

                     p2->next=p1; //头结点交换

                     stu=p2;

              }

              p1=stu;

              while(p1->next->next) { //中间的交换

                     p2=p1;

                     p1=p1->next;

                     if(p1->AA>p1->next->AA) {

                            p2->next=p1->next;

                            p1->next=p1->next->next;

                            p2->next->next=p1;

                            p1=p2->next; //交换

                     }

              }

       }

       p1=stu;

       do {

              p1->play();

              p1=p1->next;

       }while(p1);

}

 

void cla::staxis() {   //排序

       system("cls");

       char c;

       cout<<"请选择以何种方式排序:"<<endl;

       cout<<"1……number"<<endl;

       cout<<"2……math"<<endl;

       cout<<"3……language"<<endl;

       cout<<"4……english"<<endl;

       cout<<"5……total"<<endl;

       cout<<"6……return"<<endl;

       cout<<"choose(1-6)"<<endl;

       cin>>c;

      

       switch (c) {

       case '1':pxh(); break;

       case '2':psx(); break;

       case '3':pyw(); break;

       case '4':pyy(); break;

       case '5':pAA(); break;

       case '6':return;

       }

      

}

 

void cla::ssave() {

       system("cls");

       char c;

       cout<<"\nsafe,[Y/N]:";

       cin>>c;

       if(toupper(c)!='Y')

              return;

      

      

       ofstream tfile("date.txt",ios_base::binary);

       student *p=stu;

       while(p) {

              tfile<<p->name<<"\t"<<p->num<<"\t"<<p->x<<"\t"<<p->y<<"\t"<<p->z;

              tfile<<endl;

              p=p->next;

       }

       tfile.close();

       cout<<"down..."<<endl;

}

 

void cla::sload() {

       student *p;

       p=stu;

       while(p) {

              stu=p->next;

              delete p;

              p=stu;

       }

      

      

       ifstream tfile("date.txt",ios_base::binary);

      

       string name1;

       long num1;

       int x1,y1,z1;

      

       tfile>>name1>>num1>>x1>>y1>>z1;

       while(tfile.good()) {

             

              student *s;

              s=stu;

              s=new student(name1,num1,x1,y1,z1);

              s->next=0;

              s->AA=x1+y1+z1;

              if(stu) {

                     student *p2;

                     p2=stu;

                     while(p2->next) {

                            p2=p2->next;

                     }

                     p2->next=s;

              }

              else {

                     stu=s;

              }

              tfile>>name1>>num1>>x1>>y1>>z1;

       }

       tfile.close();

       cout<<"\ninformation has down...\n";

}

#endif

转载于:https://www.cnblogs.com/vmyspace/archive/2012/08/22/2651512.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/403725.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2015年第六届蓝桥杯C/C++程序设计本科B组决赛

1.积分之谜&#xff08;枚举&#xff09; 2.完美正方形 3.关联账户&#xff08;并查集&#xff09; 4.密文搜索 5.居民集会 6.模型染色 1.积分之迷 小明开了个网上商店&#xff0c;卖风铃。共有3个品牌&#xff1a;A&#xff0c;B&#xff0c;C。为了促销&#xff0c;每件商品都…

js上传文件;input上传文件;

html原生上传文件方式1&#xff1a; <!DOCTYPE html> <html><head><meta charset"utf-8" /><title>Document</title><script></script></head><body><div>选择文件(可多选):<input type&quo…

SHELL test [ 命令用法

From: http://blog.csdn.net/ubuntulover/article/details/6978305 原文地址&#xff1a;http://www.examw.com/linux/all/114976/index.htmltest命令用法。功能&#xff1a;检查文件和比较值 1&#xff09;判断表达式 if test (表达式为真) if test !表达式为假 test 表达式…

HDU-2159 FATE 二维背包

FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3955 Accepted Submission(s): 1750 Problem Description最近xhd正在玩一款叫做FATE的游戏&#xff0c;为了得到极品装备&#xff0c;xhd在不停的杀怪做任务…

vuex随记

1.下载vue 2.引入封装 import Vue from vue import Vuex from vuex import getters from ./gettersVue.use(Vuex)const modulesFiles require.context(./modules, true, /\.js$/)const modules modulesFiles.keys().reduce((modules, modulePath) > {// set ./app.js &g…

VLC源码分析总结

From: http://blog.csdn.net/lvmaker/article/details/8785936 1&#xff0e; 概述 VLC属于Video LAN开源项目组织中的一款全开源的流媒体服务器和多媒体播放器。作为流媒体服务器&#xff0c;VLC跨平台&#xff0c;支持多操作系统和计算机体系结构&#xff1b;作为多媒体播放…

android super this区别

参考http://blog.163.com/qq3076169126/blog/static/1717240672012620111028892/ 为什么要使用this&#xff0c;简单讲&#xff0c;就是方法中的某个形参与当前对象的某个成员有相同的名字&#xff0c;为了区别而使用“this.成员”。 例&#xff1a; public class DemoThis { p…

接口报Provisional headers are shown原因和解决方法

1.前端访问后端接口报has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response. 2.原因&#xff1a;可能是你的接口请求头没有设置token

Android开发用到的几种常用设计模式浅谈(一):组合模式

1&#xff1a;应用场景 Android中对组合模式的应用&#xff0c;可谓是泛滥成粥&#xff0c;随处可见&#xff0c;那就是View和ViewGroup类的使用。在android UI设计&#xff0c;几乎所有的widget和布局类都依靠这两个类。组合模式&#xff0c;Composite Pattern&#xff0c;是一…

【Linux】FTP文件下载

代码来源于网络&#xff0c;记录下&#xff0c;方便日后使用(适用于Linux平台) /*使用FTP协议获取服务器上的文件(Passive方式)1 在客户端创建一个SOCK_STREAM类型的套接字&#xff0c;并与FTP服务器端的21号命令端口连接&#xff08;因为FTP服务器的21号端口在侦听&#xff0…

分页存储过程

View Code --------------------------------------用途&#xff1a;支持任意排序的分页存储过程 --说明&#xff1a;------------------------------------CREATE PROCEDURE [dbo].[UP_GetRecordByPageOrder]tblName varchar(255), -- 表名 fldName varchar(255), -- 显示…

vuex的使用和封装

一、Vuex基本使用 1.下载vuex依赖 npm install vuex --save2.在src/store/index.js下引入使用 import Vue from vue import Vuex from vuexVue.use(Vuex)export default new Vuex.Store({state: {},mutations: {},actions: {},modules: {} })3.在main.js内&#xff0c;将stor…

Nginx下配置小绿锁https

我用的是阿里云服务器&#xff0c;centos7.2的操作系统&#xff0c;服务器类型&#xff1a;nginx/1.12.1 这是github上的官方配置https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E 刚开始配置的时候也遇到了很多坑&#xff0c;假设你已经配置好了服务器等需要准备…

win7 删除Windows服务的方法

From: http://www.jb51.net/os/windows/25090.html 一、什么是Windows服务    Windows服务也称为Windows Service&#xff0c;它是Windows操作系统和Windows网络的基础&#xff0c;属于系统核心的一部分&#xff0c;它支持着整个Windows的各种操作。诸如DNS客户端、打印程序、…

hadoop-hbase-spark单机版安装

0 需要开放的外网端口 50070&#xff0c;8088&#xff0c;60010 &#xff0c;7077 1 设置ssh免密码登录 ssh-keygen -t dsa -P -f ~/.ssh/id_dsa cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys chmod 0600 ~/.ssh/authorized_keys 2 解压安装包 tar -zxvf /usr/jxx/…

最长单调子序列及计数(poj1952)

被这个问题困住了&#xff0c;就像憋了一泡屎&#xff0c;但是便秘了&#xff0c;不往下说了&#xff0c;你懂的。 在网上查了各种资料&#xff0c;各种文章&#xff0c;其实大家说的都差不多&#xff0c;无非是枚举、求该序列和它的排序后的序列的最大公共子序列、动态规划、基…

ACM学习历程—51NOD 1685 第K大区间2(二分 树状数组 中位数)

http://www.51nod.com/contest/problem.html#!problemId1685 这是这次BSG白山极客挑战赛的E题。 这题可以二分答案t。 关键在于&#xff0c;对于一个t&#xff0c;如何判断它是否能成为第k大。 将序列中大于t的置为1&#xff0c;小于t的置为-1&#xff0c;等于t的置为0。那么区…

vue项目请求封装;axios封装使用

vue项目&#xff0c;封装axios请求方式和响应状态码&#xff1b;以及接口的api封装&#xff1b; 目录结构&#xff1a; 1.具体在src/utils/request.js下封装axios&#xff1a; ①引入axios和router ②引入element-ui是为了用提示组件 和加载组件&#xff08;可选择去掉&#…

【Bash】实现指定目录下的文件编码转换,以原文件名保存

文件名: encodeExchange.sh Linux版本&#xff1a; #!/bin/bashfEncodeUTF-8 tEncodeGBK#fEncodeGBK #tEncodeUTF-8files"Classes/*"# convert files encoding from GBK->UTF-8 or UTF-8->GBK convertFileEncode() {if [ $# -lt 3 ]; thenecho "Usage: …

linux下恢复误删文件

linux下文件实际上是一个指向inode的链接, inode链接包含了文件的所有属性, 比如权限和所有者, 数据块地址(文件存储在磁盘的这些数据块中). 当你删除(rm)一个文件, 实际删除了指向inode的链接, 并没有删除inode的内容. 进程可能还在使用. 只有当inode的所有链接完全移去, 然后…