軟件第二次做業:熟悉使用工具

Git地址 https://github.com/doraemon-n/dora
Git用戶名 doraemon-n
學號後五位 61205
博客地址 https://www.cnblogs.com/summer-00/
做業連接 https://www.cnblogs.com/ChildishChange/p/10398212.htm

VS安裝以及Git的學習

在網上找vs的安裝包而後勾選對應的我所須要的東西開始下載(因爲在這以前已經有了vs,因此就沒有截圖了),看https://www.cnblogs.com/math/p/git.html瞭解Git的基本做用,該如何使用。
遇到的問題大概就是下載很慢,Git是全英文,對新的環境不熟悉
***html

建立項目

打開vs,點新建->項目->c++建立項目開始編寫個人代碼



ios

代碼思路

背景
阿超家裏的孩子上小學一年級了,這個暑假老師給家長們佈置了一個做業:家長天天要給孩子出一些合理的,但要有些難度的四則運算題目,而且家長要對孩子的做業打分記錄。練習題在運算過程當中不得出現非整數
設計
(1)四則運算符:出題的四則運算符應該是隨機的,因此能夠想到用隨機函數srand(),只有四個運算符(+,-,*,/),因此用數組的方式列舉出來(或用enum)。c++

char operate()//獲取隨機運算符
{
    int seed;//隨機數種子
    cout << "請輸入隨機數種子以產生運算符"<<endl;
    cin >> seed;
    char ope[4] = { '+','-','*','/' };
    srand(seed); 
    return ope[rand() % 4];
}

(2)四則運算數:運算數在0~100之間,因此有1+rand()%100,因爲是小學一年級,運算結果不是分數,運算的過程數據也不能出現分數。git

int num()//獲取隨機數
{
    int seed;
    cout << "請輸入隨機數種子以產生0~100的數字" << endl;
    cin >> seed;
    srand(seed);
    return 1 + rand() % 100;
}

(3)完整代碼,能力有限,並無一個文件,運行界面也不同。github

#include "pch.h"
#include <iostream>
#include<cstdlib>
#include<fstream>
using namespace std;


char operate()//獲取隨機運算符
{
    int seed;
    cout << "請輸入隨機數種子以產生運算符"<<endl;
    cin >> seed;
    char ope[4] = { '+','-','*','/' };
    srand(seed); 
    return ope[rand() % 4];
}
int num()//獲取隨機數
{
    int seed;
    cout << "請輸入隨機數種子以產生0~100的數字" << endl;
    cin >> seed;
    srand(seed);
    return 1 + rand() % 100;
}

int main()
{
    int n;
    char char_1,char_2;
    int num1, num2, num3, operate_num;

    cout << "請輸入你想要的題目總數" << endl;
    cin >> n;

    while (n)//while循環,以產生對應數目的題
    {
        cout << "請輸入操做符數目(2或3)來肯定運算數的數目" << endl;
        cin >> operate_num;
        if (operate_num == 2)//有三個運算數,兩個運算符
        {
            num1 = num();
            num2 = num();
            num3 = num();
            cout << "三個隨機運算數爲" << num1 << ";" << num2 << ";" << num3 << endl;
            char_1 = operate();
            char_2 = operate();
            cout << "兩個隨機運算符爲" << char_1 << ";" << char_2 << endl;
            cout << num1 << char_1 << num2 << char_2 << num3 << "= " << endl;
        }

        else if (operate_num == 3)//有四個運算數,三個運算符
        {
            int num4;
            char char_3;
            num1 = num();
            num2 = num();
            num3 = num();
            num4 = num();
            cout << "四個隨機運算數爲" << num1 << ";" << num2 << ";" << num3 << ";" << num4 << endl;
            char_1 = operate();
            char_2 = operate();
            char_3 = operate();
            cout << "三個隨機運算符爲" << char_1 << ";" << char_2 << ";" << char_3 << endl;
            cout << num1 << char_1 << num2 << char_2 << num3 << char_3 << num4 << "= " << endl;
        }
        n--;
    }
    return 0;
}

結果數組

請輸入你想要的題目總數
2
49*52-55=
52/55*59+62=

GitHub克隆

測試問題

代碼在運行的時候顯得繁瑣,結果不能保證不出現非整數。
****
函數

感想

學習使用一個新的工具仍是有一點麻煩的,尤爲是界面是全英文,可是在不斷地摸索以後會慢慢地習慣瞭解。在寫代碼的過程當中,最開始是不知道要怎麼隨機的產生不一樣的運算符的,經過不斷思考選擇用數組,本身在寫代碼的過程當中,其實有不少沒必要要的,可是限於能力,就以爲本身應該多練習下各類不一樣的題型。而後就是本身真的不知道的必定要去問別人或者百度把它搞清楚。助教給的操做過程已經很清楚了,但本身有些地方仍是看不懂,由於有些步驟操做出來的結果與做業連接上說的不太同樣,就本身琢磨哪一步不對。工具

相關文章
相關標籤/搜索