#include <iostream.h>
#include <conio.h>
class Book
{
private :
int idno;
float price;
public :
void readData( )
{
cin>>idno;
cin>>price;
}
void printData( )
{
cout<<”Id no =”<<idno<<”\n”;
cout<<”Price =”<<price<<”\n”;
}
};
void main( )
{
Book books[5];
cout<<”Enter id no and price for 5 books\n”;
for(int i =0; i<5; i++)
books[i]. readData( );
cout<<”You have entered :\n”;
for(i=0 ; i<5; i++)
books[i]. printData( );
}
Output :
Enter id no and price for 5 books
112 150
224 345
342 120
445 450
566 230
You have entered :
Id no = 112 Price = 150
Id no = 224 Price = 345
Id no = 342 Price = 120
Id no = 445 Price = 450
Id no = 566 Price = 230
#include <conio.h>
class Book
{
private :
int idno;
float price;
public :
void readData( )
{
cin>>idno;
cin>>price;
}
void printData( )
{
cout<<”Id no =”<<idno<<”\n”;
cout<<”Price =”<<price<<”\n”;
}
};
void main( )
{
Book books[5];
cout<<”Enter id no and price for 5 books\n”;
for(int i =0; i<5; i++)
books[i]. readData( );
cout<<”You have entered :\n”;
for(i=0 ; i<5; i++)
books[i]. printData( );
}
Output :
Enter id no and price for 5 books
112 150
224 345
342 120
445 450
566 230
You have entered :
Id no = 112 Price = 150
Id no = 224 Price = 345
Id no = 342 Price = 120
Id no = 445 Price = 450
Id no = 566 Price = 230
0 comments:
Post a Comment