Question

In: Computer Science

10.13 LAB*: Warm up: Online shopping cart (Part 1) (1) Create three files to submit: ItemToPurchase.h...

10.13 LAB*: Warm up: Online shopping cart (Part 1)

(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:

Item 1
Enter the item name:
Chocolate Chips
Enter the item price:
3
Enter the item quantity:
1

Item 2
Enter the item name:
Bottled Water
Enter the item price:
1
Enter the item quantity:
10


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

Ex:

TOTAL COST
Chocolate Chips 1 @ $3 = $3
Bottled Water 10 @ $1 = $10

Total: $13

code ---------------------------------------------------------

#include <iostream>
using namespace std;

#include "ItemToPurchase.h"

int main() {

/* Type your code here */

return 0;
}

Solutions

Expert Solution

output:

my code:

#include <iostream>
using namespace std;
/*Below make a class with a private member ,mutators & accessors*/
class ItemTOPurchase{
private:
/*Below we define 3 private member*/
string itemname;
int itemprice;
int itemQuantity;
public:
/*default constructor with value 0*/
ItemTOPurchase()
{
itemname=" ";
itemprice=0;
itemQuantity=0;
}
/*below we make 3 mutators functions for set the value of private member*/
void SetName(string n) /*this function is used for set itemname */
{
itemname=n;
}
void SetPrice(int p) /*this function is used for set itemprice */
{
itemprice=p;
}
void SetQuantity(int q) /*this function is used for set itemQuantity */
{
itemQuantity=q;
}
  
/*below we make 3 accessors functions for set the value of private member*/
string GetName() /*this function is used for get itemname */
{
return itemname;
}
int GetPrice() /*this function is used for get itemname */
{
return itemprice;
}
int GetQuantity() /*this function is used for get itemname */
{
return itemQuantity;
}
};


int main()
{   
ItemTOPurchase I1; /*make object for first item*/
ItemTOPurchase I2; /*make object for second item*/
string name;
int price;
int quantity;
cout<<"Item 1"<<endl<<"Enter the item name:"<<endl;
getline(cin, name); /*take item name input from user*/
cout<<"Enter the item price:"<<endl;
cin>>price; /*take item price input from user*/
cout<<"Enter the item quantity:"<<endl;
cin>>quantity; /*take item price input from user*/
I1.SetName(name); /*set item 1 name into object*/
I1.SetPrice(price); /*set item 1 price into object*/
I1.SetQuantity(quantity); /*set item 1 quantity into object*/
  
cin.ignore();
  
cout<<endl<<endl<<"Item 2"<<endl<<"Enter the item name:"<<endl;
getline(cin, name); /*take item name input from user*/
cout<<"Enter the item price:"<<endl;
cin>>price; /*take item price input from user*/
cout<<"Enter the item quantity:"<<endl;
cin>>quantity; /*take item price input from user*/
I2.SetName(name); /*set item 2 name into object*/
I2.SetPrice(price); /*set item 2 price into object*/
I2.SetQuantity(quantity); /*set item 2 quantity into object*/
  
  
/*here we print total cost we use of accessors of class*/
cout<<"TOTAl COST"<<endl;
cout<<I1.GetName()<<" "<<I1.GetQuantity() <<" @ " <<I1.GetPrice()<<" = "<<I1.GetPrice()*I1.GetQuantity()<<endl;
cout<<I2.GetName()<<" "<<I2.GetQuantity() <<" @ " <<I2.GetPrice()<<" = "<<I2.GetPrice()*I2.GetQuantity()<<endl;
return 0;
}


Related Solutions

HOMEWORK PROJECT #1 – SHOPPING CART Part I. Create two files to submit: ItemToPurchase.java – Class...
HOMEWORK PROJECT #1 – SHOPPING CART Part I. Create two files to submit: ItemToPurchase.java – Class Definition ShoppingCartPrinter.java – Contains main() method Build the ItemToPurchase class with the following specifications: Specifications Description ItemToPurchase(itemName) itemName – The name will be a String datatype and Initialized in default constructor to “none”. ItemToPurchase(itemPrice) itemPrice – The price will be integer datatype and Initialized in default constructor to 0. ItemToPurchase(itemQuantity) itemQuantity – The quantity will be integer datatype Initialized in default constructor to 0....
IN C++ 7.22 LAB*: Program: Online shopping cart (Part 2) This program extends the earlier "Online...
IN C++ 7.22 LAB*: Program: Online shopping cart (Part 2) 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...
9.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same...
9.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input. This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Private fields string itemDescription -...
5.9 Online shopping cart (Java) Create a program using classes that does the following in the...
5.9 Online shopping cart (Java) Create a program using classes that does the following in the zyLabs developer below. For this lab, you will be working with two different class files. To switch files, look for where it says "Current File" at the top of the developer window. Click the current file name, then select the file you need. (1) Create two files to submit: ItemToPurchase.java - Class definition ShoppingCartPrinter.java - Contains main() method Build the ItemToPurchase class with the...
7.7 Ch 7 Program: Online shopping cart (continued) (C) This program extends the earlier "Online shopping...
7.7 Ch 7 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 struct to contain a new data member. (2 pt) char itemDescription[ ] - set to "none" in MakeItemBlank() Implement the following related functions for the ItemToPurchase struct. PrintItemDescription() Has an ItemToPurchase parameter. Ex. of PrintItemDescription() output: Bottled Water: Deer Park, 12 oz. (2) Create three new files: ShoppingCart.h - struct definition and...
Create a Python 3 program that acts as a grocery store shopping cart. 1. Create a...
Create a Python 3 program that acts as a grocery store shopping cart. 1. Create a class named GroceryItem. This class should contain: - an __init__ method that initializes the item’s name and price - a get_name method that returns the item’s name - a get_price method that returns the item’s price - a __str__ method that returns a string representation of that GroceryItem - an unimplemented method is_perishable Save this class in GroceryItem.py. 2. Create a subclass Perishable that...
(1) Create three files to submit. ContactNode.h - Class declaration ContactNode.cpp - Class definition main.cpp -...
(1) Create three files to submit. ContactNode.h - Class declaration ContactNode.cpp - Class definition main.cpp - main() function (2) Build the ContactNode class per the following specifications: Parameterized constructor. Parameters are name followed by phone number. Public member functions InsertAfter() (2 pts) GetName() - Accessor (1 pt) GetPhoneNumber - Accessor (1 pt) GetNext() - Accessor (1 pt) PrintContactNode() Private data members string contactName string contactPhoneNum ContactNode* nextNodePtr Ex. of PrintContactNode() output: Name: Roxanne Hughes Phone number: 443-555-2864 (3) In main(),...
(1) Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchase.cpp - Class definition main.cpp -...
(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)...
This week you will write a program that mimics an online shopping cart . You will...
This week you will write a program that mimics an online shopping cart . You will use all the programming techniques we have learned thus far this semester, including if statements, loops, lists and functions. It should include all of the following: The basics - Add items to a cart until the user says "done" and then print out a list of items in the cart and a total price. - Ensure the user types in numbers for quantities -...
Casper Karts manufactures a three-wheeled shopping cart that sells for $60. Variable cost per shopping cart...
Casper Karts manufactures a three-wheeled shopping cart that sells for $60. Variable cost per shopping cart is $45. Annual fixed cost is $975,000. Casper Kart sold 80,000 shopping carts in this year. 1. Please use the format of a contribution margin income statement to calculate the contribution margin (in dollars), unit contribution, and contribution margin ratio for Casper Karts. You can refer to Example 1 in the textbook. 2. What will be the break-even point in units and in dollars...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT