Blog work - function

0.PTA score

1. This chapter summarizes the study

1.1 learning content summary

  • 1. Definition of function: the function is a complete stand-alone program modules specific tasks, including library functions and custom functions two kinds. 例如scanf()、printf()等为库函数, Provided the system is defined by the c language, as long as you can directly call programming; cylinder()、fact()require the user to define custom functions belong.

  • 2. From the calculation function to achieve a functional standpoint, the concept of a function on the C language and mathematics are very close. Argument functions in C language called mathematical function parameters with values ​​result in mathematical function f (x) is calculated, the C language is bound to a certain data type, referred to as function type.

  • 3. The first function portion by the function types, function names and parameters in the form of tables, the first row is located in the function definition. Parameter list separated by commas each parameter, each shape must indicate the type of each of the foregoing parameters. Number of formal parameters of the function may be one, or may be a plurality, or no parameter.

  • 4. The header can function semicolon, which functions together with a complete body of the function definition.

  • 5. Any c program execution, starting with the main function main (), if they call a function, the main function is suspended in favor of the implementation of the corresponding function, the function will return after the implementation of the main function, and then from originally it was paused continue.

  • 6. When the function is defined, in its header parameter is called, the calling function is called parameter arguments. Run the program to call a function, the value of the argument is sequentially passed parameter, which is a parameter.

  • 7. The shape function must be a variable parameter, the argument may be constant or expression, arguments and parameters one correspondence, the number should be the same, the order should be, it is proposed type beginner should be consistent; returncan be run end function or be returned to the calling function with the operation result, return statement can only return a value.

  • 8.C language requirements define the function call; if before calling the function, neither the definition nor a statement, an error occurs when compiling the program.

  • 9. The function type is void, that return a result, the body can not function expressions return statement, return can be omitted; the function does not return the result of the definition, can not be omitted void; otherwise, the default function type is defined in an int; void type function, if you omit the return statement, when the function of all the statements are executed, the last encounter braces automatically return to the calling function.

  • 10. Local variables: C language function defined inside the variable called local variables; internal function of the effective scope of local variables where limited. Parameter is a local variable;
    local variables functions to avoid interference between the respective variables.

  • 11. Global variables: variable definition does not belong to any function of the outer ear function called global variables. Scope of global variables is defined from the beginning to the end of the file containing the program, within the scope of his role in all functions work.
    In general the global variables are defined in the top of the program, i.e., before the first function.

  • 12. Static local variables: stored in the static storage area, will not be the end of the function call recovery system like normal local variables as its life cycle will continue until the end of the program. Since the memory cell is preserved, once the function containing static local variable is called again, the static local variable will be re-activated, the previous value of the function call still retain, use for this call. 静态局部变量格式:static 类型名 变量表.
    Static variables given initial function only work when they first call, if there is no initial value, the system will automatically assign 0.

1.2 This chapter learning experience and the amount of code

1.2.1 Learning Experience

With learning, programming function of the charm of little by little been excavated, the learning is not just a function of our church a calculation method, but also let us know how to simplify our procedures, making it less space;

Let us appear function to enhance the readability of the code space, while the methods we can use more and more, we can do more and more questions.

1.2.2 the amount of code

Weeks The amount of code
ten 500~600
eleven 840~910
The amount of code 1340~1510

2. Integrated operations

Title: Expression primary port Automatic Generation System Operator

3. FIG function of this assignment

4. Introduction of global variables and function-

4.1. Global Variables

  • 1. Function: automatic generation of different grades of computational problems and Comparative port answers correct ratio
  • 2. global variables: count
    is subject to calculate the number of errors, to facilitate the final calculation accuracy
    global variables: all
    of each function calculation accuracy

4.2.ListMenu () function

Show all grade levels as well as their representatives digit

4.3.oralArithmeticfunction () function

  • Function: Select the desired year and the amount of the subject, to facilitate the next step function,
    and if selected grades and no error message is output
  • Idea: to determine the digital grade, enter a variable flag to determine whether the correct input

4.4.gradeOne function

  • Function: generate first-year subject, comparing answers, calculate the correct rate
  • Thinking: storing an array operator, to use random, then generates a random number calculated by the number of statistical errors of the subject, and correct ratio



4.5.gradeTwo function

  • Function: generate sophomore topic, compare answers, calculate the correct rate
  • Ideas: an array to store four operators to use random, then generates a random number calculated by the number of statistical errors of the subject, and correct ratio




4.6.gradeThree function

  • Function: generate junior title, comparing answers, calculate the correct rate, and begin to divide, in addition to 0 to troubleshoot problems
  • Ideas: an array to store four operators to use random, then generates a random number calculated by the number of statistical errors of the subject, calculation accuracy, while the divisor is determined before calculating zero




The results of the test run

  • First grade:

  • second grade:

  • Third grade:


6. Commission encountered problems and solutions

  • 1. The first is the case that the digital switch because I added '', so the program has no access has been an error; or to be reminded later only to find wrong in what
  • 2. Function Call () in the wrong many times, there has been forgotten braces
  • 3. Calculation of the symbol error input; array operator after the modification is completed to determine a good location
  • 4. Forget call sign, some data is not initialized on the use of
  • 5. I do not know there is a computer problem or procedural issues, suggesting that sometimes appear twice later answered, I do not know why this

    7. big job summary

    The big job is really hard for me, because the corresponding requirements of each logic that sometimes I would consider a particularly large number, this time I changed the code is the result of four or five times, this change is not a debugging changes, but delete all of the re-play, which is the longest time I played around 400 lines, found the problem a bit more, you need to modify the place too much, so I can not;
    second is debugging, I do not remember how many times changed but mostly certain individual data and logic debugging, how to deal with my thoughts and sometimes a sudden, and then to try;
    this is a large amount of code a lot of work, it takes a very long time, but finally hit over, it is relieved

Guess you like

Origin www.cnblogs.com/sunweiling/p/11783745.html