Software Engineering Second Job

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.

--Demand analysis

This "software" is mainly for primary school students, considering that the use and mastery of the computer is limited, so the "software" operation should be as simple as possible, easy to use;

The user can contact the simple arithmetic on this "software";

This "software" can submit the user's answer, and judge the right and wrong;

Give the correct and wrong number of questions in time after using this "software".

--Design

Considering the limited computing ability of elementary school students, the "software" randomly generates the operation number within hundred;

Considering the student's grade span is bigger, and each grade student grasps the knowledge level to have the difference. The software adopts the menu method, which can be chosen by the user to practice the algorithm;

Considering that the primary school students did not receive negative knowledge, this "software" ensures that when the user does the subtraction exercise, the randomly generated two operand subtraction will not appear negative numbers;

In addition, the software ensures that when the user divides the practice, the number of randomly generated two operands will not be divided into fractions or decimals, considering that the user is not able to divide the results of the operation.

To the higher grade students, the "software" designed the four mixed operation, convenient for users to conduct comprehensive exercises;

Finally, the "software" is designed using C language implementation.

--Code implementation

#include <time.h>
#include <stdio.h>
#include <stdlib.h>
Function prototypes
void doexercise (int);
int test (int);
Function: Scoring Device
void doexercise (int n)
{
int score=0; Practice scoring, initialized to 0
int i=0; Counter of the number of exercises

for (i=1;i<=5;i++)
{
Score=score+test (n);
}
printf ("This exercise 5 questions, you did the right%d, did wrong%d \ n", Score,5-score);
printf ("========================================================\n");
}

int test (int n)
{
int ranswer=0; Correct answer
int uanswer=0; User-Entered Answers
int t=0; Temp variable
char operation; Operation category
int num1=0; Number of Operations 1
int num2=0; Number of Operations 2

Srand (Time (NULL)); Initialize pseudo-random number seed
Num1=rand ()%100; Take a random number between 0-99
Num2=rand ()%100;

Enter the program function, if you choose 5 randomly generate 1-4 represents each of the operation mode
if (n==5)
{
N=rand ()%4+1;
}

Switch (n)
{
Case 1:
operation= ' + ';
Break
Case 2:
operation= '-';
Break
Case 3:
operation= ' * ';
Break
Case 4:
operation= '/';
Break
}

if ((operation== '-') && (num1<num2))//When the meiosis is greater than the number of meiosis, the interchange
{
T=NUM1;
num1=num2;
num2=t;
}

if (operation== '/')
{
if (num2==0)
num2=1;//when the divisor randomly takes 0 o'clock, the divisor is set to 1
num1=num1*num2;//to ensure that the Division will be assigned the product of the divisor and the divisor to dividend
}

Output test question itself, prompt user input
printf ("%d%c%d=", num1,operation,num2);
scanf ("%d", &uanswer);

program calculates correct results
Switch (operation)
{
Case ' + ':
ranswer=num1+num2;
Break

Case '-':
ranswer=num1-num2;
Break

Case ' * ':
ranswer=num1*num2;
Break

Case '/':
ranswer=num1/num2;
Break
}
Judge, do the right return 1, do wrong return 0
if (uanswer==ranswer)
{
printf ("Do It right!") \ n ");
return 1;
}
Else
{
printf ("Done wrong!" \ n ");
return 0;
}
}

void Main ()
{
int choice=0;
Do
{
printf ("\t1, addition exercises \t2, subtraction exercises \ n");
printf ("\t3, multiplication exercises \t4, division exercises \ n");
printf ("\t5, comprehensive practice \t0, exit system \ n");
printf ("===================================================\n");
printf ("Please enter your choice (0--5):");

int choice;
scanf ("%d", &choice);

while (choice<0 | | choice>5)
{
printf ("Your input is wrong, please re-enter:");
scanf ("%d", &choice);
}
if (choice==0)
Break User selects 0, exits the loop (exits the system)
Doexercise (choice); Do what exercises and start scoring
}while (TRUE);

printf ("Welcome, goodbye \ n");
}


--Test

No legal input

Subtraction:

Division:

Synthesis and exit:

Time-consuming analysis:

Process Stages

Time

Time (%)

Requirement Analysis

All

Code design

23

38.33

Code review

/td>

One

18.33

Test

5

8.33

Analysis Summary

6

/td>

Ten

--Analysis and summary

This "software" after repeated testing, in the assurance of software correctness, based on the use of structured design, easy to maintain. And the interface is relatively friendly, and when the user input is not valid prompts the user to re-enter, so that the robustness of the software has been improved. There are many shortcomings, please teacher to correct.

Software Engineering Second Job

Related Article

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.