bookPorblem

 avatar
unknown
c_cpp
10 months ago
1.9 kB
4
Indexable
#include<bits/stdc++.h>
using namespace std;

class book
{
    string author, title;
    float price;
    int amt;
public:
    book()
    {
        author="";
        title="";
        price=0;
        amt=0;
        cout<<"In default constructor"<<endl;
    }
    book(string au,string tt,float p,int a)
    {
        author=au;
        title=tt;
        price=p;
        amt=a;
        cout<<"In parameterized constructor"<<endl;
    }
     string getauth()
    {
        return author;
    }

    string gettitle()
    {
        return title;
    }
     float getprice()
    {
        return price;
    }
    int getamt()
    {
        return amt;
    }

    void display()
    {
        cout<<author<<" "<<title<<" "<<price<<" "<<amt<<endl;
    }
    ~book()
    {
        cout<<"In destructor"<<endl;
    }


};

int main()
{
    book b[3];
    for (int i=0; i<3; i++)
    {
        string au, ti;
        float pri;
        int am;
        cout<<"Enter Input: ";
        cin>>au>>ti>>pri>>am;
        book c(au,ti,pri,am);
        b[i]=c;

    }

    cout<<"Enter the title: ";
    string tt;
    cin>>tt;
    int flag=0;
     for (int i=0; i<3; i++)
    {
        cout<<"Fetching: "<<b[i].gettitle()<<endl;
        if(tt==b[i].gettitle())
        {
            flag=1;
            cout<<"Price of Book:"<<b[i].getprice()<<endl;
            cout<<"Available Copies:"<<b[i].getamt()<<endl;
            cout<<"Demamded Copies:";
            int cp;
            cin>>cp;
            book up(b[i].getauth(),b[i].gettitle(),b[i].getprice(),b[i].getamt()-cp);
            b[i]=up;
        }

    }
    if(flag==0)
    {
        cout<<"Out of Stock"<<endl;
    }
    cout<<"Author  Title  Price  Amount"<<endl;
    for (int i=0; i<3; i++)
    {
        b[i].display();
    }





}





Editor is loading...
Leave a Comment