C++實現簡單班級成績管理系統(tǒng)
更新時間:2022年02月25日 16:09:42 作者:唐納特
這篇文章主要為大家詳細介紹了C++實現簡單班級成績管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C++實現簡單班級成績管理系統(tǒng)的具體代碼,供大家參考,具體內容如下
#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;
? ? /*--------------------------輸入函數-----------------------------*/
? ? void input()
? ? {
? ? ? ? cout<<"\t請輸入姓名:"; ? ? ? cin>>name;
? ? ? ? cout<<"\t請輸入學號:"; ? ? ? cin>>num;
? ? ? ? cout<<"\t請輸入班級:"; ? ? ? cin>>cclass;
? ? ? ? cout<<"\t請輸入離散成績:"; ? cin>>lisan;
? ? ? ? cout<<"\t請輸入高數成績:"; ? cin>>gaoshu;
? ? ? ? cout<<"\t請輸入電路成績:"; ? cin>>dianlu;
? ? ? ? sum=lisan+gaoshu+dianlu;
? ? }
? ? /*------------------------------show函數------------------------*/
? ? void show()
? ? {
? ? ? ? cout<<"姓名:"<<name<<endl;
? ? ? ? cout<<"學號:"<<num<<endl;
? ? ? ? cout<<"班級:"<<cclass<<endl;
? ? ? ? cout<<"離散:"<<lisan<<endl;
? ? ? ? cout<<"高數:"<<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. 增加學生成績*--------------"<<endl;
? ? cout<<"--------------*$2. 顯示學生成績*--------------"<<endl;
? ? cout<<"--------------*$3. 更改學生成績*--------------"<<endl;
? ? cout<<"--------------*$4. 排序學生成績*--------------"<<endl;
? ? cout<<"--------------*$5. 查找學生成績*--------------"<<endl;
? ? cout<<"--------------*$6. 刪除學生成績*--------------"<<endl;
? ? cout<<"--------------*$7. 退出成績系統(tǒng)*--------------"<<endl;
}
/*------------------------------添加數據------------------------------*/
void Message::add()
{
? ? stu[n++].input();
? ? cout<<"添加成功!輸入任意字符繼續(xù):";
? ? getch();
}
/*------------------------------顯示數據------------------------------*/
void Message::display()
{
? ? for(int x=0;x<n;x++)
? ? stu[x].show();
? ? cout<<"輸入任意字符繼續(xù):";
? ? getch();
}
/*------------------------------查找函數------------------------------*/
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.按學號查找"<<endl;
? ? cout<<" ? ? ? ? ? ? ? ?2.按姓名查找"<<endl;
? ? cout<<"請輸入1或2:";
? ? cin>>a;
? ? switch(a)
? ? {
? ? case 1:{
? ? ? ? cout<<"請輸入需查找學生的學號:";
? ? ? ? cin>>bp;
? ? ? ? z=snum(bp);
? ? ? ? if(z!=-1)
? ? ? ? stu[z].show();
? ? ? ? else
? ? ? ? cout<<"沒有找到該學生"<<endl;
? ? ? ? cout<<"輸入任意字符繼續(xù)"<<endl;
? ? ? ? getch();
? ? ? ? break;
? ? }
? ? case 2:{
? ? ? ? cout<<"請輸入需查找學生的姓名:";
? ? ? ? cin>>ap;
? ? ? ? z=sname(ap);
? ? ? ? if(z!=-1)
? ? ? ? stu[z].show();
? ? ? ? else
? ? ? ? cout<<"沒有找到該學生"<<endl;
? ? ? ? cout<<"輸入任意字符繼續(xù)"<<endl;
? ? ? ? getch();
? ? ? ? break;
? ? }
? ? }
}
/*------------------------------更改數據------------------------------*/
void Message::change()
{
? ? int k;
? ? string cp;
? ? cout<<"請輸入需修改學生學號:";
? ? cin>>cp;
? ? k=snum(cp);
? ? if(k!=-1)
? ? {cout<<"已找到,請輸入新的信息。"<<endl;
? ? stu[k].input();}
?? ?else
?? ?cout<<"沒有該生信息"<<endl;
? ? cout<<"輸入任意字符繼續(xù):";
? ? getch();
}
/*------------------------------數據排序------------------------------*/
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();
}
/*------------------------------刪除數據------------------------------*/
void Message::dele()
{
? ? int y;
? ? string dp;
? ? cout<<"請輸入要刪除學生的學號:";
? ? 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();
?
}
/*------------------------------主函數------------------------------*/
int main()
{
? ? int y;
? ? string ss="y";
? ? Message h;
? ? do
? ? {
? ? system("cls");
? ? cout<<"====================歡迎進入班級成績管理系統(tǒng)!===================="<<endl;
? ? h.menu();
? ? cout<<"請輸入相應的阿拉伯數字:";
? ? 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;
}


以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
C語言中pthread_exit和pehread_join的使用
pthread_exit用于強制退出一個線程,pthread_join用于阻塞等待線程退出,獲取線程退出狀態(tài),本文主要介紹了C語言中pthread_exit和pehread_join函數的使用,具有一定的參考價值,感興趣的可以了解一下2024-02-02

