|
| 1 | +#include "14.7.1winec.h" |
| 2 | +#include <iostream> |
| 3 | + |
| 4 | + |
| 5 | +Wine::Wine() |
| 6 | +{ |
| 7 | + label = ""; |
| 8 | + ArrayInt _yrs; |
| 9 | + ArrayInt _bot; |
| 10 | + yearBottles = PairArray(_yrs, _bot); |
| 11 | + years = 0; |
| 12 | +} |
| 13 | + |
| 14 | + |
| 15 | +Wine::Wine(const char * l, int y, const int yr[], const int bot[]) |
| 16 | +{ |
| 17 | + label = std::string(l, l + strlen(l)); |
| 18 | + years = y; |
| 19 | + ArrayInt _yrs(yr, y); |
| 20 | + ArrayInt _bot(bot, y); |
| 21 | + yearBottles = PairArray(_yrs, _bot); |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +Wine::Wine(const char * l, int y) |
| 26 | +{ |
| 27 | + label = std::string(l, l + strlen(l)); |
| 28 | + years = y; |
| 29 | + ArrayInt _yrs; |
| 30 | + ArrayInt _bot; |
| 31 | + yearBottles = PairArray(_yrs, _bot); |
| 32 | +} |
| 33 | + |
| 34 | +void Wine::GetBottles() |
| 35 | +{ |
| 36 | + std::cout << "Enter " << label << " data for " << years << " year(s):" << std::endl; |
| 37 | + int index = 0; |
| 38 | + int _yearArr[years]; |
| 39 | + int _bottlesArr[years]; |
| 40 | + |
| 41 | + while(index < years) |
| 42 | + { |
| 43 | + std::cout << "Enter year: "; |
| 44 | + int _tempYr; |
| 45 | + std::cin >> _tempYr; |
| 46 | + _yearArr[index] = _tempYr; |
| 47 | + |
| 48 | + std::cout << "Enter bottles for that year: "; |
| 49 | + int _tempBt; |
| 50 | + std::cin >> _tempBt; |
| 51 | + _bottlesArr[index] = _tempBt; |
| 52 | + index++; |
| 53 | + } |
| 54 | + |
| 55 | + ArrayInt _years(_yearArr, years); |
| 56 | + ArrayInt _bottles(_bottlesArr, years); |
| 57 | + |
| 58 | + yearBottles = PairArray(_years, _bottles); |
| 59 | + |
| 60 | +} |
| 61 | + |
| 62 | + |
| 63 | +void Wine::Show() |
| 64 | +{ |
| 65 | + std::cout << "Wine: " << label << std::endl; |
| 66 | + std::cout.width(10); |
| 67 | + std::cout << "Year"; |
| 68 | + std::cout.width(10); |
| 69 | + std::cout << "Bottles" << std::endl; |
| 70 | + for(int i = 0; i < years; i++) |
| 71 | + { |
| 72 | + std::cout.width(10); |
| 73 | + std::cout << yearBottles.first()[i]; |
| 74 | + std::cout.width(10); |
| 75 | + std::cout << yearBottles.second()[i]<< std::endl; |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +std::string & Wine::Label() |
| 80 | +{ |
| 81 | + return label; |
| 82 | +} |
| 83 | + |
| 84 | + |
| 85 | +int Wine::sum() |
| 86 | +{ |
| 87 | + int sum = 0; |
| 88 | + for(int i = 0; i < years; i++) |
| 89 | + { |
| 90 | + sum += yearBottles.second()[i]; |
| 91 | + } |
| 92 | + |
| 93 | + return sum; |
| 94 | +} |
0 commit comments