C++實(shí)現(xiàn)簡單班級成績管理系統(tǒng)
本文實(shí)例為大家分享了C++實(shí)現(xiàn)簡單班級成績管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
#include<iostream> #include<fstream> #include<cstring> #include <stdlib.h> #include <conio.h> using namespace std; int n=0; class Student {public: ? ?? ?string name; ? ? string num; ? ? char cclass[20]; ? ? int lisan; ? ? int gaoshu; ? ? int dianlu; ? ? int sum; ? ? /*--------------------------輸入函數(shù)-----------------------------*/ ? ? void input() ? ? { ? ? ? ? cout<<"\t請輸入姓名:"; ? ? ? cin>>name; ? ? ? ? cout<<"\t請輸入學(xué)號:"; ? ? ? cin>>num; ? ? ? ? cout<<"\t請輸入班級:"; ? ? ? cin>>cclass; ? ? ? ? cout<<"\t請輸入離散成績:"; ? cin>>lisan; ? ? ? ? cout<<"\t請輸入高數(shù)成績:"; ? cin>>gaoshu; ? ? ? ? cout<<"\t請輸入電路成績:"; ? cin>>dianlu; ? ? ? ? sum=lisan+gaoshu+dianlu; ? ? } ? ? /*------------------------------show函數(shù)------------------------*/ ? ? void show() ? ? { ? ? ? ? cout<<"姓名:"<<name<<endl; ? ? ? ? cout<<"學(xué)號:"<<num<<endl; ? ? ? ? cout<<"班級:"<<cclass<<endl; ? ? ? ? cout<<"離散:"<<lisan<<endl; ? ? ? ? cout<<"高數(shù):"<<gaoshu<<endl; ? ? ? ? cout<<"電路"<<dianlu<<endl; ? ? ? ? cout<<"總成績"<<sum<<endl; ? ? } }; /*------------------------------創(chuàng)建類------------------------------*/ class Message {public: ? ? Message(){}; ? ? ~Message(){}; ? ? Student stu[20]; ? ? void menu(); ? ? void add(); ? ? void display(); ? ? int sname(string x); ? ? int snum(string y); ? ? void find(); ? ? void change(); ? ? void sort(); ? ? void dele(); }; /*------------------------------菜單------------------------------*/ void Message::menu() { ? ? cout<<"--------------*班級成績管理系統(tǒng)*--------------"<<endl; ? ? cout<<"--------------*$1. 增加學(xué)生成績*--------------"<<endl; ? ? cout<<"--------------*$2. 顯示學(xué)生成績*--------------"<<endl; ? ? cout<<"--------------*$3. 更改學(xué)生成績*--------------"<<endl; ? ? cout<<"--------------*$4. 排序?qū)W生成績*--------------"<<endl; ? ? cout<<"--------------*$5. 查找學(xué)生成績*--------------"<<endl; ? ? cout<<"--------------*$6. 刪除學(xué)生成績*--------------"<<endl; ? ? cout<<"--------------*$7. 退出成績系統(tǒng)*--------------"<<endl; } /*------------------------------添加數(shù)據(jù)------------------------------*/ void Message::add() { ? ? stu[n++].input(); ? ? cout<<"添加成功!輸入任意字符繼續(xù):"; ? ? getch(); } /*------------------------------顯示數(shù)據(jù)------------------------------*/ void Message::display() { ? ? for(int x=0;x<n;x++) ? ? stu[x].show(); ? ? cout<<"輸入任意字符繼續(xù):"; ? ? getch(); } /*------------------------------查找函數(shù)------------------------------*/ int Message::sname(string na) { ? ? int i; ? ? for(i=0;i<n;i++) ? ? { ? ? ? ? if(stu[i].name==na) ? ? ? ? ? ?return i; ? ? } ? ? return -1; } int Message::snum(string nu) { ? ? int i; ? ? for(i=0;i<n;i++) ? ? { ? ? ? ? if(stu[i].num==nu) ? ? ? ? ? ?return i; ? ? } ? ? return -1; } void Message::find() { ? ? int a; ? ? int z; ? ? string ap,bp; ? ? cout<<"請選擇查找方式:1.按學(xué)號查找"<<endl; ? ? cout<<" ? ? ? ? ? ? ? ?2.按姓名查找"<<endl; ? ? cout<<"請輸入1或2:"; ? ? cin>>a; ? ? switch(a) ? ? { ? ? case 1:{ ? ? ? ? cout<<"請輸入需查找學(xué)生的學(xué)號:"; ? ? ? ? cin>>bp; ? ? ? ? z=snum(bp); ? ? ? ? if(z!=-1) ? ? ? ? stu[z].show(); ? ? ? ? else ? ? ? ? cout<<"沒有找到該學(xué)生"<<endl; ? ? ? ? cout<<"輸入任意字符繼續(xù)"<<endl; ? ? ? ? getch(); ? ? ? ? break; ? ? } ? ? case 2:{ ? ? ? ? cout<<"請輸入需查找學(xué)生的姓名:"; ? ? ? ? cin>>ap; ? ? ? ? z=sname(ap); ? ? ? ? if(z!=-1) ? ? ? ? stu[z].show(); ? ? ? ? else ? ? ? ? cout<<"沒有找到該學(xué)生"<<endl; ? ? ? ? cout<<"輸入任意字符繼續(xù)"<<endl; ? ? ? ? getch(); ? ? ? ? break; ? ? } ? ? } } /*------------------------------更改數(shù)據(jù)------------------------------*/ void Message::change() { ? ? int k; ? ? string cp; ? ? cout<<"請輸入需修改學(xué)生學(xué)號:"; ? ? cin>>cp; ? ? k=snum(cp); ? ? if(k!=-1) ? ? {cout<<"已找到,請輸入新的信息。"<<endl; ? ? stu[k].input();} ?? ?else ?? ?cout<<"沒有該生信息"<<endl; ? ? cout<<"輸入任意字符繼續(xù):"; ? ? getch(); } /*------------------------------數(shù)據(jù)排序------------------------------*/ void Message::sort() { ? ? int k,j,t,flag=0; ? ? for(j=0;j<n-1;j++){ ? ? ? ? for( k = 0; k < n-1-j; k++) ? ? ? ?if (stu[k].sum>stu[k+1].sum) ? ? ? ?{t=stu[k].sum;stu[k].sum=stu[k+1].sum;stu[k+1].sum=t;flag=1;} ? ? ? ?if (flag==0) ? ? ? ?break; ? ? } ? ? for( k = 0; k <n; k++ ) ? ? cout<<stu[k].sum<<endl; ? ? cout<<"輸入任意字符繼續(xù)";?? ?getch(); } /*------------------------------刪除數(shù)據(jù)------------------------------*/ void Message::dele() { ? ? int y; ? ? string dp; ? ? cout<<"請輸入要?jiǎng)h除學(xué)生的學(xué)號:"; ? ? cin>>dp; ? ? y=snum(dp); ? ? if(y!=-1) ? ? { ? ? for(;y<n;y++) ? ? {stu[y].name=stu[y+1].name; ? ? stu[y].num=stu[y+1].num; ? ? strcpy(stu[y].cclass,stu[y+1].cclass); ? ? stu[y].lisan=stu[y+1].lisan; ? ? stu[y].gaoshu=stu[y+1].gaoshu; ? ? stu[y].dianlu=stu[y+1].dianlu; ? ? } ? ? n--; ? ? } ? ? else ? ? cout<<"輸入錯(cuò)誤,找不到該生信息"<<endl; ? ? cout<<"輸入任意字符繼續(xù)"; ? ? getch(); ? } /*------------------------------主函數(shù)------------------------------*/ int main() { ? ? int y; ? ? string ss="y"; ? ? Message h; ? ? do ? ? { ? ? system("cls"); ? ? cout<<"====================歡迎進(jìn)入班級成績管理系統(tǒng)!===================="<<endl; ? ? h.menu(); ? ? cout<<"請輸入相應(yīng)的阿拉伯?dāng)?shù)字:"; ? ? cin>>y; ? ? switch(y) ? ? { ? ? case 1:h.add();break; ? ? case 2:h.display();break; ? ? case 3:h.change();break; ? ? case 4:h.sort();break; ? ? case 5:h.find();break; ? ? case 6:h.dele();break; ? ? case 7:ss="n";break; ? ? } ?? ?}while(ss=="y"); ? ? return 0; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++和OpenCV實(shí)現(xiàn)圖像字符化效果
圖像字符化的意思是將圖像以字符形式呈現(xiàn),具有一定的娛樂價(jià)值,許多開發(fā)人員通過python實(shí)現(xiàn)該功能,C++實(shí)現(xiàn)的代碼較少,因此本文通過C++和OpenCV實(shí)現(xiàn),給予C++開發(fā)人員一些可供借鑒的思路,需要的朋友可以參考下2022-06-06C語言程序設(shè)計(jì)第五版譚浩強(qiáng)課后答案(第二章答案)
這篇文章主要介紹了C語言程序設(shè)計(jì)第五版譚浩強(qiáng)課后答案(第二章答案),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2021-04-04使用C++實(shí)現(xiàn)插件模式時(shí)的避坑要點(diǎn)(推薦)
這篇文章主要介紹了使用C++實(shí)現(xiàn)插件模式時(shí)的避坑要點(diǎn),本文主要分析實(shí)踐中常見的、因?yàn)閷υ聿磺宄愠鰜淼漠a(chǎn)品里的坑,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-08-08C++求1到n中1出現(xiàn)的次數(shù)以及數(shù)的二進(jìn)制表示中1的個(gè)數(shù)
這篇文章主要介紹了C++求1到n中1出現(xiàn)的次數(shù)以及數(shù)的二進(jìn)制表示中1的個(gè)數(shù),兩道基礎(chǔ)的算法題目,文中也給出了解題思路,需要的朋友可以參考下2016-02-02C語言實(shí)現(xiàn)求最大公約數(shù)的三種方法
最大公因數(shù),也稱最大公約數(shù)、最大公因子,指兩個(gè)或多個(gè)整數(shù)共有約數(shù)中最大的一個(gè)。本文將為大家介紹三種方法來實(shí)現(xiàn)求解兩個(gè)正整數(shù)的最大公約數(shù),需要的可以參考一下2021-12-12