Third time job

Source: Internet
Author: User

The following improvements were made on the basis of the previously written four OP program:

    1. The expression contains a negative integer (negative integer minimum 100) of the topic, and negative numbers need to be parenthesized, the user input results without parentheses. such as: (-4) = 8
    2. After the user's answer is completed, the program can display the user's answer time
Requirements Analysis:

1. Add and Function

2. Use the modular design concept to modify the previous code to encapsulate the "compute function"

Design:

1. Add Random negative function

2. Time taken to join the program

Code implementation:

Suanfa.h

#define _crt_secure_no_warnings#include "stdio.h" #include "stdlib.h" int right=0, wrong=0; void Jiafa () {int A, B, c;//definition a , B,CA = -100 + rand ()% 201;//randomly generates -100~100 number B = -100 + rand ()% 201;//randomly generates -100~100 number printf ("Please Answer: (%d) + (%d) =", A, b); scanf ("%d", &c);//keyboard accepts the value if (A + b! = c)//Determines whether the input value is correct {printf ("Error \ n"); wrong++;//logs the error value +1}else{printf ("Correct \ n"); right++; Record correct value +1}}void JIANFA () {int A, B, c;//definition A,B,CA = -100 + rand ()% 201;//randomly generated -100~100 number B = -100 + rand ()% 201;//randomly generated -100~10 0 of the number printf ("Please Answer: (%d)-(%d) =", A, b); scanf ("%d", &c), if (A-a-d! = c)//Determine if the input value is correct {printf ("Error \ n"); wrong++;} else{printf ("correct \ n"); right++;}} void Chengfa () {int A, B, c;//definition A,B,CA = -100 + rand ()% 201;//randomly generates -100~100 number b= -100 + rand ()% 201;//randomly generates -100~100 number if (a <0 && b>0) {printf ("Please Answer (: (%d) *%d=", A, b);} if (a<0 && b<0) {printf ("Answer: (%d) * (%d) =", A, b);} if (a>0 && b<0) {printf ("Answer:%d * (%d) =", A, b);} if (a>0 && b>0) {printf ("Please answer:%d *%d=", A, b);} scanf ("%d", &c)if (a*b! = c)//Determine if the input value is correct {printf ("Error \ n"); wrong++;} else{printf ("correct \ n"); right++;}}                void Chufa () {Double A, B, c;//definition A,B,CA = -100 + rand ()% 201;//randomly generates -100~100 number B = -100 + rand ()% 201; Randomly generates -100~100 's digital printf ("Please Answer: (%LF)/(%LF) =", A, B), scanf ("%lf", &c), if (A/b! = c)//Determine if the input value is correct {printf ("Error \ n"); wrong ++;} else{printf ("correct \ n"); right++;}}

Zhuchengxu.cpp

#define _crt_secure_no_warnings#include "stdio.h" #include "stdlib.h" #include "suanfa.h" #include <time.h># include<string.h> #include <iostream>    //define global variables R W record pairs of questions and wrong number of questions void main ()                                 //main function {int a = clock (); int x , con = 0;                         Define the X-value with the con value printf ("C-language four operator \ n"); while (1) {printf ("Select algorithm: \n1 plus 2 minus 3 by 4 except \ n"); if (con = = 0) scanf ("%d", &x); switch (x)                          //Judge input Value Select Sub Function program {case 1:JIAFA (); break;case 2:jianfa (); break;case 3:chengfa (); break;case 4:chufa (); printf ("1 redo, 2 change algorithm, 3 exit \ n"); scanf ("%d", &con), if (con = = 1) con = 1;if (con = 2) con = 0;if (con = 3) break;} printf ("Total number%d, correct%d problem, error%d!") \ n ", right + wrong, right, wrong); End Rebate W r value int b = Clock ();//To this end int c = b-a;//The calculated unit is milliseconds printf ("%d milliseconds \ n", c); //}

Procedure: Analysis and Summary: 1.PSP Time-consuming statistics

2. Summary: Add some function, strengthen team cooperation ability, still have many function not, realize also need to study diligently

Co-author Fan Luo

Third time job

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.