Introduction to Software engineering Personal Assignment 01

Source: Internet
Author: User
Tags random seed

One: Design ideas:

1. Randomly generates 2 random numbers from 0 to 99, used as operands, and randomly generates 1 to 0 numbers representing operator +,-,*,/.

2.if....else .... Statement controls the output of the calculation, for loop output 30 questions.

3. When the operator is "/", you need to determine whether the divisor is 0, and if 0, the number of loops plus one.

4. To ensure that the random seed is different, the Srand (Time (NULL)) function is required.

5. Loop through the questions that have already been made to see if there are any re-titles.

Two: Source program:

#include <iostream>using namespacestd; #include<string>#include<time.h>voidMain () {Srand (Time (NULL)); stringMark; intKey_one; intDividend,divider; stringresult[ -];  for(intI=0;i< -; i++) {Key_one=rand ()%4; Dividend=rand ()% -; Divider=rand ()% -; if(key_one==0) {cout<< Dividend <<"+"<< Divider <<"= ?"<<Endl; Result[i]=dividend +divider; }        Else if(key_one==1) {cout<< Dividend <<"-"<< Divider <<"= ?"<<Endl; Result[i]=dividend-divider; }        Else if(key_one==2) {cout<< Dividend <<"*"<< Divider <<"= ?"<<Endl; Result[i]=dividend *divider; }        Else if(key_one==3)        {            if(divider==0) {i++;  Break; } cout<< Dividend <<"/"<< Divider <<"= ?"<<Endl; Result[i]="Dividend/divider"; }        Elsecout<<"Please try again!"<<Endl; }}

III: Results:

Four: The reason why the class did not finish the homework on time:

Do not seriously think about the problem, the blind knock Code, the idea is not clear, just want to write a step, once the error can only find changes from scratch, wasting a lot of time.

Introduction to Software engineering Personal Assignment 01

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.