Professional Documents
Culture Documents
Design a system using a class called books with suitable member functions and Constructors. Use
new operator in constructors to allocate memory space required. Implement C++ program for the
system.
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
class book {
private:
char *author,*title,*publisher;
float *price;
1
int *stock;
public:
book() {
title=new char[20];
publisher=new char[20];
stock=new int;
void feeddata();
void editdata();
void showdata();
int search(char[],char[]);
void buybook();
};
void book::feeddata() {
cin.ignore();
2
cout<<"Enter Stock Position: "; cin>>*stock;
void book::editdata() {
void book::showdata() {
cout<<"\nPrice: "<<*price;
return 1;
3
else return 0;
void book::buybook() {
int count;
cin>>count;
if(count<=*stock) {
*stock=*stock-count;
else
int main() {
book *B[20];
int i=0,r,t,choice;
char titlebuy[20],authorbuy[20];
4
while(1) {
cout<<"\n\n\t\tMENU"
<<"\n5. Exit"
cin>>choice;
switch(choice) {
B[i]->feeddata();
i++; break;
case 2: cin.ignore();
for(t=0;t<i;t++) {
if(B[t]->search(titlebuy,authorbuy)) {
5
B[t]->buybook();
break;
if(t==1)
break;
case 3: cin.ignore();
for(t=0;t<i;t++) {
if(B[t]->search(titlebuy,authorbuy)) {
B[t]->showdata();
break;
if(t==i)
6
break;
case 4: cin.ignore();
for(t=0;t<i;t++) {
if(B[t]->search(titlebuy,authorbuy)) {
B[t]->editdata();
break;
if(t==i)
break;
case 5: exit(0);
return 0;
7
}
3. Result/Output/Writing Summary:
Buy Book
8
Search For Book
Book Price was changed from 512 to 650 and Stock Position from 16 to 31
9
Learning outcomes (What I have learnt):
I learned how to create a book management system for book shop that maintains the inventory of
books that are being sold at the shop.
Evaluation Grid:
10