#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class stock
{
char
author[50];
char
title[50];
char
pub[50];
double
price;
int
numcopies;
public:
stock();
int
access_title(char a[]);
void
input();
void
getdata(int);
};
stock::stock()
{
char author[50]={"abc"};
char title[50]={"efg"};
char pub[50]={"hij"};
price=500;
numcopies=50;
}
int stock::access_title(char a[])
{
if(strcmp(title,a))
return
0;
else
return 1;
}
void stock::getdata(int num)
{
if(numcopies>=num)
cout<<"\nCost
of "<<num<<" books is Rs. "<<(price*num);
else
cout<<"\nSorry! These many copies
are unavailable!";
}
void stock::input()
{
cout<<"\nTitle:
";
gets(title);
cout<<"\nAuthor:";
gets(author);
cout<<"\nPublisher:";
gets(pub);
cout<<"\nPrices:";
cin>>price;
cout<<"\ncopies
available:";
cin>>numcopies;
}
void main()
{
clrscr();
stock obj[2];
int n;
char ttle[50];
cout<<"Enter
details of 3 books";
for(int
i=0;i<2;++i)
obj[i].input();
cout<<endl;
cout<<"\n Enter title of required book\n";
gets(ttle);
for(i=0;i<2;i++)
{
if(obj[i].access_title(ttle))
{
cout<<"\nHow
many copies? ";
cin>>n;
obj[i].getdata(n);
}
else
cout<<"\nBook
unavailable";
}
getch();
}
OUTPUT:
Enter details of 3 books
Title: Da Vinci Code
Author:Dan Brown
Publisher:Sun
Prices:455
copies available:300
Title: Harry Potter
Author:J K Rowling
Publisher:Bloomsbury
Prices:800
copies available:100
Enter title of
required book
HarryPotter
Book available
How many copies? 20
Cost of 20 books is Rs. 16000
No comments:
Post a Comment