代码奉上:(明明没有提示出错,但一调试就会出现如题问题)
#include
#include
#include
#include
#include
using namespace std;
template
void mySort(InputIterator first, InputIterator last, OutputIterator result) {
vector s;
for (; first != last; ++first)
s.push_back(*first);
sort(s.begin(), s.end());
copy(s.begin(), s.end(), result);
}
class ren {
public:
virtual void xianshi();
void xingming() { cout << "请输入性名" << endl; cin >> mingzi; }
void chengji(double a1, double a2, double a3)
{
chengj[0] = a1;
chengj[1] = a2;
chengj[2] = a3;
}
double zongfen1(double a1, double a2, double a3)
{
double zongfen;
zongfen = a1 + a2 + a3;
return zongfen;
}
double chengj[3];
double zongfen;
string mingzi;
};
void ren::xianshi() {
cout << mingzi;
}
class xuanba : public ren {
public:
void zuigao(ren p)
{
q = p;
}
void xianshi();
ren q;
double max = 0;
};
void xuanba::xianshi() {
cout << q.mingzi << endl;
}
void fun(ren* ptr) {
ptr->xianshi();
}
int main() {
int flag = 1, flag2 = 1, i = 0;
char xuanze1, xuanze2;
double fen1, fen2, fen3;
ren a;
xuanba b;
string c;
while (flag)
{
cout << "输入数字来运行程序" << endl;
cout << "1.输入一个人的数据" << endl;
cout << "2.查看目前总分最高的人" << endl;
cout << "3.查看目前总分最高的人的三次成绩(由小到大)" << endl;
cout << "0.退出系统" << endl;
cout << "请输入选择:" << endl;
cin >> xuanze1;
switch (xuanze1)
{
case '1':
a.xingming();
cout << "请输入他的三次成绩" << endl;
cin >> fen1 >> fen2 >> fen3;
a.chengji(fen1, fen2, fen3);
fun(&a);
cout << " 的成绩已输入完毕" << endl;
a.zongfen = a.zongfen1(fen1, fen2, fen3);
if (a.zongfen > b.max)
{
b.zuigao(a);
b.max = a.zongfen;
}
while (flag2)
{
cout << "输入数字进行以下操作" << endl;
cout << "1.查看此人三次成绩(由小到大)" << endl;
cout << "2.查看此人总分" << endl;
cout << "0.返回首页" << endl;
cin >> xuanze2;
switch (xuanze2)
{
case '1':
fun(&a);
cout << " 的三次成绩从小到大为:" << endl;
mySort<double>(a.chengji, a.chengji + 3, ostream_iterator<double>(cout, " "));
cout << endl;
break;
case'2':
fun(&a);
cout << " 的总分为:" << endl;
cout << a.zongfen << endl;
break;
default:
flag2 = 0;
break;
}
}
break;
case '2':
{
cout << "目前成绩最高的人为: " << b.q.mingzi << endl;
cout << "其总分为:" << b.max << endl;
}
break;
case'3':
{
cout << "目前成绩最高的人为: " << b.q.mingzi << endl;
cout << "其三次成绩由小到大排名为:" << endl;
mySort<double>(b.q.chengji, b.q.chengji + 3, ostream_iterator<double>(cout, " "));
}
break;
default:
{
flag = 0;
}
}
}
return 0;
}