数据结构 课程设计报告 统计成绩

  • 格式:doc
  • 大小:48.00 KB
  • 文档页数:7

1 课程设计任务书

2010—2011学年第1学期

电子与信息工程 系 计算机科学与技术 专业 班级

课程设计名称: 数据结构课程设计

设计题目: 统计成绩

完成期限:自 2012 年 1 月 2 日至 2012 年 1 月 6 日共 1 周

一、设计目的

熟悉各种数据结构和运算,会使用数据结构的基本操作解决一些实际问题。

二、设计要求

(1)重视课程设计环节,用严谨、科学和踏实的工作态度对待课程设计的每一项任务;

(2)按照课程设计的题目要求,独立地完成各项任务,严禁抄袭;凡发现抄袭,抄袭者与被抄袭者皆以零分计入本课程设计成绩。凡发现实验报告或源程序雷同,涉及的全部人员皆以零分计入本课程设计成绩;

(3)学生在接受设计任务后,首先要按设计任务书的要求编写设计进程表;

(4)认真编写课程设计报告。

三、设计内容

统计成绩

1)问题描述

给出n个学生的m门考试的成绩表,每个学生的信息由学号、姓名以及各科成绩组成。对学生的考试成绩进行有关统计,并打印统计表。

2)基本要求

(1) 按总数高低次序,打印出名次表,分数相同的为同一名次;

(2) 按名次打印出每个学生的学号、姓名、总分以及各科成绩。

3)测试数据

由学生依据软件工程的测试技术自己确定。注意测试边界数据。

4)选作内容

对各科成绩设置不同的权值。

四、参考文献

1.王红梅.数据结构.清华大学出版社 2 2.王红梅.数据结构学习辅导与实验指导.清华大学出版社

3.严蔚敏,吴伟民.数据结构(C语言版).清华大学出版社

源程序:

//--------------------------------------Student.h文件------------------------------------

#pragma once

#include

using namespace std;

struct Course

{

string courseName;

float weights; //课程权值

static const int coursenum=10;

static int realcoursenum;

};

class Student

{

public:

Student();

Student(string studentID,string studentName,float*grade);

~Student();

float TotalGrade() const;//计算学生总成绩

float AverageGrade() const;//计算学生的加权平均分

void Print();//输出各科成绩,总分和加权平均分

bool operator<(const Student&student);//运算符重载

bool operator>(const Student&student);

bool operator<=(const Student&student);

bool operator>=(const Student&student);

Student& operator=(const Student&student);

static Course course[Course::coursenum];

private:

string studentID;

string studentName;

float grade[Course::coursenum];

};

//--------------------------------------QuickSort.h文件--------------------------------------

// quicksort3.cpp : 定义控制台应用程序的入口点。

//快速排序程序

#include "stdafx.h"

#include

#include

using namespace std; 3 void swap(int *values,int i,int j)

{

int temp=values[i];

values[i]=values[j];

values[j]=temp;

}

int partition(int *values,int low,int high)

{

//基本思想,以valuse[high]为标准对(low,high-1)范围内的元素进行划分

//firstbigger为第二部分的第一个元素的下标,也就是大于values[high]那一

//部分的第一个元素的下标,然后将valuse[firstbigger]与values[high]交换,

//则firstbigger为返回值

swap(values,high,rand()%(high-low+1)+low);

int firstbigger=high;

//i为当前考查元素的下标

for(int i=low;i

{

while(values[i]

++i;

if(i

{

--firstbigger;

swap(values,i,firstbigger);

}

}

swap(values,high,firstbigger);

return firstbigger;

}

void quicksort(int *values,int low,int high)

{

if(low

{

int key=partition(values,low,high);

quicksort(values,low,key-1);

quicksort(values,key+1,high);

}

}

int _tmain(int argc, _TCHAR* argv[])

{

int n=10;

int *values=new int[n];

srand((unsigned)time(NULL));

for(int i=0;i

values[i]=rand()%100; 4 cout<<"随机产生的数据为:\n";

for(int i=0;i

cout<

cout<

quicksort(values,0,n-1);

cout<<"排序后的数据为:\n";

for(int i=0;i

cout<

cout<

return 0;

}

//--------------------------------------Klass.h文件--------------------------------------

#pragma once

#include"Student.h"

class Klass

{

public:

Klass();

Klass(int studentNum,Student *student);

~Klass();

void Print();//输出课程信息和学生信息

void Rank();//对班级里的学生按成绩排序

void Add(const Student&student);//往班级里添加学生

private:

static const int maxstudentnum=50;

int studentNum;//学生人数

Student student[maxstudentnum];

};

//------------------------------------Student.cpp文件-------------------------------------

#include "StdAfx.h"

#include "Student.h"

#include

int Course::realcoursenum=0;

Course Student::course[Course::coursenum]=

{

};

Student::Student(string studentID,string studentName,float*grade)

{

this->studentID=studentID;

this->studentName=studentName; 5 for(int i=0;i

{

this->grade[i]=grade[i];

}

}

Student::Student()

{

}

Student::~Student()

{

}

float Student::TotalGrade()const //计算总成绩

{

float sum=0.0;

for(int i=0;i

{

sum+=this->course[i].weights*this->grade[i];

}

return sum;

}

float Student::AverageGrade()const //计算加权平均分

{

float sum=0.0;

for(int i=0;i

{

sum+=this->course[i].weights ;

}

return this->TotalGrade()/sum;

}

void Student::Print() //输出各科成绩 总成绩和加权平均分

{

cout<

cout<

for(int i=0;i

{

cout

}

cout

cout

cout<

}

bool Student::operator<(const Student&student)

{