码迷,mamicode.com
首页 > 编程语言 > 详细

【c++】实现一个类

时间:2015-04-23 13:28:39      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:c++   简单的类   

// 实现一个类

#include <iostream>
using namespace std;

class Book
{
	public:	
		Book( int p, char a, char n );
		void print();
	private:
		int page;
		char author;
		char name;
};

Book::Book( int p, char a, char n )
{
	page = p;
	author = a;
	name = n;
}

void Book::print()
{
	cout<<"书名是:"<<name<<endl;
	cout<<"作者是:"<<author<<endl;
	cout<<"页数为:"<<page<<endl;	
}

int main()
{
	Book book( 200, 'd', 't' );
	book.print();
	return 0;
}

<img src="http://img.blog.csdn.net/20150423112601853?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemhhb3lhcWlhbjU1Mg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

【c++】实现一个类

标签:c++   简单的类   

原文地址:http://blog.csdn.net/zhaoyaqian552/article/details/45219321

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!