CIS170C WEEK 6 LAB-RETAIL ITEMS.docx

30 July, 2024 | 2 Min Read

CIS170C Lab Report Template

(1) Code

// —————————————————————

// Programming Assignment:

// Developer:

// Date Written: 12/04/2020

// Purpose: Retail Items

// —————————————————————

#include < string > class RetailItem

{ private:

std::string description; double price; int unitOnHand;

public:

RetailItem()

{ description = “<Empty Describtion>"; price = 0; unitOnHand = 0;

}

RetailItem(std::string desc, double cost, int qty)

{ description = desc; price = cost; unitOnHand = qty;

}

std::string getDescription() { return description; }

double getPrice() { return price; } int getUnits() { return unitOnHand; }

void SetDescribtion(std::string desc) { description = desc; } void SetPrice(double cost) { price = cost; } void SetUnits(int qty) { unitOnHand = qty; }

} ;

#include < iostream >

#include < string > #include < iomanip > using namespace std;

int main()

{

RetailItem Items[3];

cout << “Welcome to the Retail store!” << endl;

string newItem; double newPrice; int newQTY; double totalINV; do

{ cout << “Price must be greater than 0.” << endl; cout << “Please enter the price for item 1: $"; cin » newPrice;

}

while (newPrice < 1); do

{ cout << “Inventory must be greater than 0.” << endl; cout << “Please enter the units on hand for item 1: “; cin » newQTY;

}

while (newQTY < 1);

cout << “Please enter the description for item 1: “; cin » newItem;

Items[0].SetDescribtion(newItem);

Items[0].SetPrice(newPrice);

Items[0].SetUnits(newQTY);

Items[1].SetDescribtion(“Jeans”) ;

Items[1].SetPrice(34.95);

Items[1].SetUnits(40);

Items[2].SetDescribtion(“Long sleve shirt”) ;

Items[2].SetPrice(24.95); Items[2].SetUnits(20);

cout << “\n\nDisplay all items " << endl; for (int i = 0; i <= 2; i++)

{ cout << “Describtion: " << Items[i].getDescription() << endl; cout << “Unit on Hand: " << Items[i].getUnits() << endl; cout << “Price: $” << Items[i].getPrice() << endl; cout << “\n”;

}

totalINV = Items[0].getUnits() + Items[1].getUnits() + Items[2].getUnits(); cout << “Display the total inventory” << endl; cout << “The total invetory is " << totalINV << endl; system(“pause”) ;

}

(2) Screenshot

Powered by TCPDF (www.tcpdf.org)

Related posts