zoukankan      html  css  js  c++  java
  • 关于四则运算

    我要编写一个关于四则运算的程序。设计思路:

    ①设计算法,需要运用随机数;②设置一个随机数z,让z对4求余得x;(3)设置分类语句让四则运算通过x随机出现;(4)设置每行输出10个的语句.

    首先,我先进行了程序估算,在我的估算中:

    查看资料等消耗15分钟左右;

    编写代码需要30分钟左右;

    调试程序及优化需要20分钟左右;

    整个程序完成时间约70分钟。

    实验结果:

    我使用了35分钟编写完成了这个程序并进行了调试优化;整体来说对于程序语言的知识掌握的不够精确。

    程序代码:

     1 #include<iostream>
     2 #include<time.h>
     3 #include<stdlib.h> //调用随机函数;
     4 using namespace std;
     5 int main()
     6 {
     7  srand((unsigned)time(NULL));//使随机产生的题目不重复;
     8  int x,y,n;//x,y为随机数,n为题目数量;
     9  int ch;
    10  cout<<"enter the amount of you want to get:";
    11  cin>>n;
    12  for(int i=1;i<=n;i++)
    13  {
    14   x=rand()%100;y=rand()%100;
    15   ch=rand()%4;
    16   switch(ch)
    17   {
    18   case 0:cout<<x<<"+"<<y<<"="<<" ";
    19    break;
    20   case 1:cout<<x<<"-"<<y<<"="<<" ";
    21    break;
    22   case 2:cout<<x<<"*"<<y<<"="<<" ";
    23    break;
    24   case 3:cout<<x<<"/"<<y<<"="<<" ";
    25   }
    26   if(i%10==0)
    27 {
    28    cout<<endl;
    29  }
    30 }
    31  return 0;
    32 }

  • 相关阅读:
    CentOS 下搭建Jenkins
    SRVE0255E: 尚未定义要处理 ***的 Web 组/虚拟主机。
    WebSphere Application Server中manageprofiles的使用
    WAS 与IHS集成问题
    CentOS ln 链接
    VIM常见命令
    虚拟机VM下CentOS7部署WASND9+HTTP9
    CentOS7下安装GUI图形界面
    CentOS 系统时间与硬件时间
    hive 排序和聚集
  • 原文地址:https://www.cnblogs.com/stdu-412/p/9753049.html
Copyright © 2011-2022 走看看