1. Engineering
  2. Computer Science
  3. the maincpp file i have to use is below i...

Question: the maincpp file i have to use is below i...

Question details

20.18 Ch 7 Warm up: Online shopping cart (C++) Instructor note: For this lab, you only need to complete the ItemToPurchase.h and ItemToPurchase.cpp files. The main.cpp file has been provided for you, and can not be changed. (1) Create three files to submit Item ToPurchase.h - Class declaration ItemToPurchase.cpp - Class definition main.cpp -main0 function Build the ItemToPurchase class with the following specifications: Default constructor . Public class functions (mutators & accessors) SetName0 & GetName0 (2 pts) . SetPrice0 & GetPrice (2 pts) . SetQuantity0 & GetQuantity0 (2 pts) Private data members string itemName Initialized in default constructor to none int itemPrice Initialized in default constructor to 0 int itemOuantity- Initialized in default constructor to 0 (2) In main0, prompt the user for two items and create two objects of the ltemToPurchase class. Before prompting for the second item, call cin.ignore0 to allow the user to input a new string. (2 pts) Ex: Item 1 Enter the item name: Chocolate Chips Enter the item price: Enter the item quantity: Item 2 Enter the item name Bottled Water Enter the item price: Enter the item quantity: 10 ence Il for Majors home> 20.18: Ch 7 Warm up: Online shopping cart (C++) TOTAL COST Chocolate Chips 1 $3-3 Bottled Water 10 $1 $10 Total: $13

The main.cpp file I have to use is below, I just need ItemToPurchase.cpp and ItemToPurchase.h

#include
#include
using namespace std;

#include "ItemToPurchase.h"

using namespace std;


int main() {
   int i;
   const int NUM_ITEMS = 2;
   string name;
   int price;
   int quantity;
   double total;
   ItemToPurchase item1;
   ItemToPurchase item2;

   for (i = 0; i < NUM_ITEMS; ++i) {
     cout << "Item " << i + 1 << endl;
     cout << "Enter the item name:" << endl;
     getline(cin, name);
   
     cout << "Enter the item price:" << endl;
     cin >> price;
   
     cout << "Enter the item quantity:" << endl;
     cin >> quantity;
     cout << endl;
   
     if (i == 0) {
       item1.SetName(name);
       item1.SetPrice(price);
       item1.SetQuantity(quantity);
     }
   
     else if (i == 1) {
       item2.SetName(name);
       item2.SetPrice(price);
       item2.SetQuantity(quantity);
     }
   
     cin.ignore();
   }

   total = (item1.GetPrice() * item1.GetQuantity()) +
       (item2.GetPrice() * item2.GetQuantity());
        
   cout << "TOTAL COST" << endl;
   item1.Print();
   item2.Print();
   cout << endl;
   cout << "Total: $" << total << endl;
    

   return 0;
}

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution