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