Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Learning Objectives • To review modular programming and text file input andoutpu

ID: 3618432 • Letter: L

Question

Learning Objectives
• To review modular programming and text file input andoutput,
• To design and implement a menu-driven program with updatesto a database,
• To employ call by reference,
• To use an ordered linear search and an array shift,
• To use string input and output,
• To employ an enum data type
• To produce a formatted report
Problem Scenario: Groovy Music , Inc. has requested an interactivepro-
gram to maintain its database of CD’s. The very hip owners ofthe specialty
music store needs the following transactions:
1. ADD
to add to the inventory (current balance on hand) of a CD or to adda
new title to the inventory,
2. DELETE
to delete (subtract) from the inventory (current balance on hand)of a
CD,
3. CHANGE
to change the selling price by updating the change history; Theselling
price is the most recently entered price. If the number of price tobe
entered is the fifth, the earliest price is removed and it isreplaced by
the second and the second is replaced by the third and the thirdis
replaced by the fourth, etc. There can be at most four prices inthe
price history of the CD, the last of which is the sellingprice.
4. VIEW
to view all information about a single CD when the user enters theCD
ASIN number.

The user should be prompted for the quantity of a particular CDwhich is to
be added or deleted. The number should be verified:
1. Quantity 0-100 for an addition (CDs delivered from thesupplier),
2. Quantity 0-25 for a subtraction (CDs sold) with check to makesure
that the full quantity is available.
When the program is started for the day, the current inventory isread from
the file cdinventory.dbf and stored in an array. After this, a menuis
displayed showing a list of options available to users of thisapplication.
Additional Requirements
1. Define an enumerated type called CDCategory that contains thefollow-
ing labels used to classify each CD: ROCK, CLASSICAL, COUNTRY,
and POP.
2. Use the getline(streamName,str) statement to read a multi-wordstring
from the stream streamName into the string variable str. This isnec-
essary because the artist’s name and CD title may consist ofvari-
able number of words. Use the getline command in conjunctionwith
streamName.ignore(100,’ ’) when it is used after a» since the getline
command does not ignore whitespaces.
3. The file must be read and data stored in arrays until end offile is
detected. All data fields are separated by spaces. For each CDthere is
the following data separated by spaces:
ASIN (a string) Music Category (1,2,3, or 4)
# of selling prices price history
(integer between 1-4) (max 4 real numbers with 2 decimalplaces)
balance on hand (integer)
Artist Name (string)
CD Title (string)
: : : :
//next CD record
4. Define a structure or a class with public data fields calledCDInfo that
consists of seven fields to store all the details about eachrecord. Use an
array of type double with size 4 to store the price history, thevarious
prices at which the CD has been sold.

5. Assume that there can be no more than 1000 titles in theinventory. So
your main function will consist of an array of type CDInfo ofmaximum
size 1000.
6. When your program begins, it reads the file cdinventory.dbf intothe
array. All processing by the application is done in the array. Whenthe
program ends, the data in the cdinventory.dbf file is overwrittenby
the contents of the array.
At a minimum, in addition to the main function, your program shouldcon-
sists of the following functions:
/**
This function prints a details report reflecting all available
information about each CD title in the inventory. This report
must be sorted by ASIN numbers, which must be the first column
in the inventory report. (Other formatting should be done at
your discretion but be sure to include all details in thereport.)
@param inventory an array of CDInfo structures that consists of
records of each title
@param numTitles the number of titles in stock
*/
void printInventory(const CDInfo inventory[], int numTitles);
/**
This function changes the quantity in stock for a given titles.
If the asin number does not exist in the inventory, theinventory
remains the same. No message is required to be shown for aninvalid
asin.
@param inventory an array of CDInfo structures that consists of
records of each title
@param numTitles the number of titles in stock
@param asin the identification code of the CD.
*/
void delete(CDInfo inventory[], string asin, int numTitles)
/**
This function increases the quantity in stock for a giventitles.
If the asin exist in the inventory, or increases the number oftitles
by adding a new title to the inventory if the asin does notexist.
@param inventory an array of CDInfo structures that consists of
records of each title
@param numTitles the number of titles in stock
@param asin the identification code of the CD.
*/
void add(CDInfo inventory[], string asin, int& numTitles)
/**
This function changes the current selling price as describedearlier.
This function must keep track of up to the most four recent pricechanges.
If the asin number does not exist in the inventory, the inventoryremains
the same. No message is required to be shown for an invalidasin.
@param inventory an array of CDInfo structures that consists ofrecords of each title
@param numTitles the number of titles in stock
@param asin the identification code of the CD.
@param newPrice the new selling price for a title
*/
void change(CDInfo inventory[], string asin, int numTitles, doublenewPrice)
/**
This function lists all the details for the title with thespecified
asin number. No message is required to be shown for an invalidasin.
@param inventory an array of CDInfo structures that consists ofrecords
of each title
@param numTitles the number of titles in stock
@param asin the identification code of the CD.
*/
void view(const CDInfo inventory[], string asin, int numTitles)
/**
This function displays the program menu below:

            Groovy Music, Inc.
         CD InventoryApplication
========================
ADD.......................[1]
DELETE...................[2]
VIEW.....................[3]
PRINT REPORT.........[4]
CHANGE PRICE.........[5]
EXIT......................[0]
*/
void menu()
You may add search and sort functions as auxiliary functions. Feelfree to
add any additional functions that you think will be helpful to youbut you
must define and use all the functions listed above. Also, performall file
input/output operations in the main function. As you overwrite thedata file
when the user chooses the EXIT option, be sure to preserve theformat of
the file.
To view the data file, execute the cat command followed by the filename.
For example, to view the report.out file, execute the commandbelow:
byte>cat cdinventory.dbf
You should see the contents of the file cdinventory.dbf, if thefile exists.
Follow the C++ Coding Style Guidelines we discussed in class. Nameyour
source file groovy.cpp.

Explanation / Answer

x.Hlor="red">please rate - thanks to get you started #include #include using namespace std; struct CDInfo{      string asin;      int cat;      int numprices;      double prices[4];      int have;      string artist;      string title;      }; void getdata(CDInfo[],int,istream&); void deleteit(CDInfo [], string , int ); void view(const CDInfo [], string , int ); void change(CDInfo [], string , int , double); void add(CDInfo [], string , int& ); void printInventory(const CDInfo [], int ); void menu();      int main() {CDInfo cd[1000]; int numTitles=0,choice; string asin; double newPrice; enum CDCategory{ROCK, CLASSICAL, COUNTRY,POP}; ifstream in; in.open("cdinventory.dbf");           //open file if(in.fail())             //is it ok?    { coutchoice; while(choice!=0)    {if(choice==1||choice==2||choice==3||choice==5)         {coutasin;         }     switch(choice)      {case 1:add(cd,asin, numTitles);              break;      case 2:deleteit(cd,asin,numTitles);             break;      case 3:view(cd, asin,numTitles);              break;      case 4:printInventory(cd,numTitles);             break;       case 5:coutnewPrice;            change(cd, asin,numTitles, newPrice);              break;      default:coutchoice;              } in.close();      system("pause"); return 0; } void printInventory(const CDInfo cd[], int numTitles) { } void add(CDInfo cd[], string asin, int& numTitles) {int i,num; for(i=0;i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote