C++学生管理系统源代码

// 学生成绩管理系统.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include
#include
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>>https://www.360docs.net/doc/cf8743665.html,>>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{
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;jS[j].rank=j+1;//设置排名
}

double getAverage(Student S[],int N)
{
double Average=0;
for(int i=0;iAverage+=(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"<<"平均分"<cout<<}

int search(Student S[],int N,char *n) //成绩查询模块
{
for(int i=0;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{
cout<<"下面输入第"<setData(S[i]);
count(S[i]);
cout<}
sort(S,M);
int order=1;
while(order!=4)
{
cout<<"*****************************命令菜单******************************"<cout<<"1.打印所有排名"<cout<<"2.打印出成绩在全班平均分以上的学生名单和数据信息"<cout<<"3.任意输入一个学号,查找出该学生在班级中的排名及其考试成绩"<cout<<"4.退出系统"<cout<<"**********************

*********************************************"<cout<<"输入命令选择:";
cin>>order;
switch(order)
{
case 1:
{
for(int j=0;jprint(S[j]);
}
break;
case 2:
{
double compare=getAverage(S,M);
for(int k=0;kif(S[k].average>compare)
print(S[k]);
}
break;
case 3:
{
char code[Max];
cout<<"输入您要查找的学号:";
cin>>code;
int result=search(S,M,code);
if(result==-1)
cout<<"您输入的学号不存在!!!"<else
print(S[result]);
}
break;
case 4:
break;
default:
cout<<"输入的命令不存在!!!"<}
}
return 0;
}



StdAfx.cpp

// stdafx.cpp : source file that includes just the standard includes
// 学生成绩管理系统.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"

// TODO: reference any additional headers you need in STDAFX.H
// and not in this file



/ stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#if !defined(AFX_STDAFX_H__C9645465_8216_4FCE_B389_BC91B73C4E65__INCLUDED_)
#define AFX_STDAFX_H__C9645465_8216_4FCE_B389_BC91B73C4E65__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


// TODO: reference additional headers your program requires here

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_STDAFX_H__C9645465_8216_4FCE_B389_BC91B73C4E65__INCLUDED_)

相关文档
最新文档