資源簡介
C++實戰源碼-自定義圖書類(入門級實例204).zip
代碼片段和文件信息
//?Book.cpp?:?Defines?the?entry?point?for?the?console?application.
//
#include?“stdafx.h“
#include?“string.h“
#include?“iostream.h“
class?Book?{
private:
char?m_title[30]; //定義書名
char?m_author[30]; //定義作者
double?m_price; //定義價格
public:
Book(){}
Book(char?title[]?char?author[]?double?price)?//利用構造方法初始化域
{
strcpy((char?*)(m_title)(char?*)(title));
strcpy((char?*)(m_author)(char?*)(author));
m_price?=?price;
}
char?*?gettitle()? //獲得書名
{
return?m_title;
}
char?*?getAuthor()? //獲得作者
{
return?m_author;
}
double?getPrice()? //獲得價格
{
return?m_price;
}
};
int?main(int?argc?char*?argv[])
{
Book?book(“《VC從入門到精通(第2版)》“?“明日科技“?59.8);//創建對象
cout?<“書名:“?<tle()?< cout?<“作者:“?< cout?<“價格:“?<
return?0;
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件?????????999??2010-10-13?18:22??Book\Book.cpp
?????文件????????4512??2010-10-13?18:02??Book\Book.dsp
?????文件?????????533??2010-10-13?18:02??Book\Book.dsw
?????文件?????????291??2010-10-13?18:02??Book\StdAfx.cpp
?????文件?????????769??2010-10-13?18:02??Book\StdAfx.h
- 上一篇:C++實戰源碼-通過函數模板返回最小值
- 下一篇:C++實戰源碼-多維數組的指針參數
評論
共有 條評論