The first program of software engineering

Source: Internet
Author: User

Title: Write a program that can automatically generate primary arithmetic.

Analysis: First draw a good flowchart on paper, there is a basic idea, constitute a framework, and then programming on the computer.

Using the auto-Generate function rand () generates three random numbers, including two operands, and a number representing the operation symbol.

0 represents addition, 1 represents subtraction, and 2 represents multiplication. 3 represents division.

Then the switch statement is used to realize the random appearance of the arithmetic symbol.

The code is as follows:

#include <iostream.h>
#include <stdlib.h>
void Main ()
{
int a,b,c;
for (int i=0;i<30;i++)
{
A=rand ()%100;
B=rand ()%100;
C=rand ()%4;
Switch (c)
{
Case 0:
cout<<a<< "+" <<b<< "=" <<endl;break;
Case 1:
cout<<a<< "-" <<b<< "=" <<endl;break;
Case 2:
cout<<a<< "*" <<b<< "=" <<endl;break;
Case 3:
if (b==0)
Break
Else
cout<<a<< "/" <<b<< "=" <<endl;break;
}
}
}

Operation Result:

In the short time of the class, oneself did not complete this procedure, the main reason or oneself Foundation is not firm, many basic knowledge have forgotten, at the beginning also did not learn. In the following days, to check the gaps, and try to make up for their shortcomings.

The first program of software engineering

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.