项目结构
选手类(Player)
操作类(System) // 老师说最好别用这个名字,以后一定要注意这个问题
Player类
这一部分代码是写在头文件里的
#define TheJudgesNum 10
class Player
{
private:
public:
char num[20];
char name[20];
int score[TheJudgesNum];
float sum;
float ave;
Player *next;
Player();
~Player();
int getMaxScore();
int getMinScore();
};
Player.cpp立马跟上
#include "Player.h"
#include <iostream>
using namespace std;
int Player::getMaxScore() {
int Maxscore = score[0];
for (int i = 1; i < TheJudgesNum; i++) {
if (score[i] > Maxscore) {
Maxscore = score[i];
}
}
return Maxscore;
}
int Player::getMinScore() {
int Minscore = score[0];
for (int i = 1; i < TheJudgesNum; i++) {
if (score[i] < Minscore) {
Minscore = score[i];
}
}
return Minscore;
}
Player::Player()
{
for (int i = 0; i < TheJudgesNum; i++) {
score[i] = 0;
}
sum = 0;
ave = 0;
}
Player::~Player()
{
}
emmm怎么不是4个字符缩进,看起来好奇怪
System类
#pragma once
#include"Player.h"
class System
{
private:
int PlayerNum;
Player *Head;
Player *End;
public:
void Interface();
void Run();
void InputPlayerInformation();
void OutputPlayerInformation();
void GiveScore();
void Sort();
void Swap(Player *A,Player *B);
bool Search(char ch[20],int i);
void WriteDataFile();
void AddPlayerInformation();
void ReadDataFile();
System();
~System();
};
System.cpp
#include "Player.h"
#include "System.h"
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
void System::Interface() {
cout << endl;
cout << " ***************菜单****************" << endl;
cout << " *** 1——录入选手信息 ***" << endl;
cout << " *** 2——信息输出 ***" << endl;
cout << " *** 3——评委打分 ***" << endl;
cout << " *** 4——成绩排序(平均分) ***" << endl;
cout << " *** 5——数据查询 ***" << endl;
cout << " *** 6——追加选手信息 ***" << endl;
cout << " *** 7——写入数据文件 ***" << endl;
cout << " *** 0——退出系统 ***" << endl;
cout << " ***********************************" << endl;
cout << endl;
cout << " ***********************************" << endl;
cout << " *** 请选择想要进行的操作 ***" << endl;
cout << " ***********************************" << endl;
}
void System::Run() {
int choice = 1;
while (choice) {
Interface();
cin >> choice;
if (choice > 7 || choice < 0) {
cout << " ****************************