This is a C++ question. This has been asked many times on here but every program
ID: 3773315 • Letter: T
Question
This is a C++ question. This has been asked many times on here but every program does not work. Can someone please help with a working program?
This program will allow the user to keep track of a CD or DVD collection. This can only work exclusively with either CDs or DVDs since some of the data is different—your choice. Each CD/DVD in the collection will be represented as a class, so you will have one class that is a single CD/DVD.
The CD class will use a vector to keep track of the titles of the songs on the CD; this will allow each CD to have a different number of songs. It should also maintain the length of each song thus another vector. The class will also keep track of the total length of the CD. The class will also have a data member for the artist name and the name of the CD. The DVD class will have data members for the title of the movie, the length of the movie, and the year the movie was released.
The class will have a vector which is used to store the name of the actors and actresses in the movie. Another vector will be used to maintain the character names that the actor/actress played in the movie. These two vectors must work in parallel, meaning the first actor/actress in the list must correspond to the first character in the other vector. The program will maintain a list of CD/DVDs. This list will be a vector of that class type (CD or DVD).
The program must provide methods (functions) to add a CD/DVD, remove a CD/DVD and update a CD/DVD. There should also be a function that displays the entire list of CDs/DVDs. The output must be a table format, with heading. For the DVDs: Movie Title Length of Movie Year Released Actors/Actresses Characters
Note: the movie title, length of movie and year released should only appear once while the actors/actresses and characters will have several lines. So the other columns must be displayed with blanks. For the CDs: Artist CD Name Length of CD Song Title Song Length Note: the artist name, CD name and length of CD should only appear once while the song title and length will have several lines. So the other columns must be displayed with blanks.
Explanation / Answer
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
const int invSize = 2;
void getInventory(ifstream& infile, vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice); // Erin
void displayMenu(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice); // Erin
void sellItem(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice); //
void itemSearch(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice); //
void printReport(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice);
int main() // Erin
{
vector<int> itemQuantity;
vector<string> itemID;
vector<string> itemName;
vector<int> pOrdered;
vector<int> pInStore;
vector<int> pSold;
vector<double> manufPrice;
vector<double> sellingPrice;
//int itemNumber;
ifstream infile;
infile.open("C:\inventory.txt");
if (!infile)
{
cout << "Input file (inventory.txt) does not exsit." << endl;
return 1;
}
getInventory(infile, itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
displayMenu(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
//sellItem(invSize, itemID, itemName, sellingPrice, pInStore);
//itemSearch(itemID, invSize, itemNumber);
//printReport(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
infile.close();
return 0;
}
void getInventory(ifstream& infile, vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice) // Erin
unsigned int i;
string line;
//infile >> itemID(line) >> itemName(line) >> pOrdered(line) >> manufPrice(line) >> sellingPrice(line);
for (i = 0; i < itemID.size(); i++)
{
infile >> itemID[i]
>> itemName[i]
>> pOrdered[i]
>> manufPrice[i]
>> sellingPrice[i];
}
pInStore[i] = pOrdered[i];
pSold[0] = 0;
}
void displayMenu(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice) // Erin
{
char menuAnswer;
cout << "Type 'C' to check whether or not an item is in stock." << endl;
cout << "Type 'S' to sell an item to a customer." << endl;
cout << "Type 'R' to print an inventory report." << endl;
cin >> menuAnswer;
if (menuAnswer = 'C' || 'c')
itemSearch(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
if (menuAnswer = 'S' || 's')
sellItem(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
if (menuAnswer = 'R' || 'r')
printReport(itemID, itemName, pOrdered, pInStore, pSold, manufPrice, sellingPrice);
}
void sellItem(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice)
int invSize;
int itemID[invSize];
string itemName[invSize];
float sellingPrice[invSize];
int itemQuantity[invSize];
int itemNumber;
int index;
int number;
int amtBought;
float cash;
char verifyItem;
using namespace std;
//User entered information, specific for this module
//int itemNumber;
//int index;
//int number;
int amtBought;
double cash;
char verifyItem;
int i;
int itemNumber;
for (i = 0; i < 5; i++)
{
//Finding out what's being sold.
cout << "What itemID is being purchased? ";
cin >> itemNumber;
//Locating item in inventory
//index = itemSearch(itemID, invSize, itemNumber);
i = itemNumber;
if (i != -1)
{
cout << "You are selling " << itemName[i] << ", which costs $" << sellingPrice[i]
<< ". Is this correct? (Y/N)" << endl;
cout << endl;
cin >> verifyItem;
if (verifyItem == 'N' || verifyItem == 'n')
{
cout << "What item number is being purchased? " << endl;
cin >> itemNumber;
}
cout << "How many items are being purchased? " << endl;
cin >> amtBought;
if (amtBought < 1)
cout << "None of this item is being purchased!" << endl;
else
{
if (pInStore[i] < amtBought)
cout << "There are not enough of this item to sell! Up to " << pInStore[i] << " can be sold." << endl;
else
{
cout << "The total price of this transaction is " << amtBought * sellingPrice[i] << endl;
cout << "How much money did the customer give? " << endl;
cin >> cash;
if (cash < (amtBought * sellingPrice[i]))
{
cout << "The customer did not pay enough." << endl;
continue;
}
else
{
pInStore[i] = pInStore[i] - amtBought;
cout << "Please give the customer $" << cash - (amtBought * sellingPrice[i]) << " in change." << endl;
cout << "Have a nice day!" << endl;
}
}
}
}
}
}
void itemSearch(vector<string> itemID, vector<string> itemName, vector<int> pOrdered,
vector<int> pInStore, vector<int> pSold, vector<double> manufPrice,
vector<double> sellingPrice) //
{
int number;
cout << "Which item would you like to check?" << endl;
cout << endl;
cin >> number;
//for (number = 0; number < 5; number++)
if (pInStore[number] > 0)
cout << "There are " << pInStore[number] << "of that item available." << endl;
}
vector<int> pOrdered,
void printReport(vector<string> itemID, vector<string> itemName, vector<int> pOrdered, vector<int>pInStore,vector<int>pSold,vector<double>manufPrice,vector<double> sellingPrice)
unsigned int i;
int totalItems = 0;
double totalInventory = 0;
cout << " Friendly Hardware Store" << endl << endl;
cout << "itemID ItemName pOrdered pInStore pSold manufPrice sellingPrice" << endl;
cout << fixed << showpoint;
cout << setprecision(2);
// start loop at zero because the first element in a
// vector object is at location 0 (P. 576).
for (i = 0; i < itemID.size(); i++)
{
cout << left;
cout << setw(7) << itemID.at(i);
cout << setw(15) << itemName.at(i);
cout << right;
cout << setw(8) << pOrdered.at(i);
cout << setw(9) << pInStore.at(i);
cout << setw(6) << pSold.at(i);
cout << setw(11) << manufPrice.at(i);
cout << setw(13) << sellingPrice.at(i) << endl;
totalInventory += pInStore.at(i) * sellingPrice.at(i);
totalItems += pInStore.at(i);
}
cout << endl;
cout << "Total Inventory: $" << totalInventory << endl;
cout << "Total number of items in the store: " << totalItems << endl;
return;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.