This job is to design and implement a arithmetic topic random generator (support fractional operation), its functions include generating the problem file, and automatically generate the corresponding answer file, and according to the input of the title file, the input answer file to be graded.
Time table
PSP2.1 |
Personal Software Process Stages |
Time |
Planning |
Plan |
|
· Estimate |
· Estimate how long this task will take |
24h |
Development |
Development |
|
· Analysis |
· Demand analysis (including learning new technologies) |
2h |
· Design Spec |
· Creating a design Document |
2h |
· Design Review |
· Design Review (and colleagues review design documents) |
1h |
· Coding Standard |
· Code specification (to develop appropriate specifications for current development) |
1h |
· Design |
· Specific design |
2h |
· Coding |
· Specific code |
5h |
· Code Review |
· Code review |
1h |
· Test |
· Test (self-test, modify code, commit changes) |
10h |
Reporting |
Report |
|
· Test Report |
· Test report |
3h |
· Size Measurement |
· Computational effort |
1h |
· Postmortem & Process Improvement Plan |
· Summarize afterwards and propose process improvement plan |
1h |
|
Total |
29h |
I can see from the table that my actual time is much more than the estimated time, and in the coding and testing debug on a huge amount of time, the reason is very simple, design stage design considerations are not complete, not meticulous.
Demand analysis and Design solutions
The requirements are broadly divided into three parts:
1. Randomly generated topics based on parameters
2. Calculate the answers to the generated questions
3. Correcting a given question and answer
Careful analysis of the words, you can draw a few functional requirements:
1. Use command line arguments to enter parameters for the program
2. Achieve arithmetic between fractions and integers
3. Guaranteed non-repetition of generated topics
4. The generated topic will not appear negative at every step of the calculation
5. When output, all fractions are converted to true fractions or with fractions
6. Analysis and calculation of read-in expressions
For the above functions, it is easy to think of using a fractional class (class fraction), to unify the number of representations in the topic, and the overloaded arithmetic to implement the calculation function and output to string.
Fraction class Definition:
classFraction {Private: Long Longups; Long LongDowns; Public://constructor Functionfraction (); Fraction (intmax); Fraction (Long LongULong Longd); Fraction (strings); //Overloaded OperatorsFriend Fractionoperator+(ConstFraction &f1,ConstFraction &F2); Friend Fractionoperator-(ConstFraction &f1,ConstFraction &F2); Friend Fractionoperator*(ConstFraction &f1,ConstFraction &F2); Friend Fractionoperator/(ConstFraction &f1,ConstFraction &F2); FriendBOOL operator==(ConstFraction &f1,ConstFraction &F2); //tostirng conversion Function stringOutput ()Const;};
View Code
For the generated topics, I designed the problem class to manage all the requirements of the topic, including weight, calculation, legitimacy, and output as String
Problem class Definition:
classproblem{Private: Vector<Char>ops; Vector<fraction>numbers; Public: //constructor Functionproblem::p Roblem (); Problem (intOpnintR); Problem (Vector<Char> Ops, vector<fraction>N); //Compare and calculate BOOLCompareConstProblem &p)Const; BOOLCalculate (fraction &a)Const; //ToString Conversion Function stringOutput ()Const;};
View Code
after the data structure has been designed, the rest of the design "seems" to be "in the right way" (but this self-righteous idea behind debug, leaving a lot of pits). just use the Generate random number, step by step to generate the problem.
Test
After writing the code, I spent a lot of time on the test ... Fix the previous logic bug,
TestCase 1
Personapplication.exe-n 10
TestCase 2
Personapplication.exe-n 10-r 10
TestCase 3
Personapplication.exe-n 5000-r 10
TestCase 4
Personapplication.exe-n 10000-r 10
TestCase 5
Personapplication.exe-n 10000-r 100
The second feature is the same as the test case, but some changes are made to the answer and the title file. Because the file is too large, it is not displayed.
Performance analysis
By analyzing the chart, it can be seen that my program calls most frequently are the application of the vector container and the size () member function, which is due to the fact that I frequently press elements and eject elements in my programming.
In addition, compare () function calls are also very many, because my check weight algorithm can only be done by 22 compared to the brute force algorithm. There is no time to think and implement better algorithms orz ...
Problem, summary, Harvest
Complete the following questions and experiences on this individual project.
First of all, for the C + + language and VS2012 programming environment unfamiliar, resulting in my early start coding, very low efficiency, often on the side of the code, while searching for a variety of small problems.
then the most vexing problem encountered during the coding process is the string handling problem in C + +. In C + +, you need to differentiate between the three different string data structures of char *,cstring,string. because C + + is inherited from the other, there are many library function interfaces that accept only char * parameters, so the conversion between the string I want and the various other types of variables is where I spend a lot of time. Although it was found on the internet that the StringStream class in <sstream> was very convenient to build a string, I started using the wrong method ... Orz .... (Good Miss Java string~~~). But I ended up happily learning to use this class.
The last question is the horror of not writing detailed design documents. When I was designing, I didn't create a real design document, which led me to think and encode, resulting in a lot of effort to fix the weird logic bugs or clerical errors left in the previous code. Do not design exhausted people!!!
Personal Project---Arithmetic topic Generator Project record