20200711 千锤百炼软工人第六天
今天也是很遗憾没有学习JAVA语言.........
今天还是完成的小学期之前的几个任务的完善工作
在此附上源代码和运行截图
#include<iostream>
#include<time.h>
#include<stdlib.h>
using namespace std;
class youxi
{
public:
youxi();
~youxi
(void);
void caiquan();
void cwinadd();
void pwinadd();
void peaceadd();
int putcwin();
int putpwin();
int putpeace();
#include<time.h>
#include<stdlib.h>
using namespace std;
class youxi
{
public:
youxi();
~youxi
(void);
void caiquan();
void cwinadd();
void pwinadd();
void peaceadd();
int putcwin();
int putpwin();
int putpeace();
private:
int a, b;
int cwin, pwin, peace;
};
youxi::youxi()
{
cwin = 0;
pwin = 0;
peace = 0;
}
int a, b;
int cwin, pwin, peace;
};
youxi::youxi()
{
cwin = 0;
pwin = 0;
peace = 0;
}
youxi::~youxi(void)
{
}
void youxi::caiquan()
{
cout << "请输入石头,剪刀,或布.三者的代号为1、2、3(输入4退出)\n";
srand(time(0));
for (;;)
{
cin >> a;
if (a != 1 && a != 2 && a != 3 && a != 4)
{
cout << "请重新输入。\n";
continue;
}
if (a == 4)
{
cout << "电脑赢的次数:" << putcwin() << endl << "玩家赢的次数:" << putpwin() << endl << "平局次数:" << putpeace() << endl;
break;
}
if (a != 1 && a != 2 && a != 3 && a != 4)
{
cout << "请重新输入。\n";
continue;
}
if (a == 4)
{
cout << "电脑赢的次数:" << putcwin() << endl << "玩家赢的次数:" << putpwin() << endl << "平局次数:" << putpeace() << endl;
break;
}
b = rand() % 3 + 1;
if (b == 1)
cout << "电脑出的石头。";
else if (b == 2)
cout << "电脑出的剪刀。";
else if (b == 3)
cout << "电脑出的布。";
cout << endl;
if (a == 1 && b == 2 || a == 2 && b == 3 || a == 3 && b == 1)
{
cout << "玩家胜利。";
pwinadd();
}
else if (b == 1 && a == 2 || b == 2 && a == 3 || b == 3 && a == 1)
{
cout << "电脑胜利。";
cwinadd();
}
else if (a == b)
{
cout << "平局。";
peaceadd();
}
cout << endl;
}
if (b == 1)
cout << "电脑出的石头。";
else if (b == 2)
cout << "电脑出的剪刀。";
else if (b == 3)
cout << "电脑出的布。";
cout << endl;
if (a == 1 && b == 2 || a == 2 && b == 3 || a == 3 && b == 1)
{
cout << "玩家胜利。";
pwinadd();
}
else if (b == 1 && a == 2 || b == 2 && a == 3 || b == 3 && a == 1)
{
cout << "电脑胜利。";
cwinadd();
}
else if (a == b)
{
cout << "平局。";
peaceadd();
}
cout << endl;
}
}
void youxi::cwinadd()
{
cwin++;
}
void youxi::cwinadd()
{
cwin++;
}
void youxi::pwinadd()
{
pwin++;
}
{
pwin++;
}
void youxi::peaceadd()
{
peace++;
}
{
peace++;
}
int youxi::putcwin()
{
return cwin;
}
int youxi::putpwin()
{
return pwin;
}
int youxi::putpeace()
{
return peace;
}
int main()
{
youxi a;
a.caiquan();
{
return cwin;
}
int youxi::putpwin()
{
return pwin;
}
int youxi::putpeace()
{
return peace;
}
int main()
{
youxi a;
a.caiquan();
}