急求c++歌手比赛成绩系统

2024-11-18 11:27:52
推荐回答(3个)
回答(1):

//include//////////////
#include "stdio.h"
#include //DEFINE////////////////////
#define LONG 20
//global////////////////////////////
int ID,x,y[10],a,i,flag,what,REMOVE = 0; //存放ID,MARK,AVE, i用于循环,flag是循环标志
//REMOVE用于存放弃掉最高分和最低分后的统计值
char n,name; //存放name
Sum=0,aver=0,
flag = 1;
//FUNCTION////////////////////////define singer's message/////////
//Singer 里面的参数分别代表:编号,姓名,选手的平均成绩,总成绩
void Singer()
{

ID = x; //ID 初始化
name = n; //名字初始化
printf("选手ID:%d\n",ID);
/* printf("选手名字:%s\n",name);*/

//Singer 函数仅用于输出
/* printf("选手ID:%d\n选手名字:%s",ID,name);*/

}//这里设置一个手动打分,要求你输入分数的,当然也可以随机,用random函数就可以了
void Ping()
{
int j,sorce[10]; //i 用于循环,Sum用于统计总成绩,aver用于统计平均成绩
int MAX,MIN; //存放最高和最低分,

printf("请输入10个评委打的分数:\n");
for(i=0;i<10;i++)
{
scanf("%d",&sorce[i]);
//总成绩
Sum += sorce[i];
}
//平均成绩算法 //弃掉最高和最低分
for(i = 0;i<10;i++)
{

for(j = i;j<10;j++)
{
MAX = MIN = sorce[0]; //先假设MAX和MIN得值
if(sorce[i] //通过下面的筛选,可以求出最大积分和最小积分
MAX = sorce[j];
MIN = sorce[i];
}
}
REMOVE = Sum - MAX - MIN ;
//求出平均分
aver = REMOVE/8;

}void SingMark()
{
printf("弃掉最高分和最低分,%d选手的总分是:%d\n该平均分为%d\n",ID,REMOVE,aver);
}
//用于界面信息
void output(){
int i; //用于循环
for(i = 0;i<10;i++)
printf(" ");
for(i = 0;i<32;i++)
printf("*");
printf("\n");
for(i=0;i<10;i++)
printf(" ");
printf("*"); printf("1.输入选手的信息");
for(i=0;i<14;i++)
printf(" ");
printf("*\n");
for(i=0;i<10;i++)
printf(" ");
printf("*");
printf("2.评委打分统计");
for(i=0;i<16;i++)
printf(" ");
printf("*\n");
for(i=0;i<10;i++)
printf(" ");
printf("*");
printf("3.比赛结果,选手信息输出");
for(i=0;i<6;i++)
printf(" ");
printf("*\n");

for(i=0;i<10;i++)
printf(" ");
printf("*");
printf("0.退出");
for(i=0;i<24;i++)
printf(" ");
printf("*");
printf("\n");

for(i=0;i<10;i++)
printf(" ");
for(i=0;i<32;i++)
printf("*");
printf("\n");
}void main()
{
int yes;

output();
while(flag)
{
printf("请选择功能(0-3):\n");
scanf("%d",&what);

switch(what)
{
case 0:
break; case 1:
printf("请输入选手的ID,姓名(xx,xx)\n");
scanf("%d,%s",&x,&n);

//test///////////////
printf("%d",x);
/*printf("%s",n);*/

//输入判断,仅检测输入的是否是空值
if(x == " " || n == " ")
printf("输入错误,ID与姓名不能是空值\n");
ID = x; //ID初始化
name = n; //名字初始化
//else return success
break;
case 2:
Ping();
break; case 3:
printf("比赛结果,选手信息输出\n");
//void Singer(int ID,char name)
Singer();
SingMark();
break;

default:
printf("请做出正确选择\n");
break;

} //end switch
printf("是否要继续?(0/1)\n");
scanf("%d",&yes);
if(yes) flag = 1;
else flag = 0;
} //end while} //end main
选手名字我不懂获取

回答(2):

我这个是C++的代码 里面含有标准库。
#include
#include
#include
#include
#include
#include
using namespace std;

class Person
{
public:
Person(){};
Person(string name, double score)
{
this->m_Name = name;
this->m_Score = score;
}

string m_Name;
double m_Score; //平均分

};

void creatPerson(vector&v,int n)
{

int score = 0;
for (int i = 0; i < n; ++i)
{
string name1 = to_string(i+1); //int类型转化为string类型
string name2 = "号选手";
name1 += name2;
Person p(name1, score);
v.push_back(p);
}

}

void printVector(vector&v)
{
for (vector::iterator it = v.begin(); it != v.end(); ++it)
{
cout << it->m_Name << "最终平均分数为:" << it->m_Score << endl;

}

}

void printVector2(vector&v)
{
for (vector::iterator it = v.begin(); it != v.end(); ++it)
{
cout << it->m_Name << " ";
}
cout << endl;
}

void setVector(vector&v,int m)
{
for (vector::iterator it = v.begin(); it != v.end(); ++it)
{
dequed;
cout << "已为" << it->m_Name <<"打了"<for (int i = 0; i < m; ++i)
{
int score = rand() % 41 + 60; // 打分区间60~100
d.push_back(score);
}

for (deque::iterator dit = d.begin(); dit != d.end(); ++dit)
{
cout << *dit << " ";
}
cout << endl;

sort(d.begin(), d.end());

d.pop_front();
d.pop_back();

/*for (deque::iterator dit = d.begin(); dit != d.end(); ++dit)
{
cout << *dit << " ";
}
cout << endl;*/

int sum = 0;
for (deque::iterator dit = d.begin(); dit != d.end(); ++dit)
{
sum += *dit;
}
//cout << "sum=" << sum << "数量" << d.size() << endl;

double avg = sum*1.0 / d.size();

it->m_Score = avg;

}
cout << endl;
}

void sortScore(vector&v)
{
vector::iterator it = v.begin();

Person t;
for (unsigned int i = 0; i < v.size(); ++i)
{
for (unsigned int j = 0; j < v.size() - i - 1; ++j)
{
if (it[j].m_Score>it[j + 1].m_Score) //比较分数
{
t = it[j]; //更换整体
it[j] = it[j + 1];
it[j + 1] = t;
}
}
}

}

int main(void)
{
cout << "软件说明:" << endl;
cout << "该软件为N个评委为M个选手打分,这样每一个选手就收到N次打分,去掉一个最低分和一个最高分,算出选手的平均分,并为这些选手按平均分从低到高排序。" << endl;
cout << endl;
cout << "请输入选手的个数N=";
int n;
while (true)
{
char c = cin.peek();
if (c > '0'&& c <= '9')
{
cin >> n;
cout << "你设置的选手人数为:" << n << endl;
break;
}
cin.clear(); //重置标志位
cin.sync(); //清空缓冲区
cout << "你输入不正确,请重新输入" << endl;
}
getchar();
cout << endl;
cout << "请输入评委的个数M=";
int m;
while (true)
{
char c = cin.peek();
if (c > '0'&& c <= '9')
{
cin >> m;
cout << "你设置的评委人数为:" << m << endl;
break;
}
cin.clear(); //重置标志位
cin.sync(); //清空缓冲区
cout << "你输入不正确,请重新输入" << endl;
}
cout << endl;
cout << "请这"<cout << "(为了避免手动输入分数浪费时间,下面让计算机随机为选手打"<cout << endl;
srand((unsigned int)time(NULL)); //随机数种子
vectorv;
creatPerson(v,n);

//printVector(v);
setVector(v,m);

cout << endl;
cout << "去掉一个最低分,去掉一个最高分:"<printVector(v);

cout << endl;
cout << "选手成绩由低到高排序如下:" << endl;
sortScore(v);
printVector2(v);

system("pause");
return 0;
}

回答(3):

Sql语句编的可以吗