Software Engineering (third job)

Source: Internet
Author: User
Tags visual studio 2010

Software Engineering (third job)

Member: Zhou Deli, Wang Mingxia

First, the topic

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

1 Please refer to the contents of the Textbook page57:4.2-4.3 section, modify the original procedure, so that it conforms to the "Code style and design norms" of the basic requirements;

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

Tips:

In the case of C language, the function declaration and implementation can be stored in the header file (. h) and the source file (. c) respectively;

3 Test its simple addition function by testing the program and API interface.

Tips:

Unit test Method Please refer to the contents of page21:2.1.1 section

4 Extender features (optional)

Add feature point support for the first job:
1). The program can be a positive integer arithmetic with parentheses, support fractions, divide to retain two decimal places, such as: (1/3+1) * = 2.67, special note: Here is 2.67 instead of 2.66, or maintain fractional form: 8/3
2). The expression contains a negative integer (negative integer minimum not less than 100), and the negative number needs to be parenthesized, the user input results without parentheses. such as: (-4) = 8

Second, demand analysis

1. Basic functions

1) This software can choose the required arithmetic symbol, namely add, subtract, multiply, divide.

2) for the user-selected operation symbol can automatically generate two random numbers of integers want x, Y.

3) The software can be used to manually input the results of the operation to determine the user's answer to the wrong.

4) The correct number of errors can be counted for the correctness of the user's answer.

2. The extended function selected by this group is the second one.

That is, 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

three , Basic Design

- modified the original program to basically conform to the "Code style and design specifications" requirements.

-- split, encapsulate, and test your code in the Visual Studio 2010 environment.

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

--The function declaration and implementation are stored in the header file (. h) and the source file (. cpp), respectively.

--Test the addition in arithmetic.

Four, the code

Stdaxf.h

#include <stdio.h> #include <stdlib.h> #include <windows.h> #include <time.h>void jia (int *, int *) void Jian (int *, int *), void Cheng (int *, int *); void chu (int *, int *);

Stdafx.cpp

#include "stdafx.h" void Jia (int *p, int *q) {int x, Y, Z;srand ((unsigned) time (NULL)), x = rand ()% 201-100;y = rand ()% 201-1 00;if (x<0&&y>0) {printf ("Please enter your answer: (%d) +%d=", x, y);} else if (x>0&&y<0) printf ("Please enter your answer: (%d) +%d=", x, y); else if (x<0&&y<0) {printf ("Please enter your answer: (% d) + (%d) = ", x, y);} scanf_s ("%d", &z), if (x + y! = z) {printf ("Answer error!\n"); *q++;} else{printf ("answer correct!\n"); *p++;}} void Jian (int *p, int *q) {int x, Y, Z;srand ((unsigned) time (NULL)); x = rand ()% 201-100;y = rand ()% 201-100;if (x<0& &y>0) {printf ("Please enter your answer: (%d)-%d=", x, y);} else if (x>0&&y<0) {printf ("Please enter your answer:%d-(%d) =", x, y);} else if (x<0&&y<0) {printf ("Please enter your answer: (%d)-(%d) =", x, y);} scanf_s ("%d", &z), if (X-y! = z) {printf ("Answer error!\n"); *q++;} else{printf ("answer correct!\n"); *p++;}} void Cheng (int *p, int *q) {int x, Y, Z;srand ((unsigned) time (NULL)); x = rand ()%201-100;y = rand ()%201-100;if (x<0&amp ; &y>0) {printf ("Please enter your answer: (%d) *%d=", x, y);}else if (x>0&&y<0) {printf ("Please enter your answer:%d* (%d) =", x, y);} else if (x<0&&y<0) {printf ("Please enter your answer: (%d) * (%d) =", x, y);} scanf_s ("%d", &z), if (x*y! = z) {printf ("Answer error!\n"); *q++;} else{printf ("answer correct!\n"); *p++;}} void Chu (int *p, int *q) {int x, Y, Z;srand ((unsigned) time (NULL)); x = rand ()% 201-100;y = rand ()% 201-100;if (x<0&am p;&y>0) {printf ("Please enter your answer: (%d)/%d=", x, y);} else if (x>0&&y<0) {printf ("Please enter your answer: (%d)/%d=", x, y);} else if (x<0&&y<0) {printf ("Please enter your answer: (%d)/(%d) =", x, y);} scanf_s ("%d", &z), if (x/y! = z) {printf ("Answer error!\n"); *q++;} else{printf ("answer correct!\n"); *p++;}}

Sizeyunsuan.cpp

#include "stdafx.h"
int right = 0;int wrong = 0;void Main () {int *p = &right;int *q = &wrong;int choise, sum = 0;printf ("\n\n********** Welcome to my C-language four operating system!************************\n\n\n "); Systems (" pause "); System (" CLS "); while (1) {printf (" \ n\n\t\t\t Select the calculation symbol: \ n addition (input 1) \ t subtraction (input 2) \ t multiplication (input 3) \ t Division (input 4) \ n "), if (sum = = 0) scanf_s ("%d ", &choise); switch (choise) { Case 1:jia (P,Q); Break;case 2:jian (P,Q); Break;case 3:cheng (P,Q); Break;case 4:chu (P,Q); break;} printf ("Please select: \ t to continue (enter 1) \ t to re (enter 2) \ t to exit (input 3) \ n"), scanf_s ("%d", &sum), if (sum = = 1) sum = 1;if (sum = = 2) sum = 0;if (sum = = 3) break;} printf ("You have done%d questions, correct%d, error%d!\n", right + wrong, right, wrong); System ("Pause");}

The following is the test code:

StdAfx.h

#include <stdio.h> #include <stdlib.h> #include <windows.h> #include <time.h>int jia (int x, int y );

Test1.cpp

#include "stdafx.h" int jia (int x, int y) {return x+y;}

Test.cpp

#include "stdafx.h" int right=0,e;int wrong=0;int a=2, B=3;int  main () {printf ("\n\n********************* Welcome into my test! \n\n\n "), System (" pause "), System (" CLS "), E=jia (A, B), if (e==5) {    right++;
printf ("Correct%d \ n", right);

{
wrong++; printf ("Error%d \ n", wrong);} System ("Pause");}

  

Five, code run

Results after encapsulation:

Test Results :

Six, PSP timing

Seven, two people cooperation steps

  • First of all, we are not clear on the topic requirements, for the C language Environment, the function declaration and implementation can be stored in the header file (. h) and the source file (. c), the job has never been done.
  • Since the code written by the two were different, it took a little time to discuss whose code to use, but after deciding whose code to use, we were still unsure of the method to do the problem.
  • so through a few days, we find information on the Internet, and to the classmate, the teacher asked, got a little idea, but the specific operation is not very sure.
  • So the so-called one-point harvest, our exploration has finally succeeded, the code split successfully, but in front of us another problem arises, we do not know how to unit test code.
  • > So we decided to write the content of the blog first, and the other person first tried to write a test and normalize the code.
  • In the end, one of us has done the content of the blog, and you have another one who has done the test code and the code specification. After the synthesis, we made a rough finish of the homework.

Viii. Summary

This assignment is jointly completed by Wang Mingxia and Zhou Deli. From the beginning do not know the package, then to slowly groping, finally understand the package. This process does encounter a lot of difficulties.
However, from the encapsulated program, it does provide great convenience to those who read the program and change the program. This has benefited us a long while ago, when the teacher mentioned encapsulation, but did not emphasize that we write the program to encapsulate,
Nature cannot really experience its benefits from the practical process. At the same time in the two people's cooperation, understand its importance, whether in the Division of labor, or the idea.

Software Engineering (third 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.