question archive A music shop sells CDs, DVDs, magazines and books
Subject:Computer SciencePrice:2.87 Bought7
A music shop sells CDs, DVDs, magazines and books. It is in need of a stock management system to maintain stock records with a text (command line) menu with options to allow the user to perform the following functionality: • sell items • restock items (increase stock quantity) • add new items • update stock quantity (correct stock levels) • view a report of sales It should also be possible to load and save the stock data to/from a file.
Answer:
/*------------------------------headers files---------------------------------------------*/
#include<iostream>
#include<conio.h>
#include<fstream>
#include<iomanip>
using namespace std;
#define file "stock.txt" // Constant define file name as file
fstream f;
/*----------------------------class defination -------------------------------------------*/
class Stock{
private: //private member
int book_qty;
int magine_qty;
int dvd_qty;
int cd_qty;
public: //public members
Stock() //constructor
{
this->book_qty=0;
this->magine_qty=0;
this->cd_qty=0;
this->dvd_qty=0;
}
void sell_item(); //member functions
void restock();
void add_new();
void update();
void show();
void write_file();
int read_file();
void get();
void report();
}st; //global class object
int menu() //menu function
{
int x=0;
cout<<"\n\n\t\t\t=========================Welcome to Stock Management System portal============================\n____________________________________________________________________________________________________________________\n\n";
cout<<"\n Please choose what you want\n";
cout<<"\t1. Sell item\n";
cout<<"\t2. Restock\n";
cout<<"\t3. Add new item\n";
cout<<"\t4. update stock\n";
cout<<"\t5. report\n";
cout<<"\t6. exit\n";
cout<<"\n\n\t-->> Enter your choice only number..\n\t--> ";
cin>>x;
return x;
}
/*---------------------------------Main Function--------------------------*/
int main()
{
system("color A");
do{
system("cls");
int c=menu();
switch(c)
{
case 1:
st.sell_item();
break;
case 2:
st.restock();
break;
case 3:
{
system("cls");
int x=0;
cout<<"\nEnter 1 for proceed **All data deleted and new one updated**\n\n ";
cin>>x;
if(x==1)
st.add_new();
else
cout<<"\nplease wait and press enter";
system("pause");
}break;
case 4:
st.update();
break;
case 5:
st.report();
break;
case 6:
system("cls");
cout<<setw(55)<<"Thank you for using our portal\n\n "<<setw(55);
system("pause");
exit(0);
break;
default:
cout<<" \n\n\twrong choice\n\tplease press enter...\n\t ";
getch();
break;
}
}while(1);
getch();
}
/*------------------------class methods defination-------------------------------*/
void Stock::add_new(){
system("cls");
st.get();
st.write_file();
cout<<"\n\n\t\t--------- Data Added successfully--------\n";
getch();
}
int Stock::read_file()
{
f.close();
f.open(file);
f.read((char*)this,sizeof(Stock));
if(f.good())
return 1;
else
return 0;
}
void Stock::write_file()
{
f.close();
f.open(file,ios::out);
f.write((char*)this,sizeof(Stock));
}
void Stock::get(){
cout<<"\n-------------- Please provide given data -----------\n";
cout<<"Enter the Books Quantity..\t ";
cin>>this->book_qty;
cout<<"Enter the DVDs Quantity..\t ";
cin>>this->dvd_qty;
cout<<"Enter the CDs Quantity..\t ";
cin>>this->cd_qty;
cout<<"Enter the Magines Quantity..\t ";
cin>>this->magine_qty;
}
void Stock::restock(){
Stock ss,sa;
system("cls");
cout<<"\n\t--------- Please Enter Adding Values of Each ------------\n ";
st.get();
cout<<"\n\n\n --------before restock stacks -------\n\n";
sa.read_file();
sa.show();
if(ss.read_file())
{
ss.book_qty=ss.book_qty+st.book_qty;
ss.magine_qty=ss.magine_qty+st.magine_qty;
ss.dvd_qty=ss.dvd_qty+st.dvd_qty;
ss.cd_qty=ss.cd_qty+st.cd_qty;
ss.write_file();
cout<<"\n\n\n\n\n---------+++++++ item sell updated in stock ++++++---------\n\n";
}
else
cout<<"\n data retreving error..... \n";
cout<<"\n\n\n------------- after restock stacks updated----------------\n";
st.read_file();
st.show();
getch();
}
void Stock::sell_item(){
Stock ss,sa;
system("cls");
cout<<"\n\t--------- Please Enter Selling Rate of Each ------------\n ";
st.get();
cout<<"\n\n\n --------before selling stacks -------\n\n";
sa.read_file();
sa.show();
if(ss.read_file())
{
ss.book_qty=ss.book_qty-st.book_qty;
ss.magine_qty=ss.magine_qty-st.magine_qty;
ss.dvd_qty=ss.dvd_qty-st.dvd_qty;
ss.cd_qty=ss.cd_qty-st.cd_qty;
ss.write_file();
cout<<"\n\n\n\n\n---------+++++++ item sell updated in stock ++++++---------\n\n";
}
else
cout<<"\n data retreving error..... \n";
cout<<"\n\n\n------------- after selling stacks updated----------------\n";
st.read_file();
st.show();
getch();
}
void Stock::update(){
int ch=0,a=0;
do{
system("cls");
cout<<"\n\n\n\t------------- before stock updated----------------\n";
st.read_file();
st.show();
int x,q;
Stock ss;
cout<<"\n\n\n\t--------- Please Enter Updating Values ------------\n ";
cout<<"\n\nEnter what you want to update\n";
cout<<"\n1.Books\t2.DVDs\t3.CDs\t4.Magine\t5.proceed further..\n";
cin>>x;
switch(x)
{
case 1:
cout<<"\nenter the updating books quantity...\t";
cin>>q;
ss.cd_qty=st.cd_qty;
ss.book_qty=q;
ss.dvd_qty=st.dvd_qty;
ss.magine_qty=st.magine_qty;
break;
case 2:
cout<<"\nenter the updating DVDs quantity...\t";
cin>>q;
ss.cd_qty=st.cd_qty;
ss.book_qty=st.book_qty;
ss.magine_qty=st.magine_qty;
ss.dvd_qty=q;
break;
case 3:
cout<<"\nenter the updating CDs quantity...\t";
cin>>q;
ss.book_qty=st.book_qty;
ss.dvd_qty=st.dvd_qty;
ss.magine_qty=st.magine_qty;
ss.cd_qty=q;
break;
case 4:
cout<<"\nenter the updating magine quantity...\t";
cin>>q;
ss.cd_qty=st.cd_qty;
ss.book_qty=st.book_qty;
ss.dvd_qty=st.dvd_qty;
ss.magine_qty=q;
break;
default:
a=1;
cout<<"\nenter valid choice..\t ";
break;
}
if(a != 1)
{
ss.write_file();
cout<<"\n updated ";
cout<<"\n\n\n------------- After stocks updated ----------------\n";
st.read_file();
st.show();
}
cout<<"\n\ndo you want to update another one press 1 or another for exit \t";
cin>>ch;
}while(ch==1);
getch();
}
void Stock::show(){
cout<<"\n\n Numbers of Book : \t "<<this->book_qty;
cout<<"\n\n Numbers of DVDs : \t "<<this->dvd_qty;
cout<<"\n\n Numbers of CDs : \t "<<this->cd_qty;
cout<<"\n\n Numbers of Magines : \t "<<this->magine_qty;
}
void Stock::report()
{
system("cls");
cout<<"\n\n\t----------------- Stock report --------------------\n";
if(st.read_file())
st.show();
else
cout<<"please Add some data first.... ";
getch();
}
OUTPUT:-
PFA