RetailItem.cpp
RetailItem.h
/* RetailItem.h - Specification file for the RetailItem class. */
#ifndef RETAILITEM_H
#define RETAILITEM_H
#include <string>
using std::string;
class RetailItem
{
private:
string description; // The item description
int unitsOnHand; // The number of units at hand
double price; // The item cost
public:
// Constructor accepting arguments for each member variable
RetailItem(string descr, int units, double cost)
{
description = descr;
unitsOnHand = units;
price = cost;
}
// Mutators
void setDescription(string d)
{ description = d; }
void setUnitsOnHand(int u)
{ unitsOnHand = u; }
void setPrice(double c)
{ price = c; }
// Accessors
string getDescription() const
{ return description; }
int getUnitsOnHand() const
{ return unitsOnHand; }
double getPrice() const
{ return price; }
};
#endif
RetailItem.cpp
/* RetailItem.cpp - This program demonstrates the RetailItem class. */
#include "RetailItem.h"
#include <iomanip>
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::setw;
using std::setprecision;
using std::fixed;
void displayItems(RetailItem *, const int);
int main()
{
const int NUM_ITEMS = 3;
RetailItem items[NUM_ITEMS] = { { "Jacket", 12, 59.95 },
{ "Designer Jeans", 40, 34.95 },
{ "Shirt", 20, 24.95 } };
displayItems(items, NUM_ITEMS);
cin.get();
return 0;
}
/* **********************************************************
displayItems (accepts an array of RetailItem objects and
an integer value holding the number of items as arguments)
It displays information about the items.
********************************************************** */
void displayItems(RetailItem *items, const int NUM_ITEMS)
{
cout << "\nCYBER CITY NET-BATTLER FASHION STORE\n\n"
<< setw(29) << "Inventory Item"
<< setw(19) << "Units on Hand" << setw(16)
<< setw(13) << "Cost\n";
cout << "============================================================\n";
for (int i = 0; i < NUM_ITEMS; i++)
{
cout << "ITEM # " << (i + 1) << setw(21) << items[i].getDescription()
<< setw(19) << items[i].getUnitsOnHand()
<< setw(12) << items[i].getPrice() << "\n";
}
}
No comments:
Post a Comment