Program:
/* Write a C++ program to declare a class “Book” containing data members book_name , author_name & price.
Accept the information for one object of the class using pointer to that object. */
#include<iostream.h>
#include<conio.h>
class book
public:int price;
char book_name[10],author_name[10];
void get()
cout<<"Enter the name of book:";
cin>>book_name;
cout<<"Enter the author of book:";
cin>>author_name;
cout<<"Enter the price of book:";
cin>>price;
void disp()
cout<<endl;
cout<<"Name of book:\t"<<book_name<<endl;
cout<<"Author of book:\t"<<author_name<<endl;
cout<<"Price of book:\t"<<price<<endl;
};
void main()
clrscr();
book b;
book *p;
p=&b;
p->get();
p->disp();
getch();
Output:
Enter the name of book:abc
Enter the author of book:xyz
Enter the price of book:500
Name of book: abc
Author of book: xyz
Price of book: 500
Program:
/* Write a C++ program to declare a class “Box” having data members height , width & length . Accept this
information for one object of the class using pointer to that object */
#include<iostream.h>
#include<conio.h>
class box
public:int length,width,height,a,v;
void get()
cout<<"Enter the length of box:";
cin>>length;
cout<<"Enter the width of box:";
cin>>width;
cout<<"Enter the height of box:";
cin>>height;
void cal()
a=length*width;
v=length*width*height;
void disp()
cout<<endl;
cout<<"Area of box:\t"<<a<<endl;
cout<<"Volume of box:\t"<<v<<endl;
};
void main()
clrscr();
box b;
box *p;
p=&b;
p->get();
p->cal();
p->disp();
getch();
Output:
Enter the length of box:5
Enter the width of box:5
Enter the height of box:5
Area of box: 25
Volume of box: 125
Program:
/* Write a C++ program to declare a class birthday having data members day , month & year. Accept this information
for five objects using pointer t the array of objects */
#include<iostream.h>
#include<conio.h>
class birthday
public:
int day,month,year;
void get()
cout<<"Enter the day:";
cin>>day;
cout<<"Enter the month:";
cin>>month;
cout<<"Enter the year:";
cin>>year;
void disp()
cout<<endl;
cout<<"Day:\t"<<day<<endl;
cout<<"Month:\t"<<month<<endl;
cout<<"Year:\t"<<year<<endl;
};
void main()
clrscr();
int i;
birthday b[5];
birthday *p;
p=&b[0];
for(i=0;i<5;i++)
p->get();
p=&b[0];
for(i=0;i<5;i++)
p->disp();
getch();
Output:
Enter the day:01
Enter the month:01
Enter the year:2000
Enter the day:02
Enter the month:01
Enter the year:2000
Enter the day:03
Enter the month:01
Enter the year:2000
Enter the day:04
Enter the month:01
Enter the year:2000
Enter the day:05
Enter the month:01
Enter the year:2000
Day: 01
Month: 01
Year: 2000
Day: 02
Month: 01
Year: 2000
Day: 03
Month: 01
Year: 2000
Day: 04
Month: 01
Year: 2000
Day: 05
Month: 01
Year: 2000