I have the first program completed not how request but it wo

I have the first program completed (not how request, but it works) and I am trying to get the second portion together.

First Program requested (complete)**********************************************

(1) Create three files to submit:

ItemToPurchase.h - Class declaration

ItemToPurchase.cpp - Class definition

main.cpp - main() function

Build the ItemToPurchase class with the following specifications:

Default constructor

Public class functions (mutators & accessors)

SetName() & GetName() (2 pts)

SetPrice() & GetPrice() (2 pts)

SetQuantity() & GetQuantity() (2 pts)

Private data members

string itemName - Initialized in default constructor to \"none\"

int itemPrice - Initialized in default constructor to 0

int itemQuantity - Initialized in default constructor to 0

(2) In main(), prompt the user for two items and create two objects of the ItemToPurchase class. Before prompting for the second item, call cin.ignore() to allow the user to input a new string. (2 pts)

Ex:


(3) Add the costs of the two items together and output the total cost. (2 pts)

Ex:

Second Portion I am on now*********************************************************************************

7.19 Program: Online shopping cart (continued) (C++)

This program extends the earlier \"Online shopping cart\" program. (Consider first saving your earlier program).

(1) Extend the ItemToPurchase class per the following specifications:

Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)

Public member functions

SetDescription() mutator & GetDescription() accessor (2 pts)

PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal

PrintItemDescription() - Outputs the item name and description

Private data members

string itemDescription - Initialized in default constructor to \"none\"

Ex. of PrintItemCost() output:


Ex. of PrintItemDescription() output:


(2) Create three new files:

ShoppingCart.h - Class declaration

ShoppingCart.cpp - Class definition

main.cpp - main() function (Note: main()\'s functionality differs from the warm up)

Build the ShoppingCart class with the following specifications. Note: Some can be function stubs (empty functions) initially, to be completed in later steps.

Default constructor

Parameterized constructor which takes the customer name and date as parameters (1 pt)

Private data members

string customerName - Initialized in default constructor to \"none\"

string currentDate - Initialized in default constructor to \"January 1, 2016\"

vector < ItemToPurchase > cartItems

Public member functions

GetCustomerName() accessor (1 pt)

GetDate() accessor (1 pt)

AddItem()

Adds an item to cartItems vector. Has parameter ItemToPurchase. Does not return anything.

RemoveItem()

Removes item from cartItems vector. Has a string (an item\'s name) parameter. Does not return anything.

If item name cannot be found, output this message: Item not found in cart. Nothing removed.

ModifyItem()

Modifies an item\'s description, price, and/or quantity. Has parameter ItemToPurchase. Does not return anything.

If item can be found (by name) in cart, check if parameter has default values for description, price, and quantity. If not, modify item in cart.

If item cannot be found (by name) in cart, output this message: Item not found in cart. Nothing modified.

GetNumItemsInCart() (2 pts)

Returns quantity of all items in cart. Has no parameters.

GetCostOfCart() (2 pts)

Determines and returns the total cost of items in cart. Has no parameters.

PrintTotal()

Outputs total of objects in cart.

If cart is empty, output this message: SHOPPING CART IS EMPTY

PrintDescriptions()

Outputs each item\'s description.


Ex. of PrintTotal() output:


Ex. of PrintDescriptions() output:


(3) In main(), prompt the user for a customer\'s name and today\'s date. Output the name and date. Create an object of type ShoppingCart. (1 pt)

Ex.


(4) Implement the PrintMenu() function. PrintMenu() has a ShoppingCart parameter, and outputs a menu of options to manipulate the shopping cart. Each option is represented by a single character. Build and output the menu within the function.

If the an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call PrintMenu() in the main() function. Continue to execute the menu until the user enters q to Quit. (3 pts)

Ex:


(5) Implement Output shopping cart menu option. (3 pts)

Ex:


(6) Implement Output item\'s description menu option. (2 pts)

Ex.


(7) Implement Add item to cart menu option. (3 pts)

Ex:


(8) Implement remove item menu option. (4 pts)

Ex:


(9) Implement Change item quantity menu option. Hint: Make new ItemToPurchase object and use ItemToPurchase modifiers before using ModifyItem() function. (5 pts)

Ex:

My Program to start second portion***********************************************************************************************

main.cpp**************************************************************************************

#include <iostream>

#include <string>

#include <vector>

using namespace std;

#include \"ItemToPurchase.h\"

#include \"ShoppingCart.h\"

void PrintMenu()

{

char userKey = \'?\';

cout << \"MENU\" << endl;

cout << \"a - Add item to cart\" << endl;

cout << \"d - Remove item from cart\" << endl;

cout << \"c - Change item quantity\" << endl;

cout << \"i - Output items\' descriptions\" << endl;

cout << \"o - Output shopping cart\" << endl;

cout << \"q - Quit\" << endl << endl;

while (userKey != \'q\')

{

cout << \"Choose an option: \";

cin >> userKey;

if (userKey == \'a\' || userKey == \'A\')

{

cout << \"A selected\" << endl;

}

else if (userKey == \'d\' || userKey == \'D\')

{

cout << \"D selected\" << endl;

}

else if (userKey == \'c\' || userKey == \'C\')

{

cout << \"C selected\" << endl;

}

else if (userKey == \'i\' || userKey == \'I\')

{

cout << \"I selected\" << endl;

}

else if (userKey == \'o\' || userKey == \'O\')

{

cout << \"O selected\" << endl;

}

else if (userKey == \'q\' || userKey == \'Q\')

{

cout << \"Q selected\" << endl;

userKey = \'q\';

}

else if (userKey != \'q\')

{

cout << \"Invalid Choice, please choose a valid option.\" << endl;

}

}

return;

}

int main()

{

// ShoppingCart cart;

string customerName, todaysDate;

cout << \"Enter Customer\'s Name: \";

getline(cin, customerName);

cout << endl << \"Enter Today\'s Date: \";

getline(cin, todaysDate);

cout << endl << \"Customer Name: \" << customerName << endl;

cout << \"Today\'s Date: \" << todaysDate << endl;

PrintMenu();

return 0;

}

ShoppingCart.h**************************************************************************************

#pragma once

#ifndef ShoppingCart_h

#define ShoppingCart_h

class ShoppingCart {

public:

ShoppingCart();

string GetCustomerName();// accessor(1 pt)

string GetDate();// accessor(1 pt)

void AddItem();// Adds an item to cartItems vector.Has parameter ItemToPurchase.Does not return anything.

void RemoveItem(); // Removes item from cartItems vector.Has a string(an item\'s name) parameter. Does not return anything.

//If item name cannot be found, output this message: Item not found in cart.Nothing removed.

void ModifyItem(); // Modifies an item\'s description, price, and/or quantity. Has parameter ItemToPurchase. Does not return anything.

//If item can be found(by name) in cart, check if parameter has default values for description, price, and quantity.If not, modify item in cart.

//If item cannot be found(by name) in cart, output this message : Item not found in cart.Nothing modified.

int GetNumItemsInCart(); //(2 pts) Returns quantity of all items in cart.Has no parameters.

int GetCostOfCart();// (2 pts) Determines and returns the total cost of items in cart.Has no parameters.

void PrintTotal(); // Outputs total of objects in cart.

//If cart is empty, output this message: SHOPPING CART IS EMPTY

void PrintDescriptions();// Outputs each item\'s description

private:

string customerName;

string currentDate;

vector <ShoppingCart> cartItems;

};

#endif

ShoppingCart.cpp**************************************************************************************

#include <iostream>

#include <string>

#include <vector>

#include \"ShoppingCart.h\"

using namespace std;

ShoppingCart::ShoppingCart() //default constructor

{

customerName = \"none\";

currentDate = \"January 1, 2016\";

return;

}

string ShoppingCart::GetCustomerName()

{

return customerName;

}

string ShoppingCart::GetDate()

{

return todaysDate;

}

void ShoppingCart::AddItem()// Adds an item to cartItems vector.Has parameter ItemToPurchase.Does not return anything.

{

return;

}

void ShoppingCart::RemoveItem()// Removes item from cartItems vector.Has a string(an item\'s name) parameter. Does not return anything.

{

//cout << \"Item not found in cart. Nothing removed.\" << endl;

return;

}

void ShoppingCart::ModifyItem() // Modifies an item\'s description, price, and/or quantity. Has parameter ItemToPurchase. Does not return anything. If item can be found(by name) in cart, check if parameter has default values for description, price, and quantity.If not, modify item in cart. If item cannot be found(by name) in cart, output this message : Item not found in cart.Nothing modified.

{

return;

}

int ShoppingCart::GetNumItemsInCart() //(2 pts) Returns quantity of all items in cart.Has no parameters.

{

return numItems;

}

int ShoppingCart::GetCostOfCart()// (2 pts) Determines and returns the total cost of items in cart.Has no parameters.

{

return costOfCart;

}

void ShoppingCart::PrintTotal() // Outputs total of objects in cart.

{

//cout << \"SHOPPING CART IS EMPTY\" << endl;

return;

}

void ShoppingCart::PrintDescriptions()// Outputs each item\'s description

{

// int i;

// i = 0;

// while (i < sizeofvector)

// {

//

// ++i;

// }

return;

}

ItemToPurchase.h**************************************************************************************

#pragma once

#ifndef ItemToPurchase_h

#define ItemToPurchase_h

class ItemToPurchase {

public:

ItemToPurchase();

string SetName(string resitemName);

string GetName(string resitemName);

int SetPrice(int resitemPrice);

int GetPrice(int resitemPrice);

int SetQuantity(int resitemQuantity);

int GetQuantity(int resitemQuantity);

void SetDescription();

void GetDescription();

void PrintItemCost();

void PrintItemDescription();

void PrintTotal();

void Reserve(string resitemName, int resitemPrice, int resitemQuantity);

void Print() const;

void testPrint();

private:

string itemName;

string itemDescription;

int itemPrice;

int itemQuantity;

int combinedTotal;

};

#endif

ItemToPurchase.cpp**************************************************************************************

#include <iostream>

#include <string>

#include <vector>

using namespace std;

#include \"ItemToPurchase.h\"

ItemToPurchase::ItemToPurchase() //default constructor

{

itemName = \"NoName\"; //default name

itemPrice = -1; //default price

itemQuantity = -1; //default qty

itemDescription = \"None\";

combinedTotal = 0; //default total

return;

}

string ItemToPurchase::SetName(string resitemName)

{

itemName = resitemName;

return itemName;

}

string ItemToPurchase::GetName(string resitemName)

{

itemName = resitemName;

return itemName;

}

int ItemToPurchase::SetPrice(int resitemPrice)

{

itemPrice = resitemPrice;

return itemPrice;

}

int ItemToPurchase::GetPrice(int resitemPrice)

{

itemPrice = resitemPrice;

return itemPrice;

}

int ItemToPurchase::SetQuantity(int resitemQuantity)

{

itemQuantity = resitemQuantity;

return itemQuantity;

}

int ItemToPurchase::GetQuantity(int resitemQuantity)

{

itemQuantity = resitemQuantity;

return itemQuantity;

}

void ItemToPurchase::SetDescription()

{

return;

}

void ItemToPurchase::GetDescription()

{

return;

}

void ItemToPurchase::PrintItemCost() //Outputs the item name followed by the quantity, price, and subtotal

{

return;

}

void ItemToPurchase::PrintItemDescription() //Outputs the item name and description

{

return;

}

//the below should have been through the above functions

void ItemToPurchase::Reserve(string resitemName, int resitemPrice, int resitemQuantity)

{

itemName = resitemName;

itemPrice = resitemPrice;

itemQuantity = resitemQuantity;

return;

}

void ItemToPurchase::Print() const

{

int unitTotal;

unitTotal = itemQuantity * itemPrice;

cout << itemName << \" \" << itemQuantity << \" @ $\" << itemPrice << \" = $\" << unitTotal << endl;

return;

}

void ItemToPurchase::PrintTotal()

{

cout << \"Total: $\" << combinedTotal << endl;

}

void ItemToPurchase::testPrint()

{

cout << itemName << endl << itemPrice << endl << itemQuantity << endl << endl;

return;

}

Solution

#include \"stdafx.h\"
#include \"ShopKeeper.h\"
#include \"Player.h\"

#include <iostream>


void PurchaseItem(Player& plyr)
{
  

int responce = 0;
std::cout << \"1: Mace - 30 gold. 2: Bow - 50 gold. 3: Boots - 10 gold. 4: Bearskin - 75 gold. 5: Helmet - 25 gold.\" << \"\ \";

do
{
std::cin >> responce;

switch (responce)
{
case 1:
plyr.AddItem(\"Mace\", 30);
break;

case 2:
plyr.AddItem(\"Bow\", 50);
break;

case 3:
plyr.AddItem(\"Boots\", 10);
break;

case 4:
plyr.AddItem(\"Bearskin\", 75);
break;

case 5:
plyr.AddItem(\"Helmet\", 25);
break;

default:
std::cout << \"Please enter valid data.\" << \"\ \";
std::cout << \"1: Mace - 30 gold. 2: Bow - 50 gold. 3: Boots - 10 gold. 4: Bearskin - 75 gold. 5: Helmet - 25 gold.\" << \"\ \";
}
} while (responce > 5 || responce < 1);

}

I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******
I have the first program completed (not how request, but it works) and I am trying to get the second portion together. First Program requested (complete)*******

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site