1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
#include <iostream>
#include <string>
#include <vector>
//using namespace std;
using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;
class Items
{
public:
//default constructor
Items();
//member function declarations
string getName();
void setName (string name);
int getNumber ();
void setNumber (int number);
string getUnits ();
void setUnits(string units);
double getPrice();
void setPrice (double price);
protected:
//private:
//variables (name, number, units, unit price)
string name;
int number;
string units;
double price;
};
class List
/*
: public Items
store item objects on the list object, add an item, remove an item
provide 10% club card discount
as item objects are created they need to be stored as list objects
*/
{
public:
//default constructor
List();
void addListitem(vector<List>& p)
{
//function is to take item, number, units, and price, populate them to
//a temp, then push them into the vector
int pIndex = 0;
double cost;
string package;
int quantity;
string thing;
//getName()
//{
thing = name;
//}
//getNumber()
//{
quantity = number;
//}
//getUnits()
//{
package = units;
//}
//Items.getPrice()
//{
cost = price;
//}
List pTemp(thing, quantity, package, cost);
//(item,number,units,price);
p.push_back(pTemp);
pIndex++;
}
private:
string name;
int number;
string units;
double price;
protected:
};
List::List()
{
cout << " I have been constructed";
/*
void addListitem(vector<List>& p)
{
//function is to take item, number, units, and price, populate them to
//a temp, then push them into the vector
int pIndex = 0;
double cost;
string package;
int quantity;
string thing;
List pTemp(thing,quantity,package,cost);
p.push_back(pTemp);
pIndex++;
}
*/
}
int main()
{
vector <Items> p;
char input;
cout << " You must input the item, number to buy, units it " << endl;
cout << " comes in, and the cost per unit" << endl;
cout << endl;
do
{
string n;
cout << " What item would you like to place on the list? " << endl;
cin >> n;
int k;
cout << " How many " << n << " would you like to buy? " << endl;
cin >> k;
string m;
cout << " What units do the " << n << " come in? " << endl;
cin >> m;
double v;
cout << " What is the price per " << m << " of " << n << "?" << endl;
cin >> v;
cout << endl;
cout << "ITEM: " << "NUMBER: " << "UNITS: " << "PRICE: " << endl;
cout << endl;
//constructors...
Items Items;
Items.setName (n);
Items.setNumber (k);
Items.setUnits (m);
Items.setPrice (v);
cout << endl;
cout << " type y to continue making the list, and add another item" << endl;
cout << "type any other character to move along without adding another item" << endl;
cin >> input;
cout << endl;
List List;
Items.getName();
Items.getNumber();
Items.getUnits();
Items.getPrice();
}
while (input == 'y' || input == 'Y');
cout << endl << endl;
cin.ignore();
cin.get();
return 0;
}
//create object
Items::Items()
{
}
//member functions (accessors and mutators)
string Items::getName()
{
return name;
}
void Items::setName(string i)
{
name = i;
cout << " " << name;
}
int Items::getNumber()
{
return number;
}
void Items::setNumber(int a)
{
number = a;
cout << " " << number << " ";
}
string Items::getUnits()
{
return units;
}
void Items::setUnits(string b)
{
units = b;
cout << " " << units << " ";
}
double Items::getPrice()
{
return price;
}
void Items::setPrice(double c)
{
price = c;
cout << " " << price << endl;
}
|