小學生算數系統

#include
#include <cstring>
#include<ctime>
#include<cstdlib>
using namespace std;
class Text
{
private:
    string name;
    int number;
    int num;
    int opera;
    int score;
public:
    Text(string n,int nu,int s)
    {
        name=n;
        num=nu;
        score=s;
    }
    void information();
    void exam();
    void display();
};
void Text::information()
{
    cout<<endl;
    cout<<"歡迎使用小學生測試系統"<<endl;
    cout<<endl;
    cout<<"     現在進行測驗     "<<endl;
    cout<<endl;
    cout<<"  祝你考出一個好成績  "<<endl;
    cout<<endl;
    cout<<"請輸入你的姓名"<<endl;
    cin>>name;
    cout<<"請輸入你的學號"<<endl;
    cin>>number;
    cout<<endl;
}
void Text::exam()
{
srand(time(0));
    int i,result,n;
    int figure;
    int x,y;
    for(i=1;i<=10;i++)
    {
        x=rand()%25;
        y=rand()%25;
        cout<<"第"<<i<<"題: ";
        opera=rand()%2;
        if(x<y)
        {
            n=x;
            x=y;
            y=n;
        }
    switch(opera)
    {
    case 0:
        figure=x+y;
        cout<<x<<"+"<<y<<"=";
        break;
    case 1:
        figure=x-y;
        cout<<x<<"-"<<y<<"=";
        break;
    }
           cin>>result;
           if(result==figure)
             {
       score=score+10;
                if(i==10)
                {
                    cout<<"考試結束,請查看成績"<<endl;
                    break;
                }
                cout<<"答案正確,請繼續進行測試!"<<endl;
  }
            else
            {
                cout<<"答案錯誤,請重新輸入!"<<endl;
                cin>>result;
                if(result==figure)
                {
                    score=score+7;
                    if(i==10)
                    {
                      cout<<"考試結束,請查看成績"<<endl;
                    break;
                    }
                    cout<<"答案正確,請繼續進行測試!"<<endl;
                }
                else
                {
                    cout<<"答案錯誤,請重新輸入!"<<endl;
                    cin>>result;
                    if(result==(x+y))
                    {
                        score=score+5;
                        if(i==10)
                        {
                            cout<<"考試結束,請查看成績"<<endl;
                            break;
                        }
                        cout<<"答案正確,請重新輸入!"<<endl;


                    }
                    else
                    {
                        if(i==10)
                        {
                            cout<<"考試結束,請查看成績"<<endl;
                            break;
                        }
                        cout<<"答案錯誤,請查看正確答案!"<<endl;
                        cout<<figure<<endl;
                        score=score+0;
                    }
                }
            }
    }
}


void Text::display()
{
    if(score>90)
    {
        cout<<name<<"  你的分數爲:"<<score<<endl;
        cout<<"Smart"<<endl;
    }
    else if(score>80&&score<=90)
    {
        cout<<name<<"  你的分數爲:"<<score<<endl;
        cout<<"Good"<<endl;
    }
    else if(score>70&&score<=80)
    {
        cout<<name<<"  你的分數爲:"<<score<<endl;
        cout<<"Ok"<<endl;
    }
      else if(score>60&&score<=70)
    {
        cout<<name<<"  你的分數爲:"<<score<<endl;
        cout<<"Pass"<<endl;
    }
     else
    {
        cout<<name<<"  你的分數爲:"<<score<<endl;
        cout<<"Try again"<<endl;
    }
}
int main()
{
    Text student("name",1,0);
    student.information();
    student.exam();
    student.display();
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章