夜间福利网站,免费动漫av,一级做a爰片久久毛片免费陪,夜夜骑首页,黄色毛片视频,插插插操操操,综合av色

計算機二級《C++》上機練習題及答案

時間:2025-12-15 07:24:32 試題

2016計算機二級《C++》上機練習題及答案

  一、基本操作題

  1請使用VC6或使用【答題】菜單打開考生文件夾projl下的工程projl,其中有枚舉DOGCOLOR、狗類Dog和主函數(shù)main的定義。程序中位于每個“/pic/p>

  There is a white dog named Hoh0. There is a blaCk dog named Haha. There is a motley dog named Hihi. 注意:只修改每個/pic/p>

  #inClude using namespaCe std; /pic/p>

  enum DOGCOLOR{BLACK,WHITE,YELLOW,BROWN,PIEBALD,OTHER}; Class Dog{/pic/p>

  DOGCOLOR Color; Char name[20]; statiC int Count; publiC:

  Dog(Char nalTle[],DOGCOLOR Color){ strCpy(this一>name,name);

  /pic/p>

  strCpy(this一>Color,Color);

  } 1 DOGCOLOR getColor()Const{retum Color;}

  /pic/p>

  Const Char * 9etName()Const{return*finin9;} Const Char * 9etColorString()Const{

  switCh(Color){

  Case BLACK:return”blaCk“; Case WHITE:return”white”:

  Case YELLOW:return’"yellow”: Case BROWN:return”brown”; ease PIEBALD:return”piebald”:

  }

  return”motley”;

  }

  void show()Const{ . Cout<<”There is a”<

  } }; int main(){

  /pic/p>

  Dog dogl(”Hoh0”,WHITE),dog2(”Haha”,BLACK);d0g3(”Hihi”,0THER); d091.show();

  dos2.show(); dos3.show(); return 0;

  }

  參考解析:

  (1)this->color=color:

  (2)consL char getName()eonst{return*name;}

  (3)Dog dogl(”Hoho”,WHITE)。dog2(”Haha”,

  BLACK),dog3(”Hihi”,OTHER);

  二、簡單應用題

  2請使用VC6或使用【答題】菜單打開考生文件夾proj2下的工程proj2。此工程中包含一個源程序文件main.cpp,其中有“房間”類Room及其派生出的“辦公室”類0ffice的定義,還有主函數(shù)main的定義。請在程序中“/pic/p>

  辦公室房間號:308

  辦公室長度:5.6

  辦公室寬度:4.8

  辦公室面積:26.88

  辦公室所屬部門:會計科

  注意:只能在橫線處填寫適當?shù)拇a,不要改動程序中的其他內(nèi)容,也不要刪除或移動“/pic/料料found••料”。

  #include

  using namespaee std;

  class Room{ /pic/p>

  int room_n0;/pic/p>

  double length;/pic/p>

  double width;/pic/p>

  public:

  Room(int the—room—n0,double the~length,double the—width):loom—no(the—room—no),length(the—

  length),width(the—width){}

  int theRoomNo()eonst{return iDonl—n0;}

  /pic/p>

  double theLength()const{return length;}/pic/p>

  double theWidth()const{return width;}/pic/p>

  /pic/p>

  double theArea()const{_______________}/pic/p>

  };

  class Office:public Room{/pic/p>

  char*depart;/pic/p>

  public:

  Office(int the_room_n0,double the_length,double the_width,eonst char木the_depart)

  /pic/p>

 。篲______________{

  depart=new char[strlen(the depart)+1];

  /pic/p>

  strcpy(_______________);

  }

  ~Office(){delete[]depart;}

  const char*theDepartment()const{return depart;}/pic/p>

  };

  int main(){

  /pic/p>

  Office_______________;

  cout<<”辦公室房間號:”<

  <<”辦公室長度:”<

  <<”辦公室寬度:”<

  <<”辦公室面積:”<

  <<”辦公室所屬部門:”<

  return 0;

  }

  參考解析:

  (1)returtl length*width;

  (2)Room(the_room_no,the_lengih,the_width)

  (3)depart,the_depart

  (4)an_office(308,5.6,4.8,”會汁科”)

  三、綜合應用題

  43請使用VC6或使用【答題】菜單打開考生目錄proj3下的工程文件proj3,此工程中包含一個源程序文件proj3.cpp,補充編制c++程序proj3.cpp,其功能是讀取文本文件in.dat中的全部內(nèi)容,將文本存放到doc類的對象myDoc中。然后將myDoc中的字符序列反轉(zhuǎn),并輸出到文件out.dat中。文件in.dat的長度不大于1000字節(jié)。

  要求:

  補充編制的內(nèi)容寫在“/pic/pic/p>

  注意:程序最后已將結(jié)果輸出到文件0ut.dat中,輸出函數(shù)writeToFile已經(jīng)給出并且調(diào)用。

  /pic/p>

  #include

  #include

  #include

  using namespace std;

  class doc

  {

  private:

  char*sir;/pic/p>

  int length;/pic/p>

  public:

  /pic/p>

  doc(char*filename);

  void reverse();/pic/p>

  一doc();

  void writeToFile(char*filename);

  };

  doc::doc(char}filename)

  {

  ifstream myFile(filename);

  int len=1001,tmp;

  atr=new char[1en];

  length=0;

  while((trap=myFile.get())!=EOF)

  {

  str[1ength++]=trap;

  }

  str[1ength]=‘\0’;

  myFile.close();

  }

  void doc::reverse(){

  /pic/p>

  /pic/p>

  /pic/p>

  /pic/p>

  }

  doc::~doe()

  {

  delete[]str;

  }

  void doc::writeToFile(char*filename)

  {

  Ofstream outFile(filename);

  outFile<

  outFile.close();

  }

  void main()

  {

  doc myDoc(”in.dat”);

  myDoc.reveme();

  myDoc.writeToFile(”out.dat”);

  }

  參考解析:

  int j,J;/pic/p>

  for(i=0,j=length一1;i

  chartemp=str[i];

  /pic/p>

  str[i]=str[j];

  /pic/p>

  str[j]=temp;

  /pic/p>

  }

  【考點分析】

  本題主要考查的是doc類、構(gòu)造函數(shù)、成員函數(shù)和析構(gòu)函數(shù)。

  【解題思路】

  題目要求將myDoc中的字符序列反轉(zhuǎn),在main函數(shù)中我們看到myDoc是doc類,根據(jù)doc類的定義可以知道它是把讀取文件的字符串存到str動態(tài)數(shù)組中。reverse函數(shù)實現(xiàn)將數(shù)組str中的length個字符中的第一個字符與最后一個字符交換,第二個字符與倒數(shù)第二個字符交換,依次類推。使用變量i和J,分別表示第一個字符和最后一個字符的下標,定義temp作為中間變量進行交換。

【計算機二級《C++》上機練習題及答案】相關(guān)文章:

計算機二級《C++》上機試題及答案12-31

2016計算機二級《C++》上機練習題02-03

2016計算機二級C++上機試題及答案11-25

2016計算機二級《C++》上機強化練習題09-24

2016計算機二級C++上機模擬試題及答案01-16

全國計算機二級《C++》上機試題及答案12-06

全國計算機二級《C++》上機試題附答案01-15

2017計算機二級《C++》上機模擬題及答案10-31

二級C++上機沖刺題及答案解析12-15