20190919-6 four arithmetic operations required to generate questions, twinning

This job requires See : https://edu.cnblogs.com/campus/nenu/2019fall/homework/7631

Code Address: https://e.coding.net/yangtianyu/szysuan.git

Twinning partner: Wei Xin

A Requirements: (1) Function 1 . Four arithmetic

Support the four operations subject title number 4, all of the questions asked have the ability to correctly answer

Key and difficult: the need to generate a random set of expressions, including characters

Randomly generated

void Cequation(vector<char>&infix)
{
    infix.clear();
    char r_num[5];
    int temp;
    int e_form;
    push_num=0;
    e_form=rand()%11;
char RdOp()
{
    int rd_op=rand()%4;
    if(rd_op==0)
    {
        return '+';
    }
    if(rd_op==1)
    {
        return '-';
    }
    if(rd_op==2)
    {
        return '*';
    }
    if(rd_op==3)
    {
        return '/';
    }
}

Operational priorities

int Priority(char c,string str)
{
    int priority_level=str.find(c);
    if(priority_level==2||priority_level==3)
    {
        return 2;
    }
    else if(priority_level==4||priority_level==5)
    {
        return 4;
    }
    else
    {
        return priority_level;
    }

Count the number of items correct

 IF (FABS (input_ans-ANS) <= Precision) 
            { 
                right_num ++ ; 
                printf ( " answer you, you're a genius \ the n-! " ); 
            } 
            the else 
            { 
                printf ( " Think again, the answer seems to be% .1f ! Oh \ the n- " , ANS); 
            } 
        } 
        printf ( " your% d total answer questions, a total of 20 questions. " , right_num);

Screenshot function successfully run a program

 

 

 

 Harvest, experience: features a Math function realization is not difficult, as long as the priority issue carefully arithmetic operators. Through cooperation and partnership, let me know two people cooperation should be worth noting that in those areas, we have become accustomed to college a person to complete the job, so there will certainly be suited and strange feeling, no experience of cooperation. I believe slowly get better. Although the basic syntax boring, but like tall buildings, brick by brick, we must master the next hard effort.

Function 2: Support brackets 

Key and difficult: priority matching and operation of parentheses

for(int i=0;i<13;i++)
    {
        //printf("%d",form[e_form][i]);
        temp=form[e_form][i];
        if(temp<0)//左括号
        {
            while(temp<0)
            {
                infix.push_back('(');
                temp++;
                push_num++;
            }
        }
        else if(temp>0) 
        { 
            IF (TEMP == . 3 ) // digital 
            { 
                Itoa (RAND () % . 9 + . 1 , r_num, 10 ); 
                infix.push_back (r_num [ 0 ]); 
                push_num ++ ; 
            } 
            the else  IF (TEMP == . 4 ) // operator 
            { 
                infix.push_back (RDOP ()); 
                push_num ++ ; 
            } 
            the else // right parenthesis 
            {
                while(temp>0)
                {
                    infix.push_back(')');
                    push_num++;
                    temp--;
                }
            }

Function two successfully run the program screenshots

 Harvest, experience: if you are not very understanding of data structures, can not reasonably use, then the second is the more obvious features of data structures to solve the problem, this feature is similar to the previous data structure (during and after) infix expression a stack problem . To design a good program, data structures must be mastered, so they wanted to strengthen more understanding of the various data structures, for use language to achieve a variety of data structures and algorithms.

Function 3 : defining the number of items, "fine" printout, to avoid duplication

Focus and difficult: the number of items is defined, the command line parameters to distinguish whether the decimal string are wrong or a positive integer, then the printout, to avoid duplication.

string IntoSuf(vector<char>&infix,int &push_num)
{
    string temp="";
    stack<char>s;
    s.push('#');
    for(int i=0;i<push_num;i++)
    {
        switch(infix[i])
        {
        case '(':
            s.push('(');
            break;
        case ')':
            while(!s.empty()&&s.top()!='(')
            {
                temp=temp+s.top();
                s.pop();
            }
            s.pop();
            break;
        default:
            if(isdigit(infix[i]))
            {
                temp=temp+infix[i];
            }
            else
            {
                if((s.top()=='(')||(s.top()!='('&&Priority(infix[i],s_priority)>Priority(s.top(),s_priority)))
                {
                    s.push(infix[i]);
                }
                else
                {
                    while(Priority(infix[i],s_priority)<=Priority(s.top(),s_priority))
                    {
                        temp=temp+s.top();
                        s.pop();
                    }
                    s.push(infix[i]);
                }
            }
            break;
        }
    }
    while(!s.empty())
    {
        temp=temp+s.top();
        s.pop();
    }
    //cout<<temp<<endl;
    return temp;
}
double SufCount(string &suffix)
{
    stack<char>s;
    double x,y,z;
    for(int i=0;suffix[i]!='#';i++)
    {
        if(suffix[i]>='0'&&suffix[i]<='9')
        {
            s.push(suffix[i]-'0');
        }
        else
        {
            x=s.top();
            s.pop();
            y=s.top();
            s.pop();
            z=Calculate(y,x,suffix[i]);
            s.push(z);
        }
    }
    return z;

Cheng run shot

 

Harvest, experience: once again operate on the command line, before doing little problem in this area, so when asked about the command line when nothing about the use of specific methods and its forms of expression. There are programming languages that are not commonly easy to ignore the knowledge points, need to get my attention, with less reason should not be forgotten.

Function 4: support for the topic and scores

main difficulty:

string IntoSuf(vector<char>&infix,int &push_num)
{
    string temp="";
    stack<char>s;
    s.push('#');
    for(int i=0;i<push_num;i++)
    {
        switch(infix[i])
        {
        case '(':
            s.push('(');
            break;
        case ')':
            while(!s.empty()&&s.top()!='(')
            {
                temp=temp+s.top();
                s.pop();
            }
            s.pop();
            break;
        default:
            if(isdigit(infix[i]))
            {
                temp=temp+infix[i];
            }
            else
            {
                if((s.top()=='(')||(s.top()!='('&&Priority(infix[i],s_priority)>Priority(s.top(),s_priority)))
                {
                    s.push(infix[i]);
                }
                else
                {
                    while(Priority(infix[i],s_priority)<=Priority(s.top(),s_priority))
                    {
                        temp=temp+s.top();
                        s.pop();
                    }
                    s.push(infix[i]);
                }
            }
            break;
        }
    }
    while(!s.empty())
    {
        temp=temp+s.top();
        s.pop();
    }
    //cout<<temp<<endl;
    return temp;
}
double SufCount(string &suffix)
{
    stack<char>s;
    double x,y,z;
    for(int i=0;suffix[i]!='#';i++)
    {
        if(suffix[i]>='0'&&suffix[i]<='9')
        {
            s.push(suffix[i]-'0');
        }
        else
        {
            x=s.top();
            s.pop();
            y=s.top();
            s.pop();
            z=Calculate(y,x,suffix[i]);
            s.push(z);
        }
    }
    return z;

 

Run shot

 

Experience, Harvest: Score calculation compared to the first few somewhat difficult. This location is my companion solved, I also learned a lot in the process, usually a small number to see more of the algorithm, the accumulation of various methods of problem solving.

 (2) it takes a long time, the biggest event of the harvest:

Since it is two things, that the two people pair programming can not be too dependent on each other, to be more carefully to do, we could get used to a person feels a bit awkward for two people, and slowly adapt to the road and this is the way to go for future work ;

Began a big difference in the direction of the language of choice, I finally decided to use C ++ to implement the program;

Knot the two sides should be synchronized programming, continue to improve the understanding, so you can save in not understanding because the wrong time;

 

When programming, Wei Xin classmates and I found that when implementing arithmetic expression is a difficulty, check the internet, the program finally achieved, at which point the biggest gain, pair programming can play a supervisory role; 

In analyzing the program, understand each other's meaning wrong, resulting in a lot of time is wasted, I knocked a lot of unused code, through this pair programming, mastered the basic skills, as well as to improve their skills

Requirements II: given a photo, including the twinning of the two students, workplace, computer, may include other options to express pair programming objects or scenes work experience.

Location: Guanghua room apartment A411

Computer: a notebook

photo:

 

Three requirements:

Code Address: https://e.coding.net/yangtianyu/szysuan.git

 

Guess you like

Origin www.cnblogs.com/yty0726/p/11576613.html