当前位置: 首页 > 编程日记 > 正文

个人作业1:小学四则运算——基于控制台

a.需求分析:

自动生成小学四则运算题目的命令行 “软件”,满足以下需求:   

    1. 除了整数以外,还要支持真分数的四则运算,真分数的运算,例如:1/6 + 1/8 = 7/24
    2. 运算符为 +, −, ×, ÷
    3. 并且要求能处理用户的输入,并判断对错,打分统计正确率。
    4. 要求能处理用户输入的真分数, 如 1/2, 5/12 等
    5. 使用 -n 参数控制生成题目的个数,例如执行下面命令将生成10个题目
      Myapp.exe -n 10

b.功能设计:

  生成整数四则运算和分数四则运算,并判断对错,打分统计正确率

c.设计实现:

  分函数zs()主要负责整数四则运算,随机产生两个随机数和随机运算符并计算;分函数gys是求最大公约数函数;分函数fs()主要负责分数四则运算随机产生两个随机数和随机运算符并调用第三个分函数gys()进行计算;主函数main()主要实现随机调用两个分函数zs()和fs()并统计正确率

d.代码说明:

#include "stdio.h"

#include "stdlib.h"

#include "time.h"
#include "string.h"
int gcd(int x,int y)
{
    int r;
    r=x%y;
    while(r!=0)
    {
        x=y;
        y=r;
        r=x%y;
    }
    return y;
}
int zhengshu(){
    int left,mid,right,result,int_number;
    srand((unsigned)time(NULL));
    left=rand()%10;
    mid=rand()%4;
    right=rand()%10;
    printf("%d",left);
    switch(mid)
    {
        case(0):result=left+right;
        printf(" + ");break;
        case(1):result=left-right; 
        printf(" - ");break;
        case(2):result=left*right;
        printf(" ×");break;
        case(3):result=left/right;
        printf(" ÷");break;
    }
    printf("%d =",right);
    scanf("%d",&int_number);
    if(int_number == result)
        {
            printf("回答正确!    下一题:\n");
            score=score+1; 
        }
    else{
            printf("回答错误!    下一题:\n");
        }
}
int fenshu(){
    int left_x,left_y,mid,right_x,right_y,x,y,GYS,int_number1,int_number2;
    srand((unsigned)time(NULL));
    do{
    left_x=rand()%10+1;
    left_y=rand()%10+1;
    mid=rand()%4;
    right_x=rand()%10+1;
    right_y=rand()%10+1;
    }while(!(left_x<left_y&&right_x<right_y));
    printf("%d/%d",left_x,left_y);
        switch(mid)
        {
            case(0):x=left_x*right_y+left_y*right_x;
                    y=left_y*right_y;
            printf(" + ");break;
            case(1):x=left_x*right_y-left_y*right_x;
                    y=left_y*right_y;  
            printf(" - ");break;
            case(2):x=left_x*right_x;
                    y=left_y*right_y;
            printf(" ×");break;
            case(3):x=left_x*right_y;
                    y=left_y*right_x;
            printf(" ÷");break;
        }
        printf("%d/%d =",right_x,right_y);
    GYS=gcd(x,y);
    x=x/GYS;
    y=y/GYS;
    scanf("%d/%d",&int_number1,&int_number2);
    if(int_number1==x&&int_number2==y)
    {
        printf("回答正确!    下一题:\n");
        score=score+1; 
    }
    else{
        printf("回答错误!    下一题:\n");
    }
}
int main(){
    int h,count;
int score=0;
    printf("请输入题目数?");
    scanf("%d",&count);
    for(int i=0;i<count;i++)
    {
        h=rand()%2;
        if(h==0)
        {zs();}
        else
        {fs();}
    }
    printf("正确率为:%lf",score*1.0/count);
}

转载于:https://www.cnblogs.com/Xshopping/p/6516924.html

相关文章:

getchar返回int类型

#include <stdio.h> /* copy input to output; 2nd version */main(){int c;c getchar();while(c ! EOF){putchar(c);c getchar();}} 直觉告诉我getchar返回值应该是char类型的&#xff0c;这个地方为什么不能用char类型来存储getchar()的返回值呢&#xff1f; 其实文中…

8 iOS中KVO 的本质

前言本质 Automatic key-value observing is implemented using a technique called isa-swizzling 这计划的意思就是 自动的键值观察的实现基于 isa-swizzling 原理 1.KVO是基于runtime机制实现的 2.当某个类的属性对象第一次被观察时&#xff0c;系统就会在运行期动态地创…

完成工作表-使用Google Spreadsheets作为数据后端

by Gilad Dayagi通过吉拉德达亚吉 完成工作表-使用Google Spreadsheets作为数据后端 (Get Sheet Done — using Google Spreadsheets as your data backend) If you want to rapidly prototype your next web apps, try using Google Spreadsheets as your data backend.如果您…

BIEE-CSS样式大全

字体属性&#xff1a;(font) 大小 {font-size: x-large;}(特大) xx-small;(极小) 一般中文用不到&#xff0c;只要用数值就可以&#xff0c;单位&#xff1a;PX、PD 样式 {font-style: oblique;}(偏斜体) italic;(斜体) normal;(正常) 行高 {line-height: normal;}(正常) 单位&…

基于verilog的FPGA编程经验总结(XILINX ISE工具)

1.用ISE仿真的时候.所用变量一定要初始化. ISE默认初始量为"XXXXX", 而Quarters是默认为"00000"的, 其实实际上, 下到FPGA里后也是默认为0的,只是可以说ISE严谨得令人DT吧.比如说用一个累加器, result ABresult ,必须保证在某一刻A, B, result都为定值时,…

6 OC 中的isa 指针

目录 一 isa 指针 二 类对象中的superclass 一 isa 指针 isa 指针 &#xff0c;OC 中的对象都是有的 如下图所示&#xff0c;实例对象isa 指针指向 类对象&#xff0c;类对象的isa 指针指向 元类对象 二 类对象中的superclass superclass 有什么用呢&#xff1f; 比如说创…

btf-raft共识算法_了解Raft共识算法:学术文章摘要

btf-raft共识算法by Shubheksha通过Shubheksha 了解Raft共识算法&#xff1a;学术文章摘要 (Understanding the Raft consensus algorithm: an academic article summary) This post summarizes the Raft consensus algorithm presented in the paper In Search of An Underst…

iOS asset 中定义颜色,xib中便捷访问

在aseet 中定义一个颜色 这样就可以在xib 中访问颜色了&#xff0c;这样就不用重复的去输入

三种序列化方式性能比较

一下代码比较了二进制序列化、xml序列化、Protobuf序列化的运行时间&#xff0c;可是代码显得十分冗余&#xff0c;是否有大神可以指点一二&#xff0c;万分感谢 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; usi…

mac mini 装UBUNTU后没有WIFI解决办法

1、在终端中运行如下命令&#xff0c;重新安装b43相关的全部驱动和firmware: 复制代码代码如下:sudo apt-get install bcmwl-kernel-source #Broadcom 802.11 Linux STA 无线驱动源sudo apt-get install broadcom-sta-commonsudo apt-get install broadcom-sta-sourcesudo apt-…

区块链c端应用小程序_区块链如何真正起作用? 我建立了一个应用程序向您展示。...

区块链c端应用小程序by Sean Han通过肖恩韩 区块链如何真正起作用&#xff1f; 我建立了一个应用程序向您展示。 (How does blockchain really work? I built an app to show you.) According to Wikipedia, a blockchain is:根据维基百科&#xff0c;一个区块链是&#xff1…

HDU 4913 Least common multiple

/* hdu4913 Least common multiple http://acm.hdu.edu.cn/showproblem.php?pid4913 离散化 线段树 统计逆序数思想 tips: 1、线段树中一定要到处都取模&#xff0c;否则wa。。。 2、lazy是乘积的形式出现&#xff0c;不是加和*/ #include <cstdio> #include <algori…

JS ES6 实用笔记

微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 这篇博文我会一直更新。 一.导出导入的两中方式 1.export //demo1.js export const a 6 导入语法为&#xff1a; import {a} form demo1 2.export default //demo2.js export default const b 6 …

extjs editgrid增加一行

Ext.onReady(function(){ /* * EditorGridPanel的工作过程 * 1、用户点击单元格 * 2、单元格按照预设的组件显示单元格的内容并处于编辑状态 * 3、离开单元格的编辑状态 * 4、更新编辑后的内容&#xff0c;出现三角号表示已经被修改过 * 5、程序内部变化&#xff1a;将记录设置…

unity 骨骼击碎_保证击碎$ 100挑战的创新策略

unity 骨骼击碎by Glenn Gonda由Glenn Gonda 保证击碎$ 100挑战的创新策略 (A Creative Strategy Guaranteed to Crush the $100 Challenge) Before I became a software engineer, I made my living as a recording studio engineer. I have a non-traditional background an…

mac下安装libpng环境

用go写一个爬虫工具时需要使用一个go的库&#xff0c;而这个库有需要使用libpng库&#xff0c;不然编译就会提示说 png.h找不到等之类的信息&#xff0c;于是想到应该和windows一样需要安装gcc环境&#xff0c;然后让gcc里安装libpng这个库&#xff0c; 解决办法&#xff1a; 终…

linux oracle修改编码utf8

$ sqlplus /nolog SQL> connect sys/oracle as sysdba SQL> startup 如何设置ORACLE数据库的编码&#xff08;ZHS16GBK&#xff09;修改成UTF8 SQL> shutdown immediate; SQL> startup mount; SQL> alter system enable restricted session; SQL> alter sy…

Vue.js 数据绑定渲染Demo

微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 <div id"app">{{ message }} </div>var app new Vue({el: #app,data: {message: Hello Vue!} })Hello Vue!

angular搭建项目步骤_建立健康的Angular项目应采取的步骤

angular搭建项目步骤by Ashish Gaikwad通过Ashish Gaikwad 建立健康的Angular项目应采取的步骤 (Steps you should take to build a healthy Angular project) 使用Jenkins SonarQube创建您的“ Angular Fitbit” (Create your “Angular Fitbit” with Jenkins SonarQube) …

数据库的三大范式和事物

来源&#xff1a;http://blog.csdn.net/w__yi/article/details/19934319 1.1 第一范式&#xff08;1NF&#xff09;无重复的列 1.2 第二范式&#xff08;2NF&#xff09;属性完全依赖于主键 [ 消除部分子函数依赖 ] 1.3 第三范式&#xff08;3NF&#xff09;属性不依赖于其它非…

过滤器和包装器

作者&#xff1a;禅楼望月 过滤器要做的事情 请求过滤器 完成安全检查 重新格式化请求首部或体 建立请求审计或日志响应过滤器 压缩响应流 追加或修改响应流 创建一个完全不同的响应注意不能把过滤器的顺序依赖性硬编码进程序中&#xff0c;它应该由DD控制。 过滤器很像Servlet…

Missing space before value for key 'path'vue.js解决空格报错

微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 找到 webpack.base.config.js文件注释掉下面的东西&#xff01;&#xff01; module: { rules: [ /*{ test: /\.(js|vue)$/, loader: eslint-loader, enforce: "p…

现代hy-9600音响_从音响工程师到软件工程师-为什么我要学习编码

现代hy-9600音响by Kalalau Cantrell通过Kalalau Cantrell 从音响工程师到软件工程师-为什么我要学习编码 (From Sound Engineer to Software Engineer — Why I’m Learning to Code) I seriously started teaching myself to code several months ago. I say “seriously” …

微信服务号、公众号、企业号注册

转载于:https://www.cnblogs.com/zhoulaoshi/p/6536850.html

a标签onclick事件解析

微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 简单介绍<a>标签的常用点击事件的写法及作用 a href"javascript:void(0);" οnclick"js_method()" //javascript:void(0);作用是返回undefined&#xff0c;地址不发生跳转&am…

安卓版文字扫描识别软件

安卓版文字扫描识别软件 文字识别软件被越来越多的人使用&#xff0c;在使用的过程中也发现了一些问题。总结这些问题发现&#xff0c;很多人对软件能够批量识别这个问题比较关注。如果实现批量识别就可以节省时间。但是一些软件还不能实现批量识别&#xff0c;还有的软件能够做…

中级前端笔试_在短短8个月内如何获得中级前端开发人员的角色

中级前端笔试by Matthew Burfield通过马修伯菲尔德(Matthew Burfield) 在短短8个月内如何获得中级前端开发人员的角色 (How I got a mid-level front end developer role in just 8 months) Three weeks ago I landed a mid-level front-end developer role at a startup. Our…

用stm32f10x建立新的工程重要步骤

stm32f10x系列新建空的工程主要原理&#xff1a; 1.添加启动文件 不同的芯片类型的启动文件的容量是不同的&#xff0c;选择适合该芯片的容量作为启动文件。 注意&#xff1a;启动文件是汇编语言编写的&#xff0c;所以文件的后缀名为.s 2.添加时钟配置 配置文件 stm32f10x.的系…

随机生成6位图片验证码

1. [代码][C#]代码 /// <summary> /// PicHandler1 的摘要说明 /// </summary> public class PicHandler1 : IHttpHandler, IRequiresSessionState { private string mCheckNo string.Empty; protected ImgBuilder _ImgBuilder new I…

html 页面传值

微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 直接上代码&#xff0c;JS保存全局变量的三种方式。 创建一个新的JS文件&#xff0c; //quanju.js window.localStorage.JQa"JQA"; window.localStorage.setItem(JQb,JQB);//利用localStora…