C Implementation of the four Operation program

Source: Internet
Author: User

GitHub Project Address: Https://github.com/xinxianquan/ruangong

Members: Macho, Wang Zhicong.

title: Implement a command-line program that automatically generates arithmetic topics for primary schools. Requirements:

1. Use the-n parameter to control the number of generated topics

For example, Myapp.exe-n 10 will generate 10 topics.

2. Use the-r parameter to control the range of values in the topic (natural number, true fraction, and true fraction denominator)

For example, Myapp.exe-r 10 will generate arithmetic topics that are within 10 (excluding 10). This parameter can be set to 1 or other natural number. This parameter must be given, otherwise the program will error and give help information.

3. The calculation process in the generated topic cannot produce negative numbers, i.e. if there is a shape like E1 in an arithmetic expression? E2 subexpression, then e1≥e2.

4. If there is a sub-expression like E1÷e2 in the generated topic, the result should be a true fraction.

5. There are no more than 3 operators in each topic.

6. The problem of one run of a program cannot be repeated, that is, no two topics can be transformed into the same topic by means of an arithmetic expression of the finite Exchange + and the X or so. For example, 23 + 45 = and 45 + 23 = are repetitive topics, 6x8 = and 8x6 = are also repetitive topics. The two topics of 2+1 and 1+2+3 are repetitive, because the + is left-associative, and 1+2+3 is equivalent to (1+2) +3, which is the total (1+2), which is (2+1). However, 1+2+3 and 3+2+1 are two non-repetitive problems, because 1+2+3 is equivalent to (1+2) +3, and 3+2+1 is equivalent to (3+2) +1, and they cannot be changed to the same subject by a finite exchange.

The generated topic is stored in the Exercises.txt file under the current directory of the executing program, in the following format:

1. Arithmetic Topic 1

2. Arithmetic Topic 2

......

Where true scores are used in the input and output format, the true score Three-fifths is 3/5, the true fraction Two and three-eighths is 2 ' 3/8.

7. While generating the title, calculate the answer to all the questions and deposit the Answers.txt file in the current directory of the executing program, in the following format:

1. Answer 1

2. Answer 2

In particular, the operation of the true fraction is shown in the following example: 1/6 + 1/8 = 7/24.

8. The program should be able to support the generation of 10,000 topics.

9. The program supports a given topic file and answer file, determines the correct error in the answer and carries out the quantity statistics, the input parameters are as follows:

MYAPP.EXE-E <exercisefile>.txt-a <answerfile>.txt

The statistical results are output to the file Grade.txt, in the following format:

Correct:5 (1, 3, 5, 7, 9)

Wrong:5 (2, 4, 6, 8, 10)

where ":" After the number 5 indicates the number of correct/wrong questions, in parentheses is the number of the right/wrong topic.

PSP2.1 form

PSP2.1

Personal Software Process Stages

Estimated time-consuming (minutes)

Actual time elapsed (minutes)

Planning

Plan

7day 5day

· Estimate

· Estimate how long this task will take

10day 8day

Development

Development

6day 6day

· Analysis

· Demand analysis (including learning new technologies)

7day 7day

· Design Spec

· Creating a design Document

60 60

· Design Review

· Design Review (and colleagues review design documents)

180 180

· Coding Standard

· Code specification (to develop appropriate specifications for current development)

60 60

· Design

· Specific design

1day 2day

· Coding

· Specific code

3day 3day

· Code Review

· Code review

60 60

· Test

· Test (self-test, modify code, commit changes)

1day 3day

Reporting

Report

60 60

· Test Report

· Test report

60 60

· Size Measurement

· Computational effort

30 20

· Postmortem & Process Improvement Plan

· Summarize afterwards and propose process improvement plan

60 120

Total

Performance analysis

In the completion of the program, it is not possible to cycle the program, every run need to execute once, it feels a bit cumbersome, so I added a circular call in the original program, and found that no program is not controlled by parameters, is directly run after the results, and then re-added the parameter function.

It took about 3 hours to improve the program.

design has been implemented Process

This program has a total of 9 functions, namely:

Functions implemented by parameter r: void Rcommad (int m), function implemented by parameter n: void Ncommad (int n); expression generation function: void generatearithmetic (int n,int m);

A function that generates a single-operator expression: void Level_1 (int n, int m,int nm), a function that generates a double-operator expression: void level_2 (int n, int m), function that produces the result of an expression: void Answers (int num, FI LE *fpanswers);

Functions that produce an expression: void exercises (int rdnum[], char rdchar[], int rd_num, int rd_char, FILE *fpexercises);

The function that produces the result: void Grade (int m); The function that gets the arithmetic result of the keyboard input: void Answerschar (int m).

Relationship between functions: Rcommad,ncommad will generate the numerical range and number of topics, then pass parameters to the Generatearithmetic function, then generatearithmetic function call function Level_1,level_ and create different topics. And the function answers,exercises is used to write the generated topic and results into a text file,

The Answerschar function is a function used to write the results of a keyboard input to a file for storage and statistics to do the right or wrong thing, and the grade function is to write the statistics to do the right or wrong problem.

Code description

voidGeneratearithmetic (intNintM//functions that generate an expression{    voidLevel_1 (intNintMintNM);//single-operator arithmetic expression generation function    voidLevel_2 (intNintm);//Two-operator arithmetic-expression generation function    voidAnswerschar (intm);//functions to get the results of keyboard input operations    voidGrade (intm);//functions of statistical resultsFILE*Fpan; CharFilewirteanswers[] ="Wirteanswers.txt"; Chargchar[Ten]; intnm; Fpan= fopen (Filewirteanswers,"W");//text file to generate keyboard input operation results    if(Fpan = =NULL) {printf ("Open Anfile fail!"); } NM= N/2; if(n%2==0) {level_1 (n/2, M,NM); Level_2 (n/2, M); printf ("\ n Please enter your answer (the answer to each question is ended with a enter): \ n"); printf ("(Hint: true fractional notation: 3 ' 5/8) \ n");  for(inti =0; I < n; i++) {scanf ("%s", Gchar); fprintf (Fpan,"%s", Gchar); FPUTC ('\ n', Fpan);            } fclose (Fpan);            Answerschar (n);    Grade (n); }    Else{level_1 (n/2)+1, M,NM); Level_2 (n/2, M); printf ("\ n Please enter your answer (the answer to each question is ended with a enter): \ n"); printf ("(Hint: true fractional notation: 3 ' 5/8) \ n");  for(inti =0; I < n; i++) {scanf ("%s", Gchar); fprintf (Fpan,"%s", Gchar); FPUTC ('\ n', Fpan);        } fclose (Fpan);        Answerschar (n);    Grade (n); }}

The number of questions from the function Rcommad,ncommad N, the range of the topic value m to the function generatearithmetic (int n,int m), it will call the function level_1 (int n, int m,int nm); Single-operator arithmetic expression generation function

level_2 (int n, int m); A double-operator arithmetic expression produces a function that generates an expression. and Answerschar (int m); Is the function that obtains the result of the keyboard input operation,Grade (int m), is a function of statistical results,

function Generatearithmetic call Answerschar,grade can get the statistical result of doing right or doing wrong.

Test run

                       

It is correct to validate the program with the result of the same over calculation.

Project Summary

This project is generally a bit twists, at the beginning of the discovery cannot open the text file, and then found that the file is misplaced directories, and then appear unable to write the title and results to the file, repeated tests found that the format is not correct, resulting in the integer type after the error caused by the character type.

Then in comparison with the results of keyboard input and the results of the program, the results are clearly consistent but the sentence was wrong, Baidu has not been able to solve, and then through continuous inspection found that the string read from the file than the keyboard input will be more than a shift character, so

The thought of first storing it with a file is read on it, so it is.

Although this program basically realizes the function that produces the expression and the statistic result, but is not concise enough, and if the result is the score, does not carry on the numerator processing.

This project generally harvested quite a lot of, because their original foundation is not good, and did not do any projects, can through the foundation of the project to tamp the foundation is very good.

C Implementation of the four Operation program

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.