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
|
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class bench{
private:
vector<string> name;
vector<int> stock;
vector<int> order;
vector<int> day;
vector<int> month;
vector<int> year;
public:
// for testing
void AddOrder(string n, int s, int o, int d, int m, int y);
// method to test
// no need for const bench& ratula parameter?
void ShowWholeInformation();
};
void bench::AddOrder(string n, int s, int o, int d, int m, int y){
name.push_back(n);
stock.push_back(s);
order.push_back(o);
day.push_back(d);
month.push_back(m);
year.push_back(y);
}
// no need for const bench& ratula parameter?
void bench::ShowWholeInformation(){
// due to the way operator= works, you need to define
// and initialize all the iterator variable befor the
// for() loop begins.
vector<string>::iterator in = name.begin();
vector<int>::iterator is = stock.begin();
vector<int>::iterator io = order.begin();
vector<int>::iterator id = day.begin();
vector<int>::iterator im = month.begin();
vector<int>::iterator iy = year.begin();
// start off by initializing all iterators to begin()
// of corresponding vector
for( /*iterators already defined and initialized */ ;
// use && not , (comma) to check that none of
// iterators has reached the end of their array
in != name.end() && is != stock.end() && io !=order.end() &&
id != day.end() && im != month.end() && iy !=year.end();
// increment all iterators
++in,++is,++io, ++id, ++im, ++iy ){
// output basic info
cout<<*in;
cout<<" ";
cout<<*is;
cout<<" ";
cout<<*io;
cout<<" ";
// output date
cout<<*id;
cout<<"/";
cout<<*im;
cout<<"/";
cout<<*iy;
cout<<"\n";
}
}
int main()
{
bench b;
b.AddOrder("PCB185", 356, 152, 15, 5, 2015);
b.AddOrder("PCB124", 23, 56, 16, 5, 2015);
b.AddOrder("PCB500", 2265, 456, 16, 5, 2015);
b.AddOrder("PCB326", 456, 7, 17, 5, 2015);
b.AddOrder("PCB236", 99, 78, 18, 5, 2015);
b.ShowWholeInformation();
return 0;
}
|