• 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();
    private:
     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退出) ";
     srand(time(0));
     for (;;)
     {
      cin >> a;
      if (a != 1 && a != 2 && a != 3 && a != 4)
      {
       cout << "请重新输入。 ";
       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;
     }
     
     
    }
    void youxi::cwinadd()
    {
     cwin++;
    }
    void youxi::pwinadd()
    {
     pwin++;
    }
    void youxi::peaceadd()
    {
     peace++;
    }
    int youxi::putcwin()
    {
     return cwin;
    }
    int youxi::putpwin()
    {
     return pwin;
    }
    int youxi::putpeace()
    {
     return peace;
    }
    int main()
    {
     youxi a;
     a.caiquan();
    }
  • 相关阅读:
    学习Linux shell脚本中连接字符串的方法
    使用 ffmpeg 转换视频格式
    一点不懂到小白的linux系统运维经历分享
    linux利用scp远程上传下载文件/文件夹
    angular ui-select
    JavaScript sort()方法
    js性能优化
    layer弹出层
    JS复制对象
    某天修改了啥bat批处理
  • 原文地址:https://www.cnblogs.com/huangmouren233/p/13284996.html
Copyright © 2020-2023  润新知