C++實現(xiàn)簡單班級成績管理系統(tǒng)
更新時間:2022年02月25日 16:09:42 作者:唐納特
這篇文章主要為大家詳細(xì)介紹了C++實現(xiàn)簡單班級成績管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C++實現(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<<"請輸入要刪除學(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<<"輸入錯誤,找不到該生信息"<<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語言程序設(shè)計第五版譚浩強(qiáng)課后答案(第二章答案)
這篇文章主要介紹了C語言程序設(shè)計第五版譚浩強(qiáng)課后答案(第二章答案),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2021-04-04C++求1到n中1出現(xiàn)的次數(shù)以及數(shù)的二進(jìn)制表示中1的個數(shù)
這篇文章主要介紹了C++求1到n中1出現(xiàn)的次數(shù)以及數(shù)的二進(jìn)制表示中1的個數(shù),兩道基礎(chǔ)的算法題目,文中也給出了解題思路,需要的朋友可以參考下2016-02-02