|
成績(jī)管理系統(tǒng) c++工程:
0.png (8.73 KB, 下載次數(shù): 62)
下載附件
2017-12-25 22:32 上傳
單片機(jī)源程序如下:
- // 學(xué)生成績(jī)管理系統(tǒng).cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include<iostream>
- #include<cstdio>
- using namespace std;
- const int Max=5;//字符串最大長(zhǎng)度
- class Student;//類聲明
- void setData(Student &s);//設(shè)置對(duì)象s的數(shù)據(jù)
- void count(Student &s);//計(jì)算對(duì)象s的總分,平均分
- void sort(Student S[],int N);//把長(zhǎng)度為N的對(duì)象數(shù)組S,按平均分排序
- double getAverage(Student S[],int N);//計(jì)算全班的平均分
- void print(Student &s);//打印信息
- int search(Student S[],int N,char *n);//從長(zhǎng)度為M的對(duì)象數(shù)組中,查找學(xué)號(hào)n的位置
- class Student
- {
- public:
- char number[Max]; //學(xué)號(hào)
- char name[Max]; //姓名
- double chinese; //語(yǔ)文成績(jī)
- double math; //數(shù)學(xué)成績(jī)
- double english; //英語(yǔ)成績(jī)
- double total; //總分
- double average; //平均分
- int rank;//只有比較才不為了0
- };
- void setData(Student &s) //成績(jī)錄入模塊
- {
- cout<<"輸入學(xué)號(hào),姓名,語(yǔ)文,數(shù)學(xué),英語(yǔ)成績(jī):";//錄入數(shù)據(jù)
- cin>>s.number>>s.name>>s.chinese>>s.math>>s.english;
- s.total=0;//初始化
- s.average=0;
- s.rank=0;
- }
- void count(Student &s)//成績(jī)統(tǒng)計(jì)
- {
- s.total=s.chinese+s.math+s.english;
- s.average=s.total/3;
- }
- void sort(Student S[],int N)//插入法排序 (成績(jī)排名)
- {
- int index;
- Student inserter;
- for(int i=1;i<N;i++)
- {
- inserter=S[i];
- index=i-1;
- while(index>=0&&inserter.average>S[index].average)
- {
- S[index+1]=S[index];
- index--;
- }
- S[index+1]=inserter;
- }
- for(int j=0;j<N;j++)
- S[j].rank=j+1;//設(shè)置排名
- }
- double getAverage(Student S[],int N)
- {
- double Average=0;
- for(int i=0;i<N;i++)
- Average+=(S[i].chinese+S[i].math+S[i].english);
- Average/=(N*3);
- return Average;
- }
- void print(Student &s) //輸出結(jié)果
- {
- cout<<"排名"<<"\t"<<"學(xué)號(hào)"<<"\t"<<"姓名"<<"\t"<<"語(yǔ)文:"<<"\t"
- <<"數(shù)學(xué):"<<"\t"<<"英語(yǔ):"<<"\t"<<"總分"<<"\t"<<"平均分"<<endl;
- cout<<s.rank<<"\t"<<s.number<<"\t"<<s.name<<"\t"<<s.chinese<<"\t"
- <<s.math<<"\t"<<s.english<<"\t"<<s.total<<"\t"<<s.average<<endl;
- }
- int search(Student S[],int N,char *n) //成績(jī)查詢模塊
- {
- for(int i=0;i<N;i++)
- {
- if(strcmp(S[i].number,n)==0)
- return i;
- }
- return -1;
- }
- int main() //系統(tǒng)集成
- {
- const int M=3;
- Student S[M];
- for(int i=0;i<M;i++)
- {
- cout<<"下面輸入第"<<i+1<<"位同學(xué)的數(shù)據(jù):"<<endl;
- setData(S[i]);
- count(S[i]);
- cout<<endl;
- }
- sort(S,M);
- int order=1;
- while(order!=4)
- {
- cout<<"*****************************命令菜單******************************"<<endl;
- cout<<"1.打印所有排名"<<endl;
- cout<<"2.打印出成績(jī)?cè)谌嗥骄忠陨系膶W(xué)生名單和數(shù)據(jù)信息"<<endl;
- cout<<"3.任意輸入一個(gè)學(xué)號(hào),查找出該學(xué)生在班級(jí)中的排名及其考試成績(jī)"<<endl;
- cout<<"4.退出系統(tǒng)"<<endl;
- cout<<"*******************************************************************"<<endl;
- cout<<"輸入命令選擇:";
- cin>>order;
- switch(order)
- {
- case 1:
- {
- for(int j=0;j<M;j++)
- print(S[j]);
- }
- break;
- case 2:
- {
- double compare=getAverage(S,M);
- for(int k=0;k<M;k++)
- if(S[k].average>compare)
- print(S[k]);
- }
- break;
- case 3:
- {
- char code[Max];
- ……………………
- …………限于本文篇幅 余下代碼請(qǐng)從51黑下載附件…………
復(fù)制代碼
所有資料51hei提供下載:
學(xué)生成績(jī)管理系統(tǒng).rar
(367.94 KB, 下載次數(shù): 12)
2017-12-25 20:04 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
|