Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have whitespaces please help me fix. Code: ItemToPurchase.h #ifndef ITEMPURCHASEH #define ITEMPURCHASEH using namespace std; //class Declaration class ItemToPurchase { //declare private variables private:

image text in transcribed

I have whitespaces please help me fix.

Code:

ItemToPurchase.h

#ifndef ITEMPURCHASEH #define ITEMPURCHASEH using namespace std; //class Declaration class ItemToPurchase { //declare private variables private: string itemName; int itemPrice; int itemQuantity; //declare public methods public: //constructor ItemToPurchase(); //methods void SetName(string name); string GetName(); void SetPrice(int price); int GetPrice(); void SetQuantity(int quantity); int GetQuantity(); }; #endif

ItemToPurchase.cpp

#include #include "ItemToPurchase.h" using namespace std; //constructor definition ItemToPurchase::ItemToPurchase():itemName("none"),itemPrice(0),itemQuantity(0){} //method definitions void ItemToPurchase::SetName(string name) { itemName=name; } string ItemToPurchase::GetName() { return itemName; } void ItemToPurchase::SetPrice(int price) { itemPrice=price; } int ItemToPurchase::GetPrice() { return itemPrice; } void ItemToPurchase::SetQuantity(int quantity) { itemQuantity=quantity; } int ItemToPurchase::GetQuantity() { return itemQuantity; }

main.cpp

#include #include "ItemToPurchase.h" using namespace std;

int main() { //declare variables string name; int price; int quantity;

//create two objects of ItemToPurchase class ItemToPurchase item1, item2;

//get item1 details cout > price; cout > quantity;

//call methods and set variables values item1.SetName(name); item1.SetPrice(price); item1.SetQuantity(quantity); cin.ignore();

//get item2 details cout > price; cout > quantity;

//call methods and set variables values item2.SetName(name); item2.SetPrice(price); item2.SetQuantity(quantity);

cout

//calculate item1 and item2 COST int item1_cost = item1.GetQuantity() * item1.GetPrice(); int item2_cost = item2.GetQuantity() * item2.GetPrice();

//calculate total cost int total_cost = item1_cost + item2_cost;

//display item1 and item2 details cout

return 0; }

Enter the 1tem price: Enter the item quantity: Ites. 2 Inter the item name: Enter the item price: Enter the item quantity: TOTAL COST Chocolate Chipg 1 f $3=$3 Bottled Water 10 e $1=$10 Total: $13

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional IPhone And IPad Database Application Programming

Authors: Patrick Alessi

1st Edition

0470636173, 978-0470636176

More Books

Students also viewed these Databases questions

Question

Help Save & Exit Submit Multiple Choice $ 3 $ 6 $ 9 $ 1 0 $ 1 3

Answered: 1 week ago

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago