實驗4 類與物件2)

2022-06-03 04:09:12 字數 1190 閱讀 4351

#includeusing namespace std;

// 類graph的宣告

class graph ;

// 類graph的實現

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

graph::graph(char ch, int n): symbol(ch), size(n)

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

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

// size和symbol是類graph的私有成員資料

void graph::draw() ;

#endif

// 類graph的實現,graph.cpp

#include "graph.h"

#include using namespace std;

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

graph::graph(char ch, int n): symbol(ch), size(n)

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

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

// size和symbol是類graph的私有成員資料

void graph::draw()

2,

#includeusing namespace std;

class fraction;

fraction::fraction():top(0),bottom(1){}

fraction::fraction(int t,int b):top(t),bottom(b){}

fraction::fraction(int b):top(1),bottom(b){}

void fraction::show();

//類的實現,加上函式變數賦初值,以下

fraction::fraction():top(0),bottom(1){}

fraction::fraction(int t,int b):top(t),bottom(b){}

fraction::fraction(int t):top(t),bottom(1){}

void fraction::show(){

cout

實驗 4 類和物件 2

四.實驗 graph 1.類graph的宣告 ifndef graph h define graph h 類graph的宣告 class graph 2.類graph的實現 include graph.h include using namespace std 帶引數的建構函式的實現 graph g...

實驗三 類與物件2

任務四 vector hpp ifndef vector int hpp define vector int hpp include using namespace std class vector int vector int vector int int size,int v cout 呼叫建構...

C 實驗 實驗4 繼承與派生類 2

編寫乙個程式計算出球 圓柱和圓錐的表面積和體積。要求 1 定義乙個基類圓,至少含有乙個資料成員半徑 2 定義基類的派生類球 圓柱 圓錐,都含有求表面積和體積的成員函式和輸出函式。3 定義主函式,求球 圓柱 圓錐的和體積。include includeusing namespace std const...