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 it.
Presiding Officer Training module 2024 lok sabha elections
I have the first program completed (not how request, but it works) a.pdf
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)**********************************************
(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)
2. 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.
3. 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)
4. 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
#include
#include
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')
6. {
// 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.
7. 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 cartItems;
};
#endif
ShoppingCart.cpp***************************************************************
***********************
#include
#include
#include
#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
8. 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;
9. // }
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
11. 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;