Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create three files to submit: ItemToPurchase.h - Class declaration ItemToPurchas

ID: 3717782 • Letter: C

Question

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. + means public and - means private:

ItemToPurchase

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

Note: For unit testing purposes, do not implement any input or output inside your set or get functions.

If you get a compilation error in a unit test, it is likely that the order of your parameters, the types of your parameters, or the name of your function does not match the specification. This includes the const keyword at the end of get functions.

in printItemCost(), print itemName itemQuantity @ $itemPrice = $itemPrice * itemQuantity

In main, prompt the user for two items and create two objects of the ItemToPurchase class. Use getline to input the item name so the user can input more than one word. Before prompting for the second item, call cin.ignore() to clear the newline before the next call to getline.

Call printItemCost() on each of the two items

At the top of main, type cout << fixed << setprecision(2) to display your doubles as money.

it keeps saying my stuff is not declared in the scope. Please help.

Add getPrice() * setQuantity from each item and output the total cost.

Explanation / Answer

ItemToPurchase.h

#ifndef ItemToPurchase_H_
#define ItemToPurchase_H_

#include <string>

using namespace std;

class ItemToPurchase {
private:
   string itemName;
   double itemPrice;
   int itemQuantity;
public:
   ItemToPurchase();
   void SetName(string name);
   void SetPrice(double price);
   void SetQuantity(int quantity);
   string GetName();
   double GetPrice();
   int GetQuantity();
};

#endif

ItemToPurchase.cpp

#include "ItemToPurchase.h"

ItemToPurchase::ItemToPurchase() {
   itemName = "none";
   itemPrice = 0.0;
   itemQuantity = 0;
}

void ItemToPurchase::SetName(string name) {
   itemName = name;
}

void ItemToPurchase::SetPrice(double price) {
   itemPrice = price;
}

void ItemToPurchase::SetQuantity(int quantity) {
   itemQuantity = quantity;
}

string ItemToPurchase::GetName() {
   return itemName;
}

double ItemToPurchase::GetPrice() {
   return itemPrice;
}

int ItemToPurchase::GetQuantity() {
   return itemQuantity;
}

source.cpp

#include <iostream>
#include "ItemToPurchase.h"
#include <cstdlib>

using namespace std;

int main() {
   ItemToPurchase item1, item2;
   string name;
   double price;
   int q;
   cout << "Item 1" << endl;
   cout << "Enter the item name: ";
   getline(cin, name);
   cout << "Enter the item price: ";
   cin >> price;
   cout << "Enter the item quantity: ";
   cin >> q;
   item1.SetName(name);
   item1.SetPrice(price);
   item1.SetQuantity(q);
  
   cout << " Item 2" << endl;
   cout << "Enter the item name: ";
   cin.ignore();
   getline(cin, name);
   cout << "Enter the item price: ";
   cin >> price;
   cout << "Enter the item quantity: ";
   cin >> q;
   item2.SetName(name);
   item2.SetPrice(price);
   item2.SetQuantity(q);
  
   cout << " TOTAL COST" << endl;
   cout << item1.GetName() << " " << item1.GetQuantity() << " @ $" << item1.GetPrice() << " = $" << item1.GetPrice() * item1.GetQuantity() << endl;
   cout << item2.GetName() << " " << item2.GetQuantity() << " @ $" << item2.GetPrice() << " = $" << item2.GetPrice() * item2.GetQuantity() << endl;
  
   cout << " Total: $" << (item1.GetPrice() * item1.GetQuantity()) + (item2.GetPrice() * item2.GetQuantity());
   return 0;
}