#include <iostream>
//#include<cstring>
#include<string.h>
using namespace std;
class book
{
char author[50];
char title[50];
int price;
char pub[50];
int numcopies;
public:
book()
{
char*author = new char[50];
char*title = new char[50];
char*pub = new char[50];
price = 0;
numcopies = 0;
}
void getdata();
void display();
int search(char t[], char a[]);
void request();
};
void book::getdata()
{
cout << "\n Enter Author : ";
cin >> author;
cout << "\n Enter Title : ";
cin >> title;
cout << "\n Enter Publisher:-";
cin >> pub;
cout << "\n Enter Price:-";
cin >> price;
cout << "\n Enter Number of Copies";
cin >> numcopies;
}
void book::display()
{
cout << "\n\tAuthor" << "\t Title" << "\t Publisher " << "\t Price " << "\t Number of Copies";
cout << "\n\t " << author << "\t " << title << "\t " << pub << "\t\t " << price << "\t\t" << numcopies;
}
int book::search(char t[], char a[])
{
if ((strcmp(title, t) && strcmp(author, a)) == 0)
{
return 0;
}
else
{
return 1;
}
}
void book::request()
{
int num;
cout << "\n Enter the number of copies you want :";
cin >> num;
if (numcopies >= num)
{
cout << "Total cost is: " << price*num;
}
else
{
cout << "Not in stock";
}
}
int main()
{
book s1[50];
int ch, n, i, a;
char tname[50], aname[50];
do
{
cout << "\n 1.Input data: \n 2.Display\n 3.Search:\n Enter your choice:";
cin >> ch;
switch (ch)
{
case 1:
cout << "\nEnter number of books : ";
cin >> n;
for (i = 0; i<n; i++)
{
s1[i].getdata();
}
break;
case 2:
cout << "\nEntered Records are:";
for (i = 0; i<n; i++)
{
s1[i].display();
}
break;
case 3:
cout << "\nEnter Title :";
cin >> tname;
cout << "\nEnter Author Name:";
cin >> aname;
if (n == 0)
{
cout << "Invalid Inputs,Try Again";
}
else
{
for (i = 0; i<n; i++)
{
a = s1[i].search(tname, aname);
if (a == 0)
{
cout << "\nBook Found";
break;
}
}
}
if (a == 0)
{
s1[i].request();
}
else
cout << "\nBook NOT Found";
}
} while (ch != 4);
return 0;
}
Blogger Comment
Facebook Comment