欧美色欧美亚洲高清在线观看,国产特黄特色a级在线视频,国产一区视频一区欧美,亚洲成a 人在线观看中文

  1. <ul id="fwlom"></ul>

    <object id="fwlom"></object>

    <span id="fwlom"></span><dfn id="fwlom"></dfn>

      <object id="fwlom"></object>

      C++俄羅斯方塊實驗報告(附實驗體會)[合集五篇]

      時間:2019-05-12 14:32:03下載本文作者:會員上傳
      簡介:寫寫幫文庫小編為你整理了多篇相關的《C++俄羅斯方塊實驗報告(附實驗體會)》,但愿對你工作學習有幫助,當然你在寫寫幫文庫還可以找到更多《C++俄羅斯方塊實驗報告(附實驗體會)》。

      第一篇:C++俄羅斯方塊實驗報告(附實驗體會)

      程序設計綜合實驗

      設計文檔

      惠州學院

      HUIZHOU UNIVERSITY

      課程名稱: 程序設計綜合實驗

      姓名:實驗名稱: 俄羅斯方塊 學號:任課教師:

      專業(yè):班級: 計算機科學與技術1班

      實驗時間:

      計算機科學與技術

      綜合實驗項目:俄羅斯方塊游戲

      1、問題需求

      (1)游戲等級:游戲分為1-10十個等級,等級越高,方塊下落速度越快;(2)由方向鍵控制游戲:上鍵控制方塊變形、下鍵控制方塊下移并判斷是否有消行、左鍵控制方塊左移、右鍵控制方塊右移;

      (3)游戲積分:一次性消的行數(shù)越多加的分數(shù)越多,當消行每超過30行自動提高一個游戲等級。

      2、總體設計:

      (1)用數(shù)組存放方塊(2)輸出地圖

      (3)在地圖里面輸出方塊(4)開始游戲(5)方塊的旋轉(zhuǎn)(6)方塊是否能下落(7)判斷方塊是否能下落(8)提示下一個即將下落的方塊(9)控制方塊的下落速度

      (10)分成10等級,等級越高方塊下落得更快(11)消行處理(12)游戲結(jié)束

      3、詳細設計設計說明:本程序運行代碼如下:

      #include #include #include #include “colorConsole.h”

      #define SQUARE_COLOR FOREGROUND_RED| FOREGROUND_GREEN|FOREGROUND_INTENSITY //方塊的顏色 #define up

      #define down

      #define left

      #define right

      #define esc #define MAPW

      //地圖的寬度

      #define MAPH

      //地圖的高度

      BOOL isavailable(int a[],int x,int y,int w,int h);//判定是否能放下 void turn(int a[][4],int w,int h,int *x,int y);

      //轉(zhuǎn)動 int * create();

      //創(chuàng)建方塊 void init();

      //初始化工作

      void drawblocks(int a[],int w,int h,int x,int y,WORD wColors[],int nColors);void clearcache();

      //清除鍵盤緩沖區(qū) void end();void clearsquare(int *a,int w,int h,int x,int y);void gameover();void deletemap(int m[][MAPW],int row,int w,int h);//消除一行

      int dx=30,dy=5;

      //屏幕上的偏移量 int score=0,level=0;

      int map[MAPH][MAPW];int a1[4][4]={{1},{1,1,1}};int a2[4][4]={{0,1},{1,1,1}};int a3[4][4]={{1,1},{0,1,1}};int a4[4][4]={{0,0,1},{1,1,1}};int a5[4][4]={{0,1,1},{1,1}};int a6[4][4]={{1,1,1,1}};int a7[4][4]={{1,1},{1,1}};int a[4][4];

      int main(){

      init();int *b=NULL;b=create();

      //預創(chuàng)建方塊 int q=0;int sign,blank,x,y;while(1){

      for(int i=0;i<4;i++)

      //復制方塊

      for(int j=0;j<4;j++)

      if(a[i][j]=*(b+i*4+j))blank=i;

      y=1-blank;x=4;clearsquare(&a[0][0],4,4,13,13);b=create();HANDLE handle;handle=initiate();WORD wColors[1]={FOREGROUND_RED| drawblocks(b,4,4,13,13,wColors,1);wColors[0]=SQUARE_COLOR;drawblocks(&a[0][0],4,4,x,y,wColors,1);clearcache();char string[5];wColors[0]=FOREGROUND_RED| textout(handle,26+dx,5+dy,wColors,1,itoa(score,string,10));textout(handle,26+dx,9+dy,wColors,1,itoa(level,string,10));sign=1;while(sign){

      int delay=0,max_delay=100-10*level;//延遲量 while(delay

      if(_kbhit())//用if避免按住鍵使方塊卡住 {

      switch(key){ case up:

      clearsquare(&a[0][0],4,4,x,y);turn(a,4,4,&x,y);draw=1;break;

      int draw=0;int key=_getch();FOREGROUND_GREEN|FOREGROUND_INTENSITY };FOREGROUND_GREEN|FOREGROUND_INTENSITY;

      case down:

      }

      }

      }

      delay=max_delay;break;

      if(isavailable(&a[0][0],x-1,y,4,4)){

      }

      clearsquare(&a[0][0],4,4,x,y);x--;draw=1;

      case left:

      break;

      if(isavailable(&a[0][0],x+1,y,4,4)){

      } break;end();break;

      clearsquare(&a[0][0],4,4,x,y);x++;draw=1;

      case right:

      case esc:

      if(draw){

      }

      HANDLE handle;handle=initiate();

      WORD wColors[1]={SQUARE_COLOR};drawblocks(&a[0][0],4,4,x,y,wColors,1);draw=0;

      _sleep(8);delay++;if(isavailable(&a[0][0],x,y+1,4,4))//判斷是否能下移 {

      clearsquare(&a[0][0],4,4,x,y);y++;

      HANDLE handle;

      }

      }

      }

      } else {

      }

      handle=initiate();

      WORD wColors[1]={SQUARE_COLOR};drawblocks(&a[0][0],4,4,x,y,wColors,1);

      sign=0;

      //標記,使跳出 while(sign)循環(huán),產(chǎn)生新方塊 if(y<=1)gameover();

      //是否結(jié)束 for(int i=0;i<4;i++)

      //放下方塊

      for(int j=0;j<4;j++)

      if(a[i][j]&&((i+y)

      map[i+y][j+x]=a[i][j];

      int full,k=0;

      for(i=y;i

      }

      full=1;

      for(int j=1;j<11;j++){

      }

      deletemap(map,i,MAPW,MAPH);k++;

      q++;

      score=score+k;level=min(q/30,9);if(!map[i][j])full=0;

      if(full)

      //消掉一行

      return EXIT_SUCCESS;BOOL isavailable(int a[],int x,int y,int w,int h){

      for(int i=max(y,1);i

      }

      return 0;return 1;int * create(){

      } void init(){

      for(int i=0;i<20;i++){

      } for(i=0;i<12;i++){

      } map[0][i]=-1;map[19][i]=-1;map[i][0]=-2;map[i][11]=-2;

      //初始化工作

      int * a=NULL;int c=rand()%7;switch(c){ case 0:

      } return a;a=&a1[0][0];break;a=&a2[0][0];break;a=&a3[0][0];break;a=&a4[0][0];break;a=&a5[0][0];break;a=&a6[0][0];break;a=&a7[0][0];break;case 1: case 2: case 3: case 4: case 5: case 6:

      } map[0][0]=-3;map[0][11]=-3;map[19][0]=-3;map[19][11]=-3;HANDLE handle;handle=initiate();WORD wColors[1]={ FOREGROUND_GREEN|FOREGROUND_INTENSITY};textout(handle,26+dx,3+dy,wColors,1,“分數(shù)”);textout(handle,26+dx,7+dy,wColors,1,“等級”);textout(handle,26+dx,11+dy,wColors,1,“下一個方塊提示”);wColors[1]=FOREGROUND_RED|FOREGROUND_INTENSITY;drawblocks(&map[0][0],12,20,0,0,wColors,1);textout(handle,dx,dy,wColors,1,“◇══════════◇”);wColors[0]= FOREGROUND_GREEN|FOREGROUND_INTENSITY;textout(handle,dx-16,dy,wColors,1,“按任意鍵開始”);wColors[0]=FOREGROUND_RED|FOREGROUND_INTENSITY;textout(handle,dx-15,dy+3,wColors,1,“制作者”);wColors[0]=FOREGROUND_BLUE| FOREGROUND_GREEN|FOREGROUND_INTENSITY;textout(handle,dx-15,dy+5,wColors,1,“趙強”);int x=_getch();srand(x);textout(handle,dx-16,dy,wColors,1,“

      ”);void drawblocks(int a[],int w,int h,int x,int y,WORD wColors[],int nColors){

      HANDLE handle;handle = initiate();int temp;

      for(int i=0;i

      for(int j=0;j

      if((temp=a[i*w+j])&&y+i>0){

      if(temp==-3)

      textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,“◆”);

      }

      }

      else if(temp==-2)

      textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,“║”);textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,“═”);textout(handle,2*(x+j)+dx,y+i+dy,wColors,nColors,“■”);

      else if(temp==-1)else if(temp==1)void clearcache(){

      } void end(){ } void turn(int a[][4],int w,int h,int *x,int y){

      int b[4][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};int sign=0,line=0;for(int i=h-1;i>=0;i--){

      } for(int j=0;j

      {

      } line++;sign=0;if(a[i][j]){

      }

      b[j][line]=a[i][j];sign=1;exit(EXIT_SUCCESS);while(_kbhit()){ } _getch();if(sign)

      for(i=0;i<4;i++)

      if(isavailable(&b[0][0],*x-i,y,w,h))

      {

      *x-=i;

      for(int k=0;k

      for(int j=0;j

      a[k][j]=b[k][j];

      break;} } void clearsquare(int *a,int w,int h,int x,int y){ HANDLE handle;handle=initiate();WORD wColors[1]={SQUARE_COLOR};for(int i=0;i

      for(int j=0;j

      if(a[i*w+j]&&i+y>0)

      textout(handle,2*(x+j)+dx,y+i+dy,wColors,1,“ }

      void gameover(){ HANDLE handle;handle=initiate();WORD wColors[1]={FOREGROUND_RED| FOREGROUND_GREEN};textout(handle,7+dx,10+dy,wColors,1,”游戲結(jié)束“);clearcache();_getch();exit(EXIT_SUCCESS);}

      void deletemap(int m[][MAPW],int row,int w,int h){ HANDLE handle;handle=initiate();WORD wColors[1]={SQUARE_COLOR};textout(handle,2+dx,row+dy,wColors,1,”﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌“);

      ”);

      } _sleep(100);for(int i=row;i>1;i--){

      } for(i=1;i

      } BOOL textout(HANDLE hOutput,int x,int y,WORD wColors[],int nColors,LPTSTR lpszString){

      DWORD cWritten;

      BOOL fSuccess;

      COORD coord;

      coord.X = x;

      // start at first cell

      coord.Y = y;

      //

      of first row

      fSuccess = WriteConsoleOutputCharacter(hOutput,// screen buffer handle

      lpszString,// pointer to source string

      lstrlen(lpszString), // length of string

      coord,// first cell to write to

      &cWritten);

      // actual number written

      if(!fSuccess)

      cout<<“error:WriteConsoleOutputCharacter”<

      for(;fSuccess && coord.X < lstrlen(lpszString)+x;coord.X += nColors)HANDLE hOutput;

      hOutput = GetStdHandle(STD_OUTPUT_HANDLE);return hOutput;

      {

      fSuccess = WriteConsoleOutputAttribute(hOutput,// 屏幕緩存處理

      wColors,// pointer to source string

      nColors,// length of string

      coord,// first cell to write to

      &cWritten);

      // actual number written

      }

      if(!fSuccess)

      return 0;}

      4、程序運行結(jié)果截圖: cout<<“error:WriteConsoleOutputAttribute”<

      方塊左移

      方塊右移

      下一個方塊開始下落

      方塊變形

      消一行,增加1分

      成功消多行

      消多行后分數(shù)增加更多

      消完30行后,提升一個等級

      方塊疊到頂端后游戲結(jié)束

      5、程序使用說明:

      (1)按任意鍵開始游戲

      (2)控制方塊下落位置進行消行處理

      (3)成功消行后加分,當消30行之后等級升一級,最高達到10等級

      (4)當產(chǎn)生的新方塊不能再下落時,游戲結(jié)束。(5)過程中可以按ESC直接退出游戲

      6、本實驗的心得體會

      上個學期學習C++的時候,主要是局限于讀課本,記住課本上的一些知識和概念,但很少自己親自動手去編寫代碼,總是眼高手低,當真正的去編寫這個俄羅斯游戲的時候就體會到編寫代碼真的好難,尤其是剛開始的想的時候,根本不知道如何下手。后來通過上網(wǎng)查詢和請教一些編程比較好的同學后才有了一個基本的思路,自己又重新翻閱了一下課本,將課本上的知識又重新細致的復習了一遍,最終借助于網(wǎng)絡和同學的幫助完成了這個實驗。通過這個實驗發(fā)現(xiàn)自己在編程方面還有很大的欠缺,編程能力很差勁,不過通過這個實驗,也讓我對上學期學習的C++知識有了一個很好很全面的復習,這是這個實驗帶給我最大的收獲。必須要親自動手多寫,多看代碼才能真正的學好C++。

      第二篇:C++實驗報告

      姓名:XX 學院:XXX 班級:XXX 學號:XXX

      i++;

      } while(i<=10);cout<<“sum=”<

      #include using namespace std;void main(){ int i(1),sum(0);

      for(i;i<=10,i++)

      {

      sum+=i;

      }

      cout<<“sum=”< using namespace std;const float pi=3.1416;void main(){ int itype;

      cout<<“不是合法的輸入”< using namespace std;struct riqi { int year;int mon;int day;int hour;int minut;int second;};void main(){ riqi a;cout<<“輸入時間日期”<>a.year;cout<<“輸入月份”<

      實驗

      三、函數(shù)的應用(2學時)

      1、實驗目的:

      掌握函數(shù)的定義和調(diào)用方法。練習重載函數(shù)使用。練習函數(shù)模板的使用 練習使用系統(tǒng)函數(shù)。

      在main()函數(shù)中提示輸入兩個整數(shù)x,y,使用cin語句得到x,y的值,調(diào)用pow(x,y)函數(shù)計算x的y次冪的結(jié)果,再顯示出來。程序名:lab3_4.cpp。

      編寫遞歸函數(shù)int fib(int n),在主程序中輸入n的值,調(diào)用fib函數(shù)計算Fibonacci級數(shù)。公式為fib(n)=fib(n-1)+fib(n-2),n>2;fib(1)=fib(2)=1。使用if語句判斷函數(shù)的出口,在程序中用cout語句輸出提示信息。程序名:lab3_5.cpp。

      7)調(diào)試操作步驟如下:

      選擇菜單命令Build|Start Debug |Step In,系統(tǒng)進入單步執(zhí)行狀態(tài),程序開始運行,并出現(xiàn)一個DOS窗口,此時光標停在main()函數(shù)的入口處。

      把光標移到語句answer=fib(n)前,從Debug菜單單擊Run To Cursor,在程序運行的DOS窗口中按提示輸入數(shù)字10,這時回到可視界面中,光標停在第11行,觀察一下n的值。

      從Debug菜單中單擊Step Into,程序進入fib函數(shù),觀察一下n的值,把光標移到語句return(fib(n-2)+fib(n-1))前,從Debug菜單單擊Run to Cursor,再單擊Step Into,程序遞歸調(diào)用fib函數(shù),又進入fib函數(shù),觀察n的值。

      繼續(xù)執(zhí)行程序,參照上述的方法,觀察程序的執(zhí)行順序,加深對函數(shù)調(diào)用和遞歸調(diào)用的理解。

      再試試Debug菜單欄中的別的菜單項,熟悉Debug的各種方法。

      4、實驗原理

      C++中函數(shù)的重載使得同樣的函數(shù)名下,只要參數(shù)類型、數(shù)目不同時,即可根據(jù)輸入的數(shù)據(jù)進行相應的函數(shù)調(diào)用,使用起來簡單方便。

      5、思考與體會

      C++中,函數(shù)的運用與之前學過的C語言既有相同之處,也有著不同的地方。相同的地方在于格式、用法等框架上的不變。但是C語言中對于同樣的函數(shù)名是只能夠申明一種函數(shù)的,倘若有相同的函數(shù)名出現(xiàn)系統(tǒng)即會報錯,所以用起來有時是極為不便

      0

      //參數(shù)為兩個雙精度浮點形的函數(shù) int max1(double a,double b){ a=a>b?a:b;return a;} //參數(shù)為三個雙精度浮點形的函數(shù) int max1(double a,double b,double c){ a=a>b?a:b;a=a>c?a:c;return a;} void main(void){ int a;double b;a=max1(1,2);cout<

      Lab3_3: #include using namespace std;int max1(int a,int b){ a=a>b?a:b;return a;} int max1(int a,int b,int c){ a=a>b?a:b;a=a>c?a:c;return a;}

      int main(){ int i,j,k;cout<<“請輸入要比較的3個數(shù):

      ”<

      2131415

      public: Rank rank;int frequency;float voltage;CPU(Rank r,int f,float v){

      //構(gòu)造函數(shù)

      cout<<“構(gòu)造了一個CPU”<

      rank=r;

      frequency=f;

      voltage=v;} void run(){

      cout<<“CPU開始運行”<

      } void stop(){

      cout<<“CPU停止運行”<

      cout<<“RANK=”<

      cout<<“frequency=”<

      cout<<“voltage=”<

      };

      int main(){ CPU cpu(p5,500,2000);cpu.run();cpu.show();cpu.stop();return 0;}

      Lab4_2 #include using namespace std;enum Rank{p1=1,p2,p3,p4,p5,p6,p7};//CPU類 class CPU{ public:

      //析構(gòu)函數(shù)-17

      computer(Rank r,int f,float v){

      CPU cpu(r,f,v);

      //定義CPU對象

      RAM ram(1);

      //定義RAM對象

      CDROM cdrom(1);

      //定義CDROM對象

      cpu.run();

      cpu.show();

      cpu.stop();} };int main(){ computer com(p4,300,3000);return 0;}

      實驗

      七、繼承與派生(一、二)4學時

      1、實驗目的:

      學習定義和使用類的繼承關系,定義派生類。熟悉不同繼承方式下對基類成員的訪問控制。學習利用虛基類解決二義性問題

      2、實驗任務 a)定義一個基類Animal,有私有整型成員變量age,構(gòu)造其派生類dog,在其成員函數(shù)SetAge(int n)中直接給age賦值,看看會有什么問題,把age改為公有成員變量,還會有問題嗎?編程試試看。b)定義一個基類BaseClass,有整型成員變量Number ,構(gòu)造其派生類DerivedClass,觀察構(gòu)造函數(shù)和析構(gòu)函數(shù)的執(zhí)行情況。c)定義一個車(vehicle)基類,具有MaxSpeed、Weight等成員變量,Run、Stop等成員函數(shù),由此派生出自行車(bicycle)類、汽車(motorcar)類。自行車類有高度(height)等屬性,汽車類有座位數(shù)(SeatNum)等屬性。從bicycle和motorcar派生出摩托車(motorcycle)類,在繼承過程中,注意把vehicle設置為虛基類。如果不把vehicle設置為虛基類,會有什么問題?編程試試看。

      3、實驗步驟

      編寫程序定義基類Animal,成員變量age定義為私有的。構(gòu)造派生類dog,在其成員函數(shù)SetAge(int n)中直接對age賦值時,會出現(xiàn)類似以下的錯誤提示:

      error C2248:’age’:cannot access private member declared in class ‘Animal’

      error C2248:’age’:cannot access private member declared in class ‘Animal’

      把age改為公有成員變量后重新編譯就可以了。程序名為:lab7_1.cpp

      0

      確方便我們編程。

      6、部分參考代碼

      Lab7_1 #include using namespace std;

      class Animal{

      public: int age;};

      class dog:public Animal{ public: int SetAge(int n){

      age=n;

      return age;} };

      void main(void){ int age;dog d;age=d.SetAge(3);cout<<“age=”<

      Lab7_2 #include using namespace std;class BaseClass{ public: int Number;BaseClass(){

      cout<<“這是父類的構(gòu)造函數(shù)”<

      cout<<“這是父類的析構(gòu)函數(shù)”<

      //Motorcycle繼承bicycle和motorcar類

      class motorcycle:public bicycle,public motorcar{ public: motorcycle(int seat,double H,double MS,double W){

      SeatNum=seat;

      height=H;

      MaxSpeed=MS;

      Weight=W;} void show(){

      cout<<“seatnum=”<

      cout<<“height=”<

      cout<<“MaxSpeed=”<

      cout<<“weight=”<

      int main(){ motorcycle che(3,30.33,90.84,500);che.show();return 0;} 實驗

      八、多態(tài)性2學時

      1、實驗目的:

      掌握運算符重載的方法

      習使用虛函數(shù)實現(xiàn)動態(tài)多態(tài)性。

      2、實驗任務

      a)定義Point類,有坐標x,y兩個成員變量;對Point類重載“++”、“--”運算符,實現(xiàn)對坐標值的改變。

      定義一個車(vehicle)基類,有Run、Stop等成員函數(shù),由此派生出自行車(bicycle)類、汽車(motorcar)類,從bicycle和motorcar派生出摩托車(motorcycle)類,它們都有Run、Stop等成員函數(shù)。觀察虛函的作用。

      3、實驗步驟

      編寫程序定義Point類,在類中定義整型的私有成員變量x,y,定義成員函數(shù)Point& operator++();Point operator++(int);以實現(xiàn)對Point類重載“++”運算符,定義成函數(shù)Point& operator –();Point operator

      也就是函數(shù)的重載。

      6、部分參考代碼

      Lab8_1 #include using namespace std;

      class Point{ public: Point(double x=0.0,double y=0.0):xray(x),yray(y){} Point operator++(int);Point operator--(int);void show();private: double xray;double yray;};

      Point Point::operator++(int){ return Point(xray++,yray++);}

      Point Point::operator--(int){ return Point(xray--,yray--);}

      void Point::show(){ cout<<“x坐標為”<

      int main(){ Point p(4.5,6.5);cout<<“進行運算前的情況:”<

      show(&v);return 0;}

      第三篇:信息系C++實驗報告(實驗8)

      信息工程系課程實驗報告

      實驗學時 2 實驗時間 2017 年 12 月 1 日

      實驗地點

      指導教師

      課程名稱 C++程序設計 專

      業(yè)班

      成績

      實驗項目 類和對象(構(gòu)造函數(shù)、析構(gòu)函數(shù)、組合類、友元)

      實 驗 目 的 1、理解類的概念;2、掌握聲明類的方法; 3、掌握對象的定義和初始化 4、掌握通過類編寫程序 5、構(gòu)造函數(shù)、析構(gòu)函數(shù) 6、對象數(shù)組、對象引用、對象指針 7、組合類 8、靜態(tài)成員 9、友元 實 驗 內(nèi) 容 和 要 求 1、閱讀“程序 1.txt”,然后回答以下問題:

      1)行 A 定義了一個類 Test 的對象,它將調(diào)用哪個構(gòu)造函數(shù)?

      2)行 A 能否寫成 Test t1();?

      為什么不可以或者可以?

      3)行 B 定義了另一個對象,它將調(diào)用哪個構(gòu)造函數(shù)?

      4)解釋第二個構(gòu)造函數(shù)的函數(shù)體中用到 this 指針的原因:?

      5)解釋行 C 數(shù)組 p 的含義?

      2、閱讀“程序 2.txt”,然后回答以下問題:

      1)行 A 中動態(tài)申請的數(shù)組為何還要將數(shù)組大小加 1?

      2)String 類中是否還存在默認的構(gòu)造函數(shù)“String();“?

      3)行 B 開始的構(gòu)造函數(shù)稱之為

      構(gòu)造函數(shù)。解釋其功能

      4)執(zhí)行行 C 時會調(diào)用哪個構(gòu)造函數(shù)?

      5)上機驗證該程序。

      3、閱讀“程序 3.txt”,然后回答以下問題:

      1)執(zhí)行行 A 后,a1.c=

      a2.c=

      A::c=

      2)執(zhí)行行 B 后,a1.c=

      a2.c=

      A::c=

      3)行 B 可否改為”A::c=400;”

      為什么

      4)c 為類 A 的私有成員,但行 D 中為何通過 t 能直接訪問成員 c?

      5)執(zhí)行行 E 后,a1.c=

      a2.c=

      A::c=

      第 1 題、第 2 題和第 3 題不用抄題目,只需寫答案在報告紙上。

      4、定義一個點類 Point,包括數(shù)據(jù)成員點的 x 坐標和 y 坐標(int)、構(gòu)造函數(shù)以及設置點 x,y 坐標的成員函數(shù)。定義一個 CRect 類,代表一個矩形,要求

      CRect 類中有代表矩形的左上角坐標(x1,y1)和右下角坐標(x2,y2)點類的對象(組合類),要求 CRect 類中有三個成員函數(shù) RectHeight()、RectWidth()以及area(),通過這三個函數(shù)能得到矩形的高和寬和面積。

      要求 CRect 類中有構(gòu)造函數(shù),要求 CRect 類中有成員函數(shù) SetR(),通過這函數(shù)能設置矩形的左上角坐標和右下角坐標。

      5、建立一個類 primenum,求指定數(shù)據(jù)范圍內(nèi)的所有質(zhì)數(shù)。具體要求如下:

      1)私有數(shù)據(jù)成員 int data[25]

      依次存放指定范圍內(nèi)求出的所有質(zhì)數(shù) int low,high

      存放指定的數(shù)據(jù)范圍的下限和上限 int num

      存放 low 與 high 之間的質(zhì)數(shù)的個數(shù)

      2)公有成員函數(shù) primenum(int low,int high)

      構(gòu)造函數(shù),初始化 low 和 high,同時在函數(shù)體內(nèi)初始化 num 為 0 int isprime(int x)

      判斷 x 是否為質(zhì)數(shù)。若是質(zhì)數(shù),返回 1;否則,返回 0.void process()

      求指定范圍內(nèi)的所有質(zhì)數(shù),把它們依次存放在數(shù)組 data,并將求出的質(zhì)數(shù)個數(shù)存放在 num 中 void print()

      輸出求出的質(zhì)數(shù)個數(shù)以及所有質(zhì)數(shù),要求每行輸出 5 個質(zhì)數(shù)。

      3)在主函數(shù)中對該類進行測試。例如:定義一個 primenum 類的對象 test,指定查找范圍為 100~200,求出 100~200 之間的所有質(zhì)數(shù)。

      實 驗 過 程(算法、源代碼以及注釋)

      實 驗 結(jié) 果(記錄程序執(zhí)行的結(jié)果,分析結(jié)果)

      實 驗 總 結(jié)(記錄程序在調(diào)試過程中出現(xiàn)的問題以及解決方法、總結(jié)收獲和心得)

      第四篇:C++實驗

      上機實驗:

      1、回文是指正讀,反讀均相同的字符序列,如“abba”和“abdba”均是回文,但是“good”不是回文,試用STACK類編寫該程序。

      #include #include #include int IsPalindrome(const char *cScr);void main(void){ char cStr[21];while(1){ gets(cStr);printf(“%dn”,IsPalindrome(cStr));} } int IsPalindrome(const char *cScr){ int iLen = strlen(cScr);//預留數(shù)組首元素,棧頂從第二元素開始

      int top = 1;char *cMyStack =(char *)malloc((iLen/2+1)*sizeof(char));//定位對原始數(shù)組的檢測索引初始位置 cMyStack[0] = iLen/2;if(1 == iLen%2){ ++cMyStack[0];}

      //將原始數(shù)組的一半元素入棧 for(top=1;top<=iLen/2;top++){ cMyStack[top] = *(cScr+top-1);} //從棧頂開始依次匹配

      while(*(cScr+cMyStack[0])== cMyStack[--top] && cMyStack[0]++ < iLen){} if(0 == top){//是回文數(shù) free(cMyStack);return 1;} else {//不是回文數(shù)

      free(cMyStack);return 0;} } 運行結(jié)果:

      2.利用兩個棧類S1、S2模擬一個隊列時,編寫一程序利用棧的運算實現(xiàn)隊列的插入、刪除以及判斷隊列空的運算。

      #include #include #include using namespace std;template class stack2queue{ public: void pushBack(T);void popFront();T& front();bool empty()const;private: stack mStack1;stack mStack2;};template void stack2queue::pushBack(T x){ mStack1.push(x);}

      template void stack2queue::popFront(){ if(mStack2.empty()){ while(!mStack1.empty()){ mStack2.push(mStack1.top());mStack1.pop();} }

      assert(!mStack2.empty());mStack2.pop();} template T& stack2queue::front(){ if(mStack2.empty()){ while(!mStack1.empty()){ mStack2.push(mStack1.top());mStack1.pop();} } assert(!mStack2.empty());return mStack2.top();} template bool stack2queue::empty()const{ return(mStack1.empty()&& mStack2.empty());} template void printQueue(stack2queue q){ cout << “From front to back:/t(”;if(!q.empty()){ cout << q.front();q.popFront();while(!q.empty()){ cout << “, ” << q.front();q.popFront();} }else{ cout << “NULL”;} cout << “)” << endl;} int main(){ stack2queue sq;

      sq.pushBack(1);printQueue(sq);sq.pushBack(2);printQueue(sq);sq.pushBack(3);printQueue(sq);sq.popFront();printQueue(sq);sq.popFront();printQueue(sq);sq.popFront();printQueue(sq);return 0;} 運行結(jié)果:

      實驗2:

      聲明復數(shù)的類Complex,使用友元函數(shù)add實現(xiàn)復數(shù)的加法。

      #include < iostream > using namespace std;

      class Complex { private:

      double real, image;public :

      Complex(){}

      Complex(double a,double b)

      {

      real = a;image = b;}

      void setRI(double a, double b){

      real = a;image = b;} double getReal(){ return real;}

      double getImage(){ return image;} void print(){ if(image>0)

      cout<<“復數(shù):”<< real <<“ + ”<< image <<“i”<< endl;if(image<0)

      cout<<“復數(shù):”<< real <<“-”<< image <<“i”<< endl;}

      friend Complex add(Complex ,Complex);//聲明友元函數(shù) };

      Complex add(Complex c1, Complex c2)//定義友元函數(shù)

      {

      Complex c3;

      c3.real = c1.real + c2.real;//訪問Complex類中的私有成員

      c3.image = c1.image + c2.image;return c3;}

      void main(){

      Complex c1(29, 0.634), c2, c3;c2.setRI(85,106.012);c3 = add(c1, c2);

      cout<<“復數(shù)一:”;c1.print();cout<<“復數(shù)二:”;c2.print();cout<<“相加后:”;c3.print();}

      結(jié)果:

      實驗三:

      7-5 定義一個基類Shape,在此基礎上派生出一個Rectangle和Circle,二者都有getArea()函數(shù)計算對象的面積。使用Rectangle類創(chuàng)建一個派生類Square.#include using namespace std;#define PI 3.1415926 class Shape {

      public: Shape(){}

      double GetArea()

      {

      return 0.1;}

      };class Rectangle: public Shape {

      public:

      Rectangle(double w,double h)

      {

      width=w;height=h;}

      double GetArea(){

      return width*height;}

      private: double width,height;};class Circle:public Shape { private: double r;

      public: Circle(double rr){ r=rr;}

      double GetArea(){

      return PI*r*r;} };

      int main(){

      Rectangle * rec=new Rectangle(5,6);

      Circle * cir=new Circle(5);

      cout<<“RecArea:”<GetArea()<

      cout<<“CirArea:”<GetArea()<

      return 1;

      } 運行結(jié)果:

      7-10.定義一個Object類,有數(shù)據(jù)成員weight及相應的操作函數(shù),由此派生出Box類,增加數(shù)據(jù)成員height和width及相應的操作函數(shù),聲明一個Box對象,觀察構(gòu)造函數(shù)和析構(gòu)函數(shù)的調(diào)用順序。#include class object { private: int Weight;public:

      object(){ cout<<“構(gòu)造object對象”<

      class box:public object

      { private: int Height,Width;public: box(){

      cout<<“構(gòu)造box對象”<

      第五篇:C++課程設計實驗報告(范文)

      C++課程設計報告

      設計題目:

      院: 專業(yè)班級: 學生姓名: 學生學號: 指導教師:

      計算機技術與科學

      3班 樊冠男 40912140 馬軍亮

      提交時間:

      2011/1/12 成績:

      目錄

      C++課程設計報告

      第一章 引言

      C++課程設計報告

      第二章 概要設計

      C++課程設計報告

      第三章 軟件實現(xiàn)

      C++課程設計報告

      第四章 結(jié)果與討論

      下載C++俄羅斯方塊實驗報告(附實驗體會)[合集五篇]word格式文檔
      下載C++俄羅斯方塊實驗報告(附實驗體會)[合集五篇].doc
      將本文檔下載到自己電腦,方便修改和收藏,請勿使用迅雷等下載。
      點此處下載文檔

      文檔為doc格式


      聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻自行上傳,本網(wǎng)站不擁有所有權,未作人工編輯處理,也不承擔相關法律責任。如果您發(fā)現(xiàn)有涉嫌版權的內(nèi)容,歡迎發(fā)送郵件至:645879355@qq.com 進行舉報,并提供相關證據(jù),工作人員會在5個工作日內(nèi)聯(lián)系你,一經(jīng)查實,本站將立刻刪除涉嫌侵權內(nèi)容。

      相關范文推薦

        C++上機實驗報告

        第二次上機實驗報告 姓名:王小寧班級:學號: 031012 1234 第一題: 題目: 編寫一個類,聲明一個數(shù)據(jù)成員和一個靜態(tài)數(shù)據(jù)成員,其構(gòu)造函數(shù)初始化數(shù)據(jù)成員,并把靜態(tài)數(shù)據(jù)成員加1,其析......

        C++上機實驗報告

        C++上機實驗報告 實驗名稱:實驗 專業(yè)班級: 姓名: 學號: 實驗日期: 10 11 實驗 目錄 1. 實驗目的 2. 實驗內(nèi)容 3. 程序代碼 4. 調(diào)試結(jié)果 5. 實驗心得 1. 實驗目的 實驗10 (1......

        c++實驗(網(wǎng)絡工程 ))

        面向?qū)ο蟪绦蛟O計實驗 Object Oriented Programming 課程編號: 學 分: 學 時:10 先修課程:計算機導論、C語言程序設計 適用專業(yè):計算機科學與技術、軟件工程 教 材:《C++程序設計......

        C++實驗總結(jié)報告

        C++ 實驗總結(jié)報告 研究課題:圖形編輯器一、實驗目的 1. 熟悉C++的一些重要性質(zhì),利用封裝、繼承、虛函數(shù)和多態(tài)性等特性,通過實驗學習如何對各類圖元的屬性和方法進行合理的封裝......

        C++上機實驗報告5(定稿)

        C++程序?qū)嶒瀳蟾?實驗五繼承與派生 實驗目的 1.學習定義和使用類的繼承關系,定義派生類 2.熟悉不同繼承方式下對基類成員的訪問控制 3.學習利用虛基類解決二義性問題 實驗要......

        《C++程序設計》實驗報告范例

        注意:以下藍色文字部分根據(jù)情況增刪實驗1熟悉VC++6.0集成開發(fā)環(huán)境 一、實驗時間: 2011年9月20日 二、實驗地點: 第7機房 三、指導教師: 鄧譜 四、實驗目的: 1. 了解VC++6.0的主要......

        C++小區(qū)停車位管理實驗報告

        南昌大學實驗報告 學生姓名: 學號:610 專業(yè)班級:自動化班實驗類型:□ 驗證 □ 綜合■ 設計 □ 創(chuàng)新 實驗日期:實驗成績:小區(qū)停車位管理 1.實驗要求 建立一個停車場模擬的收費管理......

        西南交大c++實驗報告11

        實驗 11實驗報告 教學班級:_26_學生學號:_2015_學生姓名:__ 實驗日期:___2016.6.3____實驗地點:__7307__(機房) 指導教師簽名:_____________ 實驗成績:______________ 一、實驗目......