Job 2 (2)

Source: Internet
Author: User
Tags integer division

1) Design Purpose:

Applied to the pupils ' own examination of arithmetic

2) Programming Environment:

using VS2010, programming language C + +

3) Specific ideas:

The program theme is divided into three parts: the definition and the invocation of the header file, arithmetic, random number obtained. which Add. minus, multiply. Except for the processing of four operations, called by the switch switch statement of the main function and a while loop, the key of the program is to get a question for the user by using "rand ()%10" To obtain an integer random or true fractional value from 0 to 9.

#include <iostream>#include<stdlib.h>#include<iomanip>#include<time.h>using namespacestd;#defineRandom () (rand ()%100)//use the rand () function to randomly generate integers within 100. voidMain () {intS1,s2,s3,s4; Srand ((int) time (NULL));//Use the Srand function to set up random seeds that are related to the current time and avoid the same random number generated each time           for(intI=0;i< -; i++)//The For loop is used to cycle 30 times, generating 30 random operations. {S1=random (); S2=random (); intK= (int) rand ()%5;//use the rand () function to randomly generate integers within 5.                    Switch(k) { Case 0:{cout<<s1<<"+"<<s2<<"=";  Break;}//Perform integer addition operations                    Case 1:{cout<<s1<<"-"<<s2<<"=";  Break;}//perform integer subtraction operations                    Case 2:{cout<<s1<<"*"<<s2<<"=";  Break;}//perform integer multiplication operations                    Case 3:{                    while(s2==0) S2=random (); cout<<s1<<"/"<<s2<<"=";  Break;}//Perform integer division operations                    Case 4://True Fractional Operations Section             {           while(s2==0|| s1>=S2) {S1=random (); S2=random (); } S3=random (); S4=random ();  while(s4==0|| s3>=S4) {S3=random (); S4=random (); }            intQ= (int) rand ()%4; Switch(q) { Case 0: cout<<"("<<s1<<"/"<<s2<<")"<<"+"<<"("<<s3<<"/"<<s4<<")"<<"=";  Break;  Case 1: cout<<"("<<s1<<"/"<<s2<<")"<<"-"<<"("<<s3<<"/"<<s4<<")"<<"=";  Break;  Case 2: cout<<"("<<s1<<"/"<<s2<<")"<<"*"<<"("<<s3<<"/"<<s4<<")"<<"=";  Break;  Case 3: cout<<"("<<s1<<"/"<<s2<<")"<<"/"<<"("<<s3<<"/"<<s4<<")"<<"=";  Break; } }} cout<<Endl; }system ("Pause");}

Program diagram

Summarize

Complete this assignment with the help of a variety of sources. Through the production of this program, the use of switch statements and random functions, and the idea of using a new understanding of some of the details and procedures of the overall structure of a certain understanding. Let me realize that I have a lot of shortcomings, in this after the study, and strive to improve all aspects of their own.

Job 2 (2)

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.