Project Description: Goal: explore some of C++ programming’s advanced features.
ID: 3763591 • Letter: P
Question
Project Description:
Goal: explore some of C++ programming’s advanced features. In this project, there are two tasks.
Task I: write a program to create an online address book aiming to learn about fundamental concepts including class, inheritance, composition, linked list, searching, and sorting, and how to use them efficiently
Task II: write a program to keep track of a hardware store inventory in order to become familiar with the vector type and discover how to sort records using recursive functions.
Basic features make up most of two programs, but you can write your own code to add more features, and make your programs more effective and better overall.
Task I: Using classes and linked lists, design an online address book to keep track of the names, addresses, phone numbers, and dates of birth of family members, close friends, and certain business associates. Your program should be able to handle as many entries as required.
a. Define a class addressType that can store a street address, city, state, and ZIP code. Use the appropriate functions to print and store the address. Also, use constructors to automatically initialize the member variables.
b. Define a class extPersonType using the class personType (as defined in Example 10-10, Chapter 10), the class dateType (as designed in chapter 11’s Programming Exercise 2), and the class addressType. Add a member variable to this class to classify the person as a family member, friend, or business associate. Also, add a member variable to store the phone number. Add (or override) the functions to print and store the appropriate information. Use constructors to automatically initialize the member variables.
c. Define the class addressBookType using the previously defined classes. An object of the type addressBookType should be able to process as many entries as required. The program should perform the following operations:
i. Load the data into the address book from a disk.
ii. Sort the address book by last name.
iii. Search for a person by last name.
iv. Print the address phone number and date of birth (i exists) of a given person.
V. print the names of the people whose birthdays arein given month
vi. print the names of all the people between two last names.
Vii. ADD or deletes a new entry to the address book.
Ix. allow the user to save the data in the adress book.
Note that your program must use classes. linked list as well as at least one of searching and one of sorting algorithms discussed in the class. However, sequential search and sort algorithms cannot be used in this tast due to its high times and space computational complex.
Task i Write a program to keep track of a hardware store inventory the store sells various items for each item in the storm the following information is kept item ID, item name, number of pieces ordered, number of pieces currently in the store, number of pieces sold, manufacture's price for the item, and the stores selling price, at eh end of each week, the store manager would like to see a report in the following form:
itemID itemname pordered pintore psold manufprice sellingPrice
4444 circular 150 150 40 15.00 125.00
total inventory: ###########
total number of items in the store:
the total inventory is the total selling value of all of the items currently in the store. the total number of items is the sum of the number of pieces of all the items in the store
THE PROGRAM SHOULD BE MENU DRIVEN, GIVING THE USER VARIOUS CHOICE SUCH AS
1) checking whether and item is in stor
2) selling an item and
3) printing the report
4)after inputting the data, sort it accoding to the items names also after a item is sold upadate the aproriate counts
intially the number of pieces(of an item) in the store is the same as the number of pieces ordered and the number of pieces of an item sold is zero. input to the program is a filie consiting of data in the following form:
itemID
ItemName
pOrdered manuPrice sellingPrice
Use seven parallel vectors to store the information. The program must:
contain at least one function to input data into the vectors
contain at least one function to display the menu
contain at least one function to sell an item
contain at least one function to print the report for the manager
use a recursive ( but not iteration) algorithm to sort
Explanation / Answer
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
vector<string> itemID;
vector<string> itemName;
vector<int> pOrdered;
vector<int> pInStore;
vector<int> pSold;
vector<double> manufPrice;
vector<double> sellingPrice;
vector<string> s_IDs;
vector<string> s_names;
vector<double> s_selPrice;
vector<double> s_manPrice;
vector<int> s_inStore;
vector<int> s_sold;
vector<int> s_orders;
void getItems();
string getName();
void displayMenu();
void inputData();
static int GetIDx (int id);
static void OutputLine (int itemID, const string* itemName, int nPiecesOrdered, float fManPrice, float fSelPrice);
void salesMenu();
int main()
{
inputData();
displayMenu();
return 0;
}
void inputData()
{
string iID;
ifstream infile;
string iName;
int iOrdered = 0, iInStore = 0;
double imanufPrice = 0, isellingPrice = 0;
infile.open("**************/itemList.txt");
if(!infile)
{
cout << "File Not Found";
}
do
{
infile >> iID;
infile.ignore(100, ' ');
iName = getName();
infile >> iOrdered >> imanufPrice >> isellingPrice;
itemID.push_back(iID);
itemName.push_back(iName);
pOrdered.push_back(iOrdered);
pInStore.push_back(iOrdered);
manufPrice.push_back(imanufPrice);
sellingPrice.push_back(isellingPrice);
pSold.push_back(0);
}
while(!infile.eof());
}
string getName()
{
char ch;
string s;
ifstream infile;
infile.open("itemList.txt");
infile >> s;
infile.get(ch);
while (ch != ' ' && ch!= ' ')
{
s = s + ch;
infile.get(ch);
}
return s;
}
static void outputVectors()
{
cout << " Hardware Store"<< " " << endl << endl;
cout << "itemID itemName pOrdered pInStore pSold manufPrice sellingPrice"<< endl;
/*
for (int i = 0 ; i < s_IDs.size(); i++)
{
if (s_IDs [i] != 0)
cout << s_IDs [i] << ' ' << s_names [i].szName<< ' ' << s_orders [i] << ' ' << s_instore [i]<< ' ' << s_sold [i] << ' ' << s_manprice [i]<< ' ' << s_selprice [ i ]<< endl ;
}
*/
for (int i = 0 ; i < s_names.size(); i++)
{
if (s_names [i].id != 0)
{
int idx = GetIDx (s_names [i].id);
if (idx < 0 )
{
cout << "Exception" << endl ;
return ;
}
cout << s_IDs [idx] << ' ' << s_names [i].size()<< ' ' << s_orders [idx] << ' ' << s_inStore [idx]<< ' ' << s_sold [idx] << ' ' << s_manPrice [idx]<< ' ' << s_selPrice [ idx ]<< endl ;
}
}
}
static void printing()
{
outputVectors();
cout << resetiosflags(ios_base::scientific);
cout << "Total inventory : " << setw(7) << setprecision(12) << right << TotalInv() << endl ;
}
// PrintVector (s_IDs) ;
// OutputLine (itemID, &itemName, nPiecesOrdered, fManPrice, fSelPrice) ;
//}
void sellItem()
{
string input, item;
int itemQty, iTag = -1;
bool orderComplete = false;
cout << "Thank you for your interest in our products." << endl << endl;
salesMenu();
cout << "What would you like to do?: ";
cin >> input;
while (input != "exit" && input != "back")
{
if (input == "view")
{
printf(" %-6s %-20s %s ", "ID", "NAME", "PRICE");
for (int i = 0; i < itemID.size(); i++)
{
printf("%-6s %-20s $%.2f ", itemID[i].c_str(), itemName[i].c_str(), sellingPrice[i]);
}
}
else if (input == "buy")
{
cout << "Enter the item number of the product you want to purchase, or type cancel: ";
cin >> item;
while (item != "cancel" && orderComplete != true)
{
for (int i = 0; i < itemID.size(); i++)
{
if (item == itemID[i])
iTag = i;
}
if (iTag != -1)
{
printf ("Enter the quantity of %s you wish to purchase: ", item.c_str());
cin >> itemQty;
if (itemQty > pInStore[iTag])
{
cout << "We do not have enough of this item to fill your order." << endl
cout << "The onhand quantity of the requested item is: " << pInStore[iTag] << endl << endl;
printf ("Enter the quantity of %s you wish to purchase: ", item.c_str());
cin >> itemQty;
}
else
{
cout << "Thank you for your purchase." << endl << endl;
cout << "Item: " << itemID[iTag] << endl;
cout << "Qty: " << itemQty << endl;
printf("Total Cost: $%.2f ", itemQty * sellingPrice[iTag]);
pInStore[iTag] = pInStore[iTag] - itemQty;
pSold[iTag] = pSold[iTag] + itemQty;
orderComplete = true;
}
}
else
{
cout << "Error: The Item number you have entered is invalid." << endl;
cout << "Enter the item number of the product you want to purchase, or type cancel: ";
cin >> item;
}
}
if (item == "cancel")
{
cout << "Order cancelled." << endl;
}
}
else if (input == "help")
{
salesMenu();
}
else if (input == "exit")
{
main();
}
else if (input == "menu")
{
}
else
{
cout << "Error: Invalid entry. Type 'help' for a list of available commands." << endl;
}
orderComplete = false;
cout << " What would you like to do?: ";
cin >> input;
}
}
void displayMenu()
{
char choice = 0;
cout << "[C]heck item (inventory)" << endl;
cout << "[S]ell item" << endl;
cout << "[P]rint report" << endl;
cout << "99: Exit" << endl;
cout << endl << endl;
cout << "Insert choice: ";
cin >> choice;
if (choice == 'c' || choice == 'C')
cout << "Check item choice" << endl;
else if (choice == 's' || choice == 'S')
sellItem();
else if (choice == 'p' || choice== 'P')
printing();
else
{
cout << "Wrong input" << endl;
}
}
static int GetIDx (int id )
{
for (int i = 0 ; i < s_IDs.size(); i++)
{
if (s_IDs [i] == id)
return i ;
}
return -1 ;
}
template <class T>
static void PrintVector (const std::vector <T> &vec)
{
typename std::vector<T>::const_iterator constIterator ;
for (constIterator = vec.begin();
constIterator != vec. end();
constIterator++)
{
cout << *constIterator << endl ;
}
}
static void OutputLine (int itemID, const string* itemName, int nPiecesOrdered, float fManPrice, float fSelPrice)
{
cout << left << setw (10) << itemID << setw (13) << itemName<< setw(7) << setprecision(2) << right << nPiecesOrdered<< fManPrice << fSelPrice << endl;
}
void salesMenu()
{
cout << "Available shopping commands:" << endl << endl;
cout << "view : Show a list of all items available." << endl;
cout << "buy : Buy an item." << endl;
cout << "help : View this help menu." << endl;
cout << "back : Go back to the main menu." << endl;
cout << "exit : Exit the program." << endl << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.