1、设计一个成绩管理系统。包括 添加(insert),修改(update),删除(delete),查找(SQL)四个功能 成绩管理系统3个表 :学生(学号,姓名,性别);课程(课程号,课程名);成绩(学号,课程号,分数) 学生.学号与成绩.学号关联,课程.课程号与成绩.课程号关联。数据库相关知识点:表结构的操作 表记录的操作 表的查询

头文件student.h

#pragma once                 //student.h
#include<iostream>
#include<string>
using namespace std;
class Student                                                         //定义student类 ,其中有学号、名字、性别的数据成员
{public:int studentID;string name, sex;int LessonNumber;string LessonName;int score;Student(int sID,string na,string se ,int LNum,string LNa ,int sco );void showsth();};

头文件studentscore.h

#pragma once
#include<iostream>
using namespace std;
#include"student.h"
#include<fstream>
#define FILENAME "stuFile.txt"class StudentScore
{
public:StudentScore();void Show_Menu();//菜单void ExitSystem();//退出int m_StuNum;//学生人数Student** m_StuArray;void Add_Stu();//添加//保存文件void save();//判断是否为空bool m_FileIsEmpty;//统计人数int get_StuNum();//初始化学生void init_Stu();//显示学生//删除学生void Del_Stu();//判断有无int IsExist(int studentId);//修改学生void Mod_Stu();//查找学生void Find_Stu();~StudentScore();};

源文件student.cpp

#include<iostream>
using namespace std;
#include"student.h"Student::Student(int sID, string na, string se, int LNum, string LNa, int sco)
{this->studentID = sID;this->name = na;this->sex = se;this->LessonNumber = LNum;this->LessonName = LNa;this->score = sco;
}
void Student::showsth()
{cout << "学号" << this->studentID<< "\t名字" << this->name<< "\t性别" << this->sex<< "\t课程号" << this->LessonNumber<< "\t课程名" << this->LessonName<< "\t分数" << this->score;
}

源文件studentscore.cpp

#include"studentscore.h"StudentScore::StudentScore()
{//文件不存在ifstream ifs;ifs.open(FILENAME, ios::in);if (!ifs.is_open()){//测试代码cout << "文件不存在" << endl;this->m_StuNum = 0;this->m_StuArray = NULL;this->m_FileIsEmpty = true;ifs.close();return;}//文件存在,但为空。char ch;ifs >> ch;if (ifs.eof()){//测试代码cout << "文件为空" << endl;this->m_StuNum = 0;this->m_StuArray = NULL;this->m_FileIsEmpty = true;ifs.close();return;}//初始化//文件存在,有内容int num = this->get_StuNum();//测试代码cout << "现在有" << num << "人" << endl;this->m_StuNum = num;this->m_StuArray = new Student * [this->m_StuNum];this->init_Stu();//测试代码/*for (int i = 0; i < this->m_StuNum; i++){cout << "学号:" << this->m_StuArray[i]->studentID<< " 名字:" << this->m_StuArray[i]->name<< " 性别:" << this->m_StuArray[i]->sex<< " 课程号:" << this->m_StuArray[i]->LessonNumber<< " 课程名:" << this->m_StuArray[i]->LessonName<< " 分数:" << this->m_StuArray[i]->score << endl;}*/}//文件添加
void StudentScore::Add_Stu()
{cout << "请输入添加的学生数量:" << endl;int addNum = 0;cin >> addNum;if (addNum > 0){//添加//计算添加新空间的大小int newSize = this->m_StuNum + addNum;//开辟新空间Student** newSpace = new Student * [newSize];if (this->m_StuArray != NULL){for (int i = 0; i < this->m_StuNum; i++){newSpace[i] = this->m_StuArray[i];}}for (int i = 0; i < addNum; i++){int studentID;string name, sex;int LessonNumber;string LessonName;int score;cout << "请输入第" << i+1 << "个的学号" << endl;cin >> studentID;cout << "请输入第" << i + 1 << "个的名字" << endl;cin >> name;cout << "请输入第" << i + 1 << "个的性别" << endl;cin >> sex;cout << "请输入第" << i + 1 << "个的课程号" << endl;cin >> LessonNumber;cout << "请输入第" << i + 1 << "个的课程名" << endl;cin >> LessonName;cout << "请输入第" << i + 1 << "个的分数" << endl;cin >> score;Student* student = NULL;student =new Student(studentID,  name, sex,  LessonNumber,  LessonName,  score);newSpace[this->m_StuNum + i] = student;}delete [] this->m_StuArray;this->m_StuArray = newSpace;this->m_StuNum = newSize;this->m_FileIsEmpty = false;cout << "成功添加" << addNum << "名"<<endl;this->save();}else {cout << "输入有误" << endl;}system("pause");system("cls");
}//文件保存
void StudentScore::save()
{ofstream ofs;ofs.open(FILENAME, ios::out);for (int i = 0; i < this->m_StuNum; i++){ofs << this->m_StuArray[i]->studentID << " "<< this->m_StuArray[i]->name << " "<< this->m_StuArray[i]->sex << " "<< this->m_StuArray[i]->LessonNumber << " "<< this->m_StuArray[i]->LessonName << " "<< this->m_StuArray[i]->score << endl;}ofs.close();
}
int StudentScore::get_StuNum()
{ifstream ifs;ifs.open(FILENAME, ios::in);int studentID;string name, sex;int LessonNumber;string LessonName;int score;int num = 0;while (ifs >> studentID && ifs >> name && ifs >> sex && ifs >> LessonNumber && ifs >> LessonName && ifs >> score){num++;//统计人数}return num;
}
//初始化员工
void StudentScore::init_Stu()
{ifstream ifs;ifs.open(FILENAME, ios::in);int studentID;string name, sex;int LessonNumber;string LessonName;int score;int index=0;while (ifs >> studentID && ifs >> name && ifs >> sex && ifs >> LessonNumber && ifs >> LessonName && ifs >> score){Student* student = NULL;student = new Student(studentID, name, sex, LessonNumber, LessonName, score);this->m_StuArray[index] = student;index++;}ifs.close();
}//删除学生
void StudentScore::Del_Stu()
{if (this->m_FileIsEmpty){cout << "不存在" << endl;}else{cout<<"请输入学号" << endl;int studentID = 0;cin >> studentID;int index = this->IsExist(studentID);if (index != -1){ for (int i = index; i < this->m_StuNum - 1; i++){this->m_StuArray[i] = this->m_StuArray[i + 1];}this->m_StuNum--;this->save();cout << "删除成功" << endl;}else{cout<<"删除失败,无该学号" << endl;}}system("pause");system("cls");
}
//判断有无
int StudentScore::IsExist(int studentId)
{int index = -1;for (int i = 0; i < this->m_StuNum; i++){if (this->m_StuArray[i]->studentID == studentId){index = i;break;}}return index;
}
//修改学生
void StudentScore::Mod_Stu()
{if (this->m_FileIsEmpty){cout << "不存在" << endl;}else{cout << "请输入修改学号" << endl;int studentID = 0;cin >> studentID;int ret = this->IsExist(studentID);if (ret != -1){delete this->m_StuArray[ret];int newstudentID;string newname, newsex;int newLessonNumber;string newLessonName;int newscore;cout << "请输入该的学号" << endl;cin >> newstudentID;cout << "请输入该的名字" << endl;cin >> newname;cout << "请输入该的性别" << endl;cin >> newsex;cout << "请输入该的课程号" << endl;cin >> newLessonNumber;cout << "请输入该的课程名" << endl;cin >> newLessonName;cout << "请输入该的分数" << endl;cin >> newscore;Student* student = NULL;student = new Student(newstudentID, newname, newsex, newLessonNumber, newLessonName, newscore);this->m_StuArray[ret] = student;cout << "修改成功" << endl;this->save();}else{cout << "查无此人" << endl;}}system("pause");system("cls");
}
//查找学生
void StudentScore::Find_Stu()
{if (this->m_FileIsEmpty){cout << "不存在" << endl;}else{cout << "输入查找方式:" << endl;cout << "1.学号查找" << endl;cout << "2.名字查找" << endl;int select = 0;cin >> select;if (select == 1){int studentID=0;cout << "请输入学号" << endl;cin >> studentID;int ret = IsExist(studentID);if (ret != -1){cout << "查找成功,如下:" << endl;this->m_StuArray[ret]->showsth();studentID = 0;ret = 0;}else{cout << "查找失败" << endl;}}else if (select==2 ){string name;cout << "请输入名字:" << endl;cin >> name;bool flag = false;for (int i = 0; i <m_StuNum;i++){if (this->m_StuArray[i]->name == name){cout << "查找成功" << endl;flag = true;this->m_StuArray[i]->showsth();}}if (flag == false){cout << "查找失败" << endl;}}else{cout << "输入有误" << endl;}}system("pause");system("cls");
}
//文件菜单
void StudentScore::Show_Menu()
{cout << "欢迎使用成绩管理系统:" << endl<< "0.退出" << endl<< "1.添加学生信息" << endl<< "2.修改学生信息" << endl<< "3.删除学生信息" << endl<< "4.查找学生信息" << endl;}
void StudentScore::ExitSystem()
{cout << "欢迎下次使用" << endl; system("pause");exit(0);
}
StudentScore::~StudentScore()
{if (this->m_StuArray != NULL){delete[]this->m_StuArray;this->m_StuArray = NULL;}
}

主源文件 :成绩管理系统.cpp

#include<iostream>
using namespace std;
#include"studentscore.h"
#include"student.h"
int main()
{/*Student* student = NULL;student = new Student(123, "zhangsan", "nan", 1234, "yuwen", 100);student->showsth();*/StudentScore ss;int choice=0;while (true){ss.Show_Menu();cout << "请输入你的选项" << endl;cin >> choice;switch (choice){case 0:ss.ExitSystem();break;case 1:ss.Add_Stu();break; case 2:ss.Mod_Stu();break;case 3:{/*int ret = ss.IsExist(1);if (ret != -1){cout << "存在该学号" << endl;}else{cout << "不存在该学号" << endl;}*/ss.Del_Stu();break;}case 4:ss.Find_Stu();break;default:system("cls");break;}}system("pause");return 0;
}

【中南林业科技大学】【陈】第十周作业sqi成绩管理系统相关推荐

  1. 智能车竞赛技术报告 | 智能车视觉 - 中南林业科技大学 - 弃车人队

    简 介: 本文根据第十六届智能车大赛的要求,经过在实验室的不断调试,研究并设出了拥有自主循迹功能及数字和物种识别功能的以摄像头传感器为主导的 AGV实体.在循迹算法上,为了加快小车对赛道信息的采集速度 ...

  2. 中南林业科技大学计算机挂科,中南林业科技大学又出能辅导高数的“扫地僧”...

    中南林业科技大学又出能辅导高数的"扫地僧" http://image.dfdaily.com/2013/1/11/6349351437000037501.jpg [古棱峰] 自称今 ...

  3. 中南林业科技大学的计算机研究生分数线,2019中南林业科技大学研究生分数线汇总(含2016-2019历年复试)...

    2019中南林业科技大学研究生分数线(含2016-2019历年复试) 考研就是人生的第二次高考,是再一次改变自己命运的机会,所谓7分靠努力,3分靠填报,中南林业科技大学历年研究生复试分数线是2019- ...

  4. 2019春第十周作业

    第十周作业 本周作业头 这个作业属于哪个教程 C语言程序设计Ⅱ 这个作业要求在哪里 (https://edu.cnblogs.com/campus/zswxy/software-engineering ...

  5. 阜阳市乡镇企业中专学校计算机教师高翱简介,2017年中南林业科技大学博士研究生奖助学金...

    类似问题答案 2020年中南林业科技大学博士研究生奖助学金 奖助学金 为提高研究生待遇水平,保障研究生安心学习.潜心研究,我校统筹财政投入.科研经费.学费收入等各种资源,设立研究生国家奖学金.学业奖学 ...

  6. 20189200余超 2018-2019-2 移动平台应用开发实践第十周作业

    20189200余超 2018-2019-2 移动平台应用开发实践第十周作业 偏好 在Android应用中,我们常需要记录用户设置的一些偏好参数,,此时我们就需要用SharedPreferences和 ...

  7. 中南林业科技大学计算机考研资料汇总

    中南林业科技大学研招网 https://yjsb.csuft.edu.cn/ 中南林业科技大学(Central South University of Forestry and Technology) ...

  8. 2023中南林业科技大学计算机考研信息汇总

    中南林业科技大学研招网 https://yjsb.csuft.edu.cn/ 中南林业科技大学(Central South University of Forestry and Technology) ...

  9. 2018-2019-2 20189206 《网络攻防实践》 第十周作业

    2018-2019-2 20189206 <网络攻防实践> 第十周作业 First Draft of a Report on the EDVAC EDVAC (Electronic Dis ...

  10. 中南林业科技大学2012寒假放假时间安排

    关于2012年寒假放假及春节期间有关工作的通知 中南林业科技大学     2012-01-17 11:16:00 学校各部门.单位: 2012年寒假.春节将至,为更加科学.合理地安排工作,使全校师生员 ...

最新文章

  1. 话AI、学实践、探未来,亚马逊云科技AI在线大会报名开启!
  2. java中new BigDecimal的坑
  3. 安装全局消息钩子实现dll窗体程序注入
  4. Python 3 教程二:文件,目录和路径
  5. UIView CALayer
  6. wincc服务器客户端用虚拟机,什么情况下用wincc服务器与客户端
  7. mysql注入***扫描备忘;
  8. ARM指令集与Thumb指令集
  9. 阿里巴巴java规范
  10. 国内10大著名珠宝品牌
  11. {“errcode“:44001,“errmsg“:“empty media data, hint: [1655962096234893527769663], from ip: 222.72.xxx.
  12. 什么是Session 如何使用Session
  13. 梯度下降法 python_(四)梯度下降法及其python实现
  14. [C++][linux]C++实现类似C#AutoResetEvent或者win C++的SetEvent
  15. SQL Server 2012 未将对象引用设置到对象的实例。(SQLEditors)
  16. 入门电机系列之5编码器
  17. 求0到7组成奇数的个数c语言,c语言经典算法—求0—7 所能组成的奇数个数
  18. PS切图保存后的背景图为透明
  19. u盘计算机无法,计算机无法识别U盘的问题
  20. 微信小程序开发-新闻列表之新闻列表绑定

热门文章

  1. jasper报表格式化bigdecimal(decimal128)数据千分位
  2. 妙不可言的JASTVIN云域网,用过的都说好!你怎么看
  3. downwell什么意思_downwelling_downwelling是什么意思翻译
  4. 琵琶行----白居易
  5. 第一章概述-------第一节--1.3互联网的组成
  6. Python工具分析风险数据
  7. 无线扩展器中继器 和 电力猫 性能比较
  8. [附源码]PHP计算机毕业设计小斌美食网站(程序+LW)
  9. Unity 面试题汇总(五)性能优化知识点相关
  10. KERNEL_DIR、系统平台、交叉编译器的指定,以及内核模块驱动文件的签名