實驗3 類與物件

2022-06-01 01:48:08 字數 2162 閱讀 3456

part2:

#ifndef graph_h

#define graph_h

//類graph的宣告

class

graph ;

#endif

graph.h

//

類graph的實現

#include

"graph.h

"#include

using

namespace

std;

//帶引數的建構函式的實現

graph::graph(char ch, int

n): symbol(ch), size(n)

//成員函式draw()的實現

//功能:繪製size行,顯示字元為symbol的指定圖形樣式

void

graph::draw()

}

graph.cpp

#include #include 

"graph.h

"using

namespace

std;

intmain()

main.cpp

截圖

//聲名類

class

fraction ;

#endif

fraction.h

#include "

fraction.h

"#include

using

namespace

std;

fraction::fraction(

int a, int

b) :top(a), bottom(b) //加

void

fraction::add(fraction x, fraction y)

a = top; b =bottom;

r = top %bottom;

while (r != 0

)

top = a /bottom;

bottom = b /bottom;}//

減void

fraction::min(fraction x, fraction y)

r = top %bottom;

while (r != 0

)

top = a /bottom;

bottom = b /bottom;}//

乘void

fraction::mul(fraction x, fraction y)

r = top %bottom;

while (r != 0

)

top = a /bottom;

bottom = b /bottom;}//

除void

fraction::div(fraction x, fraction y)

r = top %bottom;

while (r != 0

)

top = a /bottom;

bottom = b /bottom;}//

比較void

fraction::com(fraction x, fraction y)

//輸出

void

fraction::show()

fraction.cpp

#include #include 

#include

"fraction.h

"using

namespace

std;

intmain()

main.cpp

截圖

實驗3 類和物件

4 11 定義並實現乙個矩形類,有長,寬兩個屬性,由成員函式計算矩形的面積。include using namespace std class rectangle rectangle rectangle float length,float wide float rectangle area int...

類與物件 實驗二

實驗目的 1 掌握類的建構函式和析構函式的概念和使用方法 2 掌握物件陣列 物件指標的定義和使用方法 3 掌握new和delete的使用方法 實驗內容 1 設計描述平面座標上的點cpoint類,該類滿足下述要求 具有x,y座標資訊 具有帶預設形參值的建構函式,引數分別用於初始化x和y座標資訊 具有獲...

實驗1 類與物件

宣告乙個cpu類,包含等級 rank 頻率 frequency 電壓 voltage 等屬性,有兩個公有成員函式run stop。其中,rank為列舉型別cpu rank,宣告為enum cpu rank p1 1,p2,p3,p4,p5,p6,p7 frequency為單位是mhz的整型數,vol...