• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. 計算機等級考試二級C++上機模擬試題及答案

        時間:2024-07-14 17:18:09 計算機等級 我要投稿
        • 相關推薦

        2016計算機等級考試二級C++上機模擬試題及答案

          一、改錯題

        2016計算機等級考試二級C++上機模擬試題及答案

          使用VC6打開考生文件夾下的工程kt6_1,此工程包含一個源程序文件kt6_1.cpp,但該程序運行有問題,請改正程序中的錯誤,使程序的輸出結果如下:

          Constructor2

          Constructor1

          i=0

          i=10

          Destructor

          源程序文件kt6_1.cpp清單如下:

          #include

          using namespace std;

          class CSample

          {

          int i;

          public:

          CSample(){cout<<"Constructor1"<

          CSample(int val){cout<<"Constructor2"<

          ~CSample(){cout<<"Destructor"<

          void disp();

          };

          /**********found**********/

          void disp()

          { cout<<"i="<

          void main()

          {

          CSample *a,b(10);

          /**********found**********/

          a->disp();

          /**********found**********/

          b->disp();

          }

          【參考答案】

          (1)將void disp()

          改為:void CSample::disp()

          (2)將a->disp();

          改為:a=new CSample; a->disp();

          (3)將b->disp();

          改為:b.disp();

          【試題解析】

          (1)主要考查類成員函數定義格式的熟練掌握,對于類體外函數的實現,應該使用作用域符"::",按照返回值類型類名::函數名(參數列表)的形式進行說明;

          (2)主要考查對動態存儲分配的掌握,根據前面的定義,a是一個指針類型的變量,指向一個對象,但是并沒有被初始化,此時a中的數據無任何意義,應該使用動態存儲分配new生成一個新的對象,并將返回的指針賦值給a;

          (3)主要考查對象指針與對象在調用成員函數時格式的不同,b是一個對象變量,使用b調用成員函數應該用"."運算符。

          修改后代碼:

          #include

          using namespace std;

          class CSample

          {

          int i;

          public:

          CSample(){cout<<"Constructor1"<

          CSample(int val){cout<<"Constructor2"<

          ~CSample(){cout<<"Destructor"<

          void disp();

          };

          /**********found**********/

          void CSample::disp()//void disp()

          { cout<<"i="<

          void main()

          {

          CSample *a,b(10);

          /**********found**********/

          a=new CSample;a->disp();

          /**********found**********/

          b.disp();

          }

          二、簡單應用題

          編寫函數fun(),它的功能是利用以下所示的簡單迭代方法求方程cos(x)-x=0的一個實根。

          xn+1=cos(xn)

          迭代步驟如下:

          (1)取x1初值為0.0。

          (2)x0=x1,把x1的值賦給x0。

          (3)x1=cos(x0),求出一個新的x1。

          (4)若x0-x1的絕對值小于0.000001,則執行步驟(5),否則執行步驟(2)。

          (5)所求x1就是方程cos(x)-x=0的一個實根,做為函數值返回。

          程序輸出結果Root=0.739085。

          注意:部分源程序已存在文件kt6_2.cpp中。

          請勿改動主函數main和其他函數中的任何內容,僅在函數fun的花括號中填入所編寫的若干語句。

          文件kt6_2的內容如下:

          #include

          #include

          using namespace std;

          float fun()

          {

          }

          void main(){

          cout<<"Root="<

          }

          【參考答案】

          float fun()

          {

          float x1=0.0,x0;

          do {

          x0=x1;

          x1=cos(x0);}

          while(fabs(x0-x1)>=1e-6);

          return x1;

          }

          【試題解析】解答本題的關鍵之處在于看清題中所給的“迭代步驟”,同時要理解xn+1=cosxn通式的含義,要考慮到x1的初值為0.0。

          fabs(x0-x1)>=0.000001和fabs(x0-x1)>=1e-6的輸出結果一致,

          但是如果沒有fabs,最后輸出結果會直接為Root=1而非Root=0.739085,

          ps:fabs(x)為對x求絕對值。說明:計算|x|,當x不為負時返回x,否則返回-x。abs和fabs是一對常用的數學函數,abs是整數取絕對值,而fabs主要用于求浮點數的絕對值。

          #include

          #include

          using namespace std;

          float fun()

          {

          float x1=0.0,x0;

          do

          {

          x0=x1;

          x1=cos(x0);

          }while(fabs(x0-x1)>=0.000001);

          return x1;

          }

          void main(){

          cout<<"Root="<

          }

          三、綜合應用題

          使用VC6打開考生文件夾下的工程kt6_3,此工程包含一個源程序文件kt6_3.cpp,其中定義了用于表示考生的類Student,請按要求完成下列操作,將程序補充完整。

          (1)定義私有數據成員code、english分別用于表示考生的編號、英語成績、它們都是int型的數據。

          。請在注釋“//**1**”之后添加適當的語句。

          (2)完成成員函數voidStudent::inputinformation()的定義,該函數用于用戶輸入一個考生對象的信息,輸入格式如下所示:

          輸入編號:

          英語成績:

          計算機成績:

          請在注釋“//**2**”之后添加適當的語句。

          (3)利用已實現的類Student的成員函數,完成函數voidfirstname(Student*A[],intnum)的定義,該函數根據考生信息A[],輸出num個考生中總分最高者的編號及其相應的總分,在此不考慮總分相同的情況。請在注釋“//**3**”之后添加適當的語句。

          注意:除在指定位置添加語句之外,請不要改動程序中的其他內容。

          源程序文件kt6_3.cpp清單如下:

          #include

          using namespace std;

          class Student

          {

          private:

          //**1**

          int computer;

          int total;

          public:

          void getinformation();

          void computesum();

          int getcode();

          int gettotalscore();

          ~Student();

          };

          void Student::getinformation()

          {

          //**2**

          cout<<"英語成績:";

          cin>>english;

          cout<<"計算機成績:";

          cin>>computer;

          }

          void Student::computesum()

          {

          total=english+computer;

          cout<<"編號"<

          }

          int Student::getcode()

          {

          return code;

          }

          int Student::gettotalscore()

          {

          return total;

          }

          void firstname(Student *A[],int num)

          {

          //**3**

          tempsum=(*A[0]).gettotalscore();

          for(int i=1;i

          {

          if(((*A[i]).gettotalscore())>tempsum)

          {

          tempcode=(*A[i]).getcode();

          tempsum=(*A[i]).gettotalscore();

          }

          }

          cout<<"總分最高者--"<

          }

          void main()

          {

          Student*A[3];

          int i,n=3;

          for(i=0;i

          {

          A[i]=new Student;

          A[i]->getinformation();

          }

          for(i=0;i

          {

          A[i]->computesum();

          }

          firstname(A,3);

          }

          【參考答案】

          (1)int code;

          int english;

          (2)cout<<"輸入編號:";

          cin>>code;

          (3)int tempcode,tempsum;

          tempcode=(*A[0]).getcode();

          【試題解析】

          本題是對C++程序設計的綜合考查,類的成員及成員函數的定義與調用,數據的輸入輸出,for循環語句,if條件判斷語句等多個知識點,其中(3)中為指針數組的使用,指針數組是一組指針,每一個成員都按照指針的操作規則,但是整個訪問規則仍然使用數組下標方式,如A[0]指的是第一個指針,而* A[0]是取出第一個指針指向的內容。

          #include

          using namespace std;

          class Student

          {

          private:

          //**1**

          int code;

          int english;

          int computer;

          int total;

          public:

          void getinformation();

          void computesum();

          int getcode();

          int gettotalscore();

          ~Student();

          };

          void Student::getinformation()

          {

          //**2**

          cout<<"輸入編號:";

          cin>>code;

          cout<<"英語成績:";

          cin>>english;

          cout<<"計算機成績:";

          cin>>computer;

          }

          void Student::computesum()

          {

          total=english+computer;

          cout<<"編號"<

          }

          int Student::getcode()

          {

          return code;

          }

          int Student::gettotalscore()

          {

          return total;

          }

          void firstname(Student *A[],int num)

          {

          //**3**

          int tempsum,tempcode;

          tempcode=(*A[0]).getcode();

          tempsum=(*A[0]).gettotalscore();

          for(int i=1;i

          {

          if(((*A[i]).gettotalscore())>tempsum)

          {

          tempcode=(*A[i]).getcode();

          tempsum=(*A[i]).gettotalscore();

          }

          }

          cout<<"總分最高者--"<

        《&.doc》
        将本文的Word文档下载到电脑,方便收藏和打印
        推荐度:
        点击下载文档

        【計算機等級考試二級C++上機模擬試題及答案】相關文章:

        計算機等級二級C語言上機模擬試題及答案10-25

        2016最新計算機二級C++上機試題及答案03-03

        計算機二級考試C++試題及答案03-27

        2017計算機等級考試二級模擬試題03-09

        計算機二級考試模擬試題及答案03-13

        2016年計算機二級C++模擬試題及答案03-07

        2016年9月計算機二級C++上機考試沖刺試題及答案03-13

        2017年9月計算機二級C++考試模擬試題及答案03-05

        計算機二級VB上機試題及答案03-14

        在线咨询
        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 在线精品免费一本 | 亚洲日韩国产精品网爆门 | 亚洲天天做日日做天天射 | 永久免费中文字幕在线 | 中文字幕乱码久久午夜 | 日韩久久精品视频 |

            2016計算機等級考試二級C++上機模擬試題及答案

              一、改錯題

            2016計算機等級考試二級C++上機模擬試題及答案

              使用VC6打開考生文件夾下的工程kt6_1,此工程包含一個源程序文件kt6_1.cpp,但該程序運行有問題,請改正程序中的錯誤,使程序的輸出結果如下:

              Constructor2

              Constructor1

              i=0

              i=10

              Destructor

              源程序文件kt6_1.cpp清單如下:

              #include

              using namespace std;

              class CSample

              {

              int i;

              public:

              CSample(){cout<<"Constructor1"<

              CSample(int val){cout<<"Constructor2"<

              ~CSample(){cout<<"Destructor"<

              void disp();

              };

              /**********found**********/

              void disp()

              { cout<<"i="<

              void main()

              {

              CSample *a,b(10);

              /**********found**********/

              a->disp();

              /**********found**********/

              b->disp();

              }

              【參考答案】

              (1)將void disp()

              改為:void CSample::disp()

              (2)將a->disp();

              改為:a=new CSample; a->disp();

              (3)將b->disp();

              改為:b.disp();

              【試題解析】

              (1)主要考查類成員函數定義格式的熟練掌握,對于類體外函數的實現,應該使用作用域符"::",按照返回值類型類名::函數名(參數列表)的形式進行說明;

              (2)主要考查對動態存儲分配的掌握,根據前面的定義,a是一個指針類型的變量,指向一個對象,但是并沒有被初始化,此時a中的數據無任何意義,應該使用動態存儲分配new生成一個新的對象,并將返回的指針賦值給a;

              (3)主要考查對象指針與對象在調用成員函數時格式的不同,b是一個對象變量,使用b調用成員函數應該用"."運算符。

              修改后代碼:

              #include

              using namespace std;

              class CSample

              {

              int i;

              public:

              CSample(){cout<<"Constructor1"<

              CSample(int val){cout<<"Constructor2"<

              ~CSample(){cout<<"Destructor"<

              void disp();

              };

              /**********found**********/

              void CSample::disp()//void disp()

              { cout<<"i="<

              void main()

              {

              CSample *a,b(10);

              /**********found**********/

              a=new CSample;a->disp();

              /**********found**********/

              b.disp();

              }

              二、簡單應用題

              編寫函數fun(),它的功能是利用以下所示的簡單迭代方法求方程cos(x)-x=0的一個實根。

              xn+1=cos(xn)

              迭代步驟如下:

              (1)取x1初值為0.0。

              (2)x0=x1,把x1的值賦給x0。

              (3)x1=cos(x0),求出一個新的x1。

              (4)若x0-x1的絕對值小于0.000001,則執行步驟(5),否則執行步驟(2)。

              (5)所求x1就是方程cos(x)-x=0的一個實根,做為函數值返回。

              程序輸出結果Root=0.739085。

              注意:部分源程序已存在文件kt6_2.cpp中。

              請勿改動主函數main和其他函數中的任何內容,僅在函數fun的花括號中填入所編寫的若干語句。

              文件kt6_2的內容如下:

              #include

              #include

              using namespace std;

              float fun()

              {

              }

              void main(){

              cout<<"Root="<

              }

              【參考答案】

              float fun()

              {

              float x1=0.0,x0;

              do {

              x0=x1;

              x1=cos(x0);}

              while(fabs(x0-x1)>=1e-6);

              return x1;

              }

              【試題解析】解答本題的關鍵之處在于看清題中所給的“迭代步驟”,同時要理解xn+1=cosxn通式的含義,要考慮到x1的初值為0.0。

              fabs(x0-x1)>=0.000001和fabs(x0-x1)>=1e-6的輸出結果一致,

              但是如果沒有fabs,最后輸出結果會直接為Root=1而非Root=0.739085,

              ps:fabs(x)為對x求絕對值。說明:計算|x|,當x不為負時返回x,否則返回-x。abs和fabs是一對常用的數學函數,abs是整數取絕對值,而fabs主要用于求浮點數的絕對值。

              #include

              #include

              using namespace std;

              float fun()

              {

              float x1=0.0,x0;

              do

              {

              x0=x1;

              x1=cos(x0);

              }while(fabs(x0-x1)>=0.000001);

              return x1;

              }

              void main(){

              cout<<"Root="<

              }

              三、綜合應用題

              使用VC6打開考生文件夾下的工程kt6_3,此工程包含一個源程序文件kt6_3.cpp,其中定義了用于表示考生的類Student,請按要求完成下列操作,將程序補充完整。

              (1)定義私有數據成員code、english分別用于表示考生的編號、英語成績、它們都是int型的數據。

              。請在注釋“//**1**”之后添加適當的語句。

              (2)完成成員函數voidStudent::inputinformation()的定義,該函數用于用戶輸入一個考生對象的信息,輸入格式如下所示:

              輸入編號:

              英語成績:

              計算機成績:

              請在注釋“//**2**”之后添加適當的語句。

              (3)利用已實現的類Student的成員函數,完成函數voidfirstname(Student*A[],intnum)的定義,該函數根據考生信息A[],輸出num個考生中總分最高者的編號及其相應的總分,在此不考慮總分相同的情況。請在注釋“//**3**”之后添加適當的語句。

              注意:除在指定位置添加語句之外,請不要改動程序中的其他內容。

              源程序文件kt6_3.cpp清單如下:

              #include

              using namespace std;

              class Student

              {

              private:

              //**1**

              int computer;

              int total;

              public:

              void getinformation();

              void computesum();

              int getcode();

              int gettotalscore();

              ~Student();

              };

              void Student::getinformation()

              {

              //**2**

              cout<<"英語成績:";

              cin>>english;

              cout<<"計算機成績:";

              cin>>computer;

              }

              void Student::computesum()

              {

              total=english+computer;

              cout<<"編號"<

              }

              int Student::getcode()

              {

              return code;

              }

              int Student::gettotalscore()

              {

              return total;

              }

              void firstname(Student *A[],int num)

              {

              //**3**

              tempsum=(*A[0]).gettotalscore();

              for(int i=1;i

              {

              if(((*A[i]).gettotalscore())>tempsum)

              {

              tempcode=(*A[i]).getcode();

              tempsum=(*A[i]).gettotalscore();

              }

              }

              cout<<"總分最高者--"<

              }

              void main()

              {

              Student*A[3];

              int i,n=3;

              for(i=0;i

              {

              A[i]=new Student;

              A[i]->getinformation();

              }

              for(i=0;i

              {

              A[i]->computesum();

              }

              firstname(A,3);

              }

              【參考答案】

              (1)int code;

              int english;

              (2)cout<<"輸入編號:";

              cin>>code;

              (3)int tempcode,tempsum;

              tempcode=(*A[0]).getcode();

              【試題解析】

              本題是對C++程序設計的綜合考查,類的成員及成員函數的定義與調用,數據的輸入輸出,for循環語句,if條件判斷語句等多個知識點,其中(3)中為指針數組的使用,指針數組是一組指針,每一個成員都按照指針的操作規則,但是整個訪問規則仍然使用數組下標方式,如A[0]指的是第一個指針,而* A[0]是取出第一個指針指向的內容。

              #include

              using namespace std;

              class Student

              {

              private:

              //**1**

              int code;

              int english;

              int computer;

              int total;

              public:

              void getinformation();

              void computesum();

              int getcode();

              int gettotalscore();

              ~Student();

              };

              void Student::getinformation()

              {

              //**2**

              cout<<"輸入編號:";

              cin>>code;

              cout<<"英語成績:";

              cin>>english;

              cout<<"計算機成績:";

              cin>>computer;

              }

              void Student::computesum()

              {

              total=english+computer;

              cout<<"編號"<

              }

              int Student::getcode()

              {

              return code;

              }

              int Student::gettotalscore()

              {

              return total;

              }

              void firstname(Student *A[],int num)

              {

              //**3**

              int tempsum,tempcode;

              tempcode=(*A[0]).getcode();

              tempsum=(*A[0]).gettotalscore();

              for(int i=1;i

              {

              if(((*A[i]).gettotalscore())>tempsum)

              {

              tempcode=(*A[i]).getcode();

              tempsum=(*A[i]).gettotalscore();

              }

              }

              cout<<"總分最高者--"<