Wednesday 11 July 2012

Composition in C++


#include<iostream>
#include<string>
using namespace std;

class author_name
{
private: string author;
public: author_name(string auth)
{
author=auth;
}
public: string get_author()
{
return author;
}
public: void show()
{
cout<<"Author Name is == "<<author<<endl;
}
};



class Book
{
private: string book_name;
author_name *myauthor;
public: Book(string aut,string b_name)
{
myauthor=new author_name(aut);
book_name=b_name;
}
public: void show()
{
cout<<"Book name == "<<book_name<<endl;
myauthor->show();
}
};

int main()
{
Book mybook("ABCDEF","C++ LANGUAGE");
mybook.show();
getchar();
return 0;
}

No comments:

Post a Comment