Software Engineering Personal Assignment 01

Source: Internet
Author: User

Before: Write a "software" that automatically generates 30 primary arithmetic topics, requiring that the true score be supported in addition to integers arithmetic

One, the design idea of the procedure

The use of time to produce, respectively randomly generated two numbers of operations, operation symbols, where the operation symbol can exist in a character array, the array subscript random. Then there can be a decision mechanism to prevent the occurrence of zero-doing dividend. Finally, in order to expand some later, I put the main function in the other function, the main function wrote a time seed, so that each generation of the topic is different.

Two, source program code

#include <iostream>using namespacestd; #include<time.h>#include<string>voidIntcal ()//Generating integer Calculations{         intshu1=0, shu2=0; //random number generation 0-100//Shu1=srand (+)shu1=0+rand ()% -; SHU2=0+rand ()% -; intsum=0; intfushu=0; stringfuhao[4]={"+","-","*","/"}; Fushu=((0+rand ()%4)+4)%4; //cout<<fushu<<endl; //determines whether SHU2 is 0 and rebuilds if the Fajo is removed     while(shu2==0&fushu==3) {SHU2=0+rand ()% -; }    //randomly generated symbols    Switch(Fushu) { Case 0:cout<<shu1<<fuhao[fushu]<<shu2<<"="<<endl; Break;  Case 1:cout<<shu1<<fuhao[fushu]<<shu2<<"="<<endl; Break;  Case 2:cout<<shu1<<fuhao[fushu]<<shu2<<"="<<endl; Break;  Case 3:cout<<shu1<<fuhao[fushu]<<shu2<<"="<<endl; Break; }}voidFract ()//Generating Fractional operations{    intzhenfens1_m=0, zhenfens1_z=0, zhenfens2_m=0, zhenfens2_z=0; Zhenfens1_m=0+rand ()% -; Zhenfens1_z=0+rand ()% -; //Judging the correctness of the true scores produced     while(zhenfens1_m<zhenfens1_z) {Zhenfens1_m=0+rand ()% -; Zhenfens1_z=0+rand ()% -; } zhenfens2_m=0+rand ()% -; Zhenfens2_z=0+rand ()% -; //Judging the correctness of the true scores produced     while(zhenfens2_m<zhenfens2_z) {Zhenfens2_m=0+rand ()% -; Zhenfens2_z=0+rand ()% -; }    stringfuhao[4]={"+","-","*","/"}; intFushu= ((0+rand ()%4)+4)%4; //cout<<fushu<<endl; //determines whether SHU2 is 0 and rebuilds if the Fajo is removed//randomly generated symbols    Switch(Fushu) { Case 0:cout<<"("<<zhenfens1_z<<"/"<<zhenfens1_m<<")"<<fuhao[fushu]<<"("<<zhenfens2_z<<"/"<<zhenfens2_m<<")"<<"="<<endl; Break;  Case 1:cout<<"("<<zhenfens1_z<<"/"<<zhenfens1_m<<")"<<fuhao[fushu]<<"("<<zhenfens2_z<<"/"<<zhenfens2_m<<")"<<"="<<endl; Break;  Case 2:cout<<"("<<zhenfens1_z<<"/"<<zhenfens1_m<<")"<<fuhao[fushu]<<"("<<zhenfens2_z<<"/"<<zhenfens2_m<<")"<<"="<<endl; Break;  Case 3:cout<<"("<<zhenfens1_z<<"/"<<zhenfens1_m<<")"<<fuhao[fushu]<<"("<<zhenfens2_z<<"/"<<zhenfens2_m<<")"<<"="<<endl; Break; }}voidMain () {Srand (Time (NULL));//set rand () random sequence seed with the current time of the system to ensure that the random sequence is different for each run    CharCh='a';//Select the type of Operation    intI//Select the number of questions to generate    intC=1;  while(c) {cout<<"Please select the type of operation: (Input A or a will print integer operations, input B or B will print the false fraction operation:)"<<Endl; CIN>>ch; cout<<"Please select the number of topics to print:"<<Endl; CIN>>i; if(ch=='a'|| ch=='A')        {            intJ//counter             for(j=0; j<i;j++) {intcal (); }        }        Else if(ch=='b'|| ch=='B')        {            intJ//counter             for(j=0; j<i;j++) {fract (); }} cout<<"continue Please enter 1, otherwise please enter 0"<<Endl; CIN>>C; } cout<<"over!"<<Endl;}

Iii. Results of operation

Iv. reasons for the failure of individual classes to be completed on time

Time is short, people are rather stupid.

Software Engineering Personal Assignment 01

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.