c 物件導向基礎練習題

2021-10-07 01:13:50 字數 1394 閱讀 8267

定義乙個借書證類 bookcard,在該類定義中包括如下內容:

私有成員變數:

char *stuname; //借書證學生的姓名

int id ; //借書證學生的學號

int number; //所借書的數量

再定義公有成員函式:

建構函式 //用來初始化 3 個資料成員

析構函式 //釋放動態空間

display( ) //顯示圖書證的 3 個資料成員的資訊

borrow( ) //將所借書的數量加 1,每個人限借 10 本

restore( ) //將所借書的數量減 1

在 main( )函式中,要求定義乙個圖書卡類的物件,在借閱和歸還後分

別顯示圖書證的資訊。請完成完整的程式

#includeusing namespace std;

class book

; book::book(char n[10],int a,int b)

id = a;

number = b;

}book::~book()

void book::display()

編寫完整程式實現上述內容(包括類的定義和類的實現)。要求程式執行結果顯示為:

name:zhangsan

age:24

credit:9001

#include#includeusing namespace std;

class student

complex operator ++(int);

friend ostream & operator <<(ostream &out, complex &obj);

friend istream & operator >>(istream &in, complex &obj);

};complex complex::operator++(int)

ostream & operator <<(ostream &out, complex &obj)

int main()

~point()

point operator ++();

//++i,加號後面有i就不用加東西 operator++()

//i++,++後面還要接東西就operator++(int)

friend ostream &operator <<(ostream &out,point &obj);

friend istream &operator >>(istream &in,point &obj);

};point point::operator ++()

ostream &operator <<(ostream &out, point &obj)

int main()

物件導向練習題

一 讀程式 1 寫出下列 的執行結果 class fatherclass public class test extends fatherclass public static void main string args 結果 fatherclass create fatherclass creat...

物件導向練習題

class myyear object definit self self.year int input 請輸入年份 def show season self for i in range 1,13 if i in 12,1,2 print i,冬季 elif i in 3,4,5 print i,...

C 物件導向練習題目

使用者從鍵盤輸入形式如 12 45 這樣的 數值範圍 字串,代表從12到45這個範圍。請你編寫乙個類 parse,可以解析這個字串。然後提供兩個函式,能夠獲取字串中的第乙個整數和第二個整數。10分 題目內容 parse類要提供乙個有參建構函式,接收乙個字串引數 parse類要提供乙個 int get...