30.1 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)

Respuesta :

Answer:

see explaination

Explanation:

#ifndef ITEMTOPURCHASE_H

#define ITEMTOPURCHASE_H

#include<iostream>

using namespace std;

class ItemToPurchase

{

public:

ItemToPurchase();

void setItemName(string name);

void setItemPrice(int itemPrice);

void setItemQuantity(int itemQuantity);

string getItemName();

int getItemPrice();

int getItemQuantity();

virtual ~ItemToPurchase();

protected:

private:

string itemName ;

int itemPrice;

int itemQuantity ;

};

#endif // ITEMTOPURCHASE_H

#include "ItemToPurchase.h"

ItemToPurchase::ItemToPurchase()

{

//ctor

this->itemName="none";

this->itemPrice=0;

this->itemQuantity=0;

}

void ItemToPurchase::setItemName(string name)

{

this->itemName=name;

}

void ItemToPurchase::setItemPrice(int itemPrice)

{

this->itemPrice=itemPrice;

}

void ItemToPurchase::setItemQuantity(int itemQuantity)

{

this->itemQuantity=itemQuantity;

}

string ItemToPurchase::getItemName()

{

return itemName;

}

int ItemToPurchase::getItemPrice()

{

return itemPrice;

}

int ItemToPurchase::getItemQuantity()

{

return itemQuantity;

}

ItemToPurchase::~ItemToPurchase()

{

//dtor

}

#include <iostream>

#include "ItemToPurchase.h"

using namespace std;

int main()

{

ItemToPurchase item1,item2;

string itemName ;

int itemPrice;

int itemQuantity ;

int totalCost=0;

cout<<"Item 1:"<<endl;

cout<<"Enter the item name : ";

getline(cin,itemName);

//cin.ignore();

cout<<"Enter the item price : ";

cin>>itemPrice;

cout<<"Enter the item quantity : ";

cin>>itemQuantity;

item1.setItemName(itemName);

item1.setItemPrice(itemPrice);

item1.setItemQuantity(itemQuantity);

cin.ignore();

cout<<"Item 2:"<<endl;

cout<<"Enter the item name : ";

getline(cin,itemName);

//cin.ignore();

cout<<"Enter the item price : ";

cin>>itemPrice;

cout<<"Enter the item quantity : ";

cin>>itemQuantity;

item2.setItemName(itemName);

item2.setItemPrice(itemPrice);

item2.setItemQuantity(itemQuantity);

cout<<"TOTAL COST : "<<endl;

cout<<item1.getItemName()<<" "<<item1.getItemQuantity()<<" at $"<<item1.getItemPrice()<<" = "<<(item1.getItemQuantity()*item1.getItemPrice())<<endl;

cout<<item2.getItemName()<<" "<<item2.getItemQuantity()<<" at $"<<item2.getItemPrice()<<" = "<<(item2.getItemQuantity()*item2.getItemPrice())<<endl;

totalCost=(item1.getItemQuantity()*item1.getItemPrice())+(item2.getItemQuantity()*item2.getItemPrice());

cout<<"Total : $"<<totalCost<<endl;

return 0;

}

Note: Replace at with the at symbol

See attachment for output

Ver imagen kendrich

In this exercise we have to use the knowledge of computational language in C code to describe a code, like this:

The code can be found in the attached image.

To make it easier the code can be found below as:

#ifndef ITEMTOPURCHASE_H

#define ITEMTOPURCHASE_H

#include<iostream>

using namespace std;

class ItemToPurchase

{

public:

ItemToPurchase();

void setItemName(string name);

void setItemPrice(int itemPrice);

void setItemQuantity(int itemQuantity);

string getItemName();

int getItemPrice();

int getItemQuantity();

virtual ~ItemToPurchase();

protected:

private:

string itemName ;

int itemPrice;

int itemQuantity ;

};

#endif // ITEMTOPURCHASE_H

#include "ItemToPurchase.h"

ItemToPurchase::ItemToPurchase()

{

this->itemName="none";

this->itemPrice=0;

this->itemQuantity=0;

}

void ItemToPurchase::setItemName(string name)

{

this->itemName=name;

}

void ItemToPurchase::setItemPrice(int itemPrice)

{

this->itemPrice=itemPrice;

}

void ItemToPurchase::setItemQuantity(int itemQuantity)

{

this->itemQuantity=itemQuantity;

}

string ItemToPurchase::getItemName()

{

return itemName;

}

int ItemToPurchase::getItemPrice()

{

return itemPrice;

}

int ItemToPurchase::getItemQuantity()

{

return itemQuantity;

}

ItemToPurchase::~ItemToPurchase()

{

}

#include <iostream>

#include "ItemToPurchase.h"

using namespace std;

int main()

{

ItemToPurchase item1,item2;

string itemName ;

int itemPrice;

int itemQuantity ;

int totalCost=0;

cout<<"Item 1:"<<endl;

cout<<"Enter the item name : ";

getline(cin,itemName);

//cin.ignore();

cout<<"Enter the item price : ";

cin>>itemPrice;

cout<<"Enter the item quantity : ";

cin>>itemQuantity;

item1.setItemName(itemName);

item1.setItemPrice(itemPrice);

item1.setItemQuantity(itemQuantity);

cin.ignore();

cout<<"Item 2:"<<endl;

cout<<"Enter the item name : ";

getline(cin,itemName);

//cin.ignore();

cout<<"Enter the item price : ";

cin>>itemPrice;

cout<<"Enter the item quantity : ";

cin>>itemQuantity;

item2.setItemName(itemName);

item2.setItemPrice(itemPrice);

item2.setItemQuantity(itemQuantity);

cout<<"TOTAL COST : "<<endl;

cout<<item1.getItemName()<<" "<<item1.getItemQuantity()<<" at $"<<item1.getItemPrice()<<" = "<<(item1.getItemQuantity()*item1.getItemPrice())<<endl;

cout<<item2.getItemName()<<" "<<item2.getItemQuantity()<<" at $"<<item2.getItemPrice()<<" = "<<(item2.getItemQuantity()*item2.getItemPrice())<<endl;

totalCost=(item1.getItemQuantity()*item1.getItemPrice())+(item2.getItemQuantity()*item2.getItemPrice());

cout<<"Total : $"<<totalCost<<endl;

return 0;

}

See more about C code at brainly.com/question/25870717

Ver imagen lhmarianateixeira
ACCESS MORE