Second assignment: Write a arithmetic "software"

Source: Internet
Author: User

    • Topic
    • Please write a "software" that can automatically generate primary arithmetic topics.
    • Allow the program to accept the user to enter the answer, and determine the right and wrong.
    • Finally, the total number of pairs/errors is given.

Requirements Analysis:

Basic functions

To achieve addition within 100

Achieve subtraction within 100

To achieve multiplication within 100

Achieve Division within 100

Design:

Programs consist of main and sub-functions

First select the type of topic to be tested, let the user enter the beginning of the problem, the topic randomly generated (1 for addition operation, 2 for subtraction, 3 for multiplication, 4 for division, 5 for the exit system)

int Question_get () is used to calculate the value of four operations, and temp represents the value calculated by the user, and the system automatically compares the answer with the value of temp to output the appropriate prompt. The final output in total answered the number of questions, correct a few words, answered a few wrong way.

Code implementation:

#include <stdlib.h> #include <stdio.h> #include <time.h>int question_get (); int type;void main (void) { int R=0;int e=0;int answer;int n;     Srand ((unsigned) time (NULL)) loop:printf ("Please select the type of topic to be tested:");     printf ("\n1. addition Operation \n2. Subtraction Operation \n3. Multiplication Operation \n4. division Operation \n5. Exit operation \ n"); printf ("\t\t\t Please select (1-5):");   scanf ("%d", &type);  while (1) {int temp;  int flag;  Answer = Question_get ();  printf ("Please answer: \ n");   scanf ("%d", &temp);   while (Temp!=answer) {e++; printf ("\ n answer wrong, try again, please redo \ n");  scanf ("%d", &temp); } r++; printf ("\ n Congratulations!   Answer right \ n ");  printf ("If you continue to press 1, exit please press 0\n");   scanf ("%d", &flag);  while (flag!=0&&flag!=1) {printf ("by other key not valid \ n"), scanf ("%d", &flag);  } if (flag==0) break; else printf ("You have answered%d questions, of which there is a correct%d, error%d \ n", e+r,r,e); Goto Loop;  }} int Question_get () {int a,b,c; Loop:if (type==1) {A=rand ()%99;  b=99-a;  B=rand ()%b;   printf ("%d +%d =?", a, b);    return (A+B);  } else if (type==2) {B=rand ()%99; C=99-b;  C=rand ()%c;  printf ("%d-%d =?", b+c, B);  return (c);  } else if (type==3) {A=rand ()%10;   B=50-a;   B=rand ()%b;  printf ("%d *%d =?", a, b);  return (A*B);  } else if (type==4) {B=rand ()%50;   c=100/b;  while (1) {C=rand ()%c;  if (c!=0) break;  } printf ("%d/%d =?", b*c, B);  return (c);   } else if (type==5) {printf ("\t\t\t exit system \ n");   System ("pause");  Exit (0); } else if (type==0| |   type>5) {printf ("\t\t\t input error, please enter the number in 1-5 \ n");   printf ("\t\t\t Please select (1-5):");   scanf ("%d", &type);  Goto Loop; }   }

 

Program:

Addition Interface:

Subtraction Interface:

Multiplication interface:

Division Interface:

Analysis and Summary:

PSP time-consuming and summary

Summary:

Must be a lot of brain to think, how to design, why to design, must have a clear idea to write code. To first think good ideas and then write, think of the process is very important, and then to achieve.

Psp

Personal Software Process Stage

Time (h)

Time (%)

Design

Specific design

6

11.5

Coding

Specific code

24

46.2

Code Review

Code review

5

9.6

Test

Testing (self-test, code modification)

13

25

Postmortem & Process

Improvement Plan

Summarize afterwards and propose process improvement plan

4

7.7

Second assignment: Write a arithmetic "software"

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.