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
|
#include <iostream>
#include <string>
#include <vector>
struct Subscriber {
int subscriberNumber;
std::string lastName;
std::string firstName;
std::string streetAddress;
std::string city;
std::string state;
int zipcode;
int expirationdate;
Subscriber(int number, std::string last,
std::string first, std::string address,
std::string cty, std::string st,
int zip, int expdate);
void print() const;
};
Subscriber::Subscriber(int number, std::string last,
std::string first, std::string address,
std::string cty, std::string st,
int zip, int expdate)
: subscriberNumber(number), lastName(last),
firstName(first), streetAddress(address),
city(cty), state(st),
zipcode(zip), expirationdate(expdate)
{}
void Subscriber::print() const
{
std::cout << "* " << firstName << ' ' << lastName
<< "\n " << streetAddress
<< "\n " << city << ' ' << state << ' ' << zipcode
<< "\n expiration date: " << expirationdate;
}
struct SubscriberHandling {
private :
int sub_id;
int curDate;
std::vector<Subscriber> subscribers;
public:
SubscriberHandling(int date);
void hardCode();
void addSubscriber();
void expiredSubscriptions();
void unexpiredSubscriptions();
void subscriptionsInState(std::string state);
void subscriptionExpiringInTwoMonths();
void searchSubscriber(int num);
void display(const Subscriber& sc) const;
};
//parametrised constructor
SubscriberHandling::SubscriberHandling(int date)
: sub_id { 101 }, curDate { date }
{
hardCode();
}
//hardcode method
void SubscriberHandling::hardCode()
{
subscribers.push_back( Subscriber(sub_id, "Gray", "John",
"233 Parkview Road", "Flushing", "Michigan",
47489, 1809) );
sub_id++;
subscribers.push_back( Subscriber(sub_id, "Tang", "Charlotte",
"303 E. Kearsley Street", "Flint", "Michigan",
48502, 1712) );
sub_id++;
subscribers.push_back( Subscriber(sub_id, "Brown", "Coral",
"8890 Holly Road", "Grand Blanc", "Michigan",
48439, 1709) );
sub_id++;
subscribers.push_back( Subscriber(sub_id, "Arai", "Hugh",
"77 Riverside Walk", "San Antonio", "Texas",
25786, 1805) );
sub_id++;
subscribers.push_back( Subscriber(sub_id, "Blackett", "Kevin",
"125 Picking Circle", "San Jose", "California",
60089, 1704) );
sub_id++;
subscribers.push_back( Subscriber(sub_id, "Achtemichuk", "Mark",
"3987 143 St", "Flint", "Michigan",
48503, 1810) );
sub_id++;
subscribers.push_back( Subscriber(sub_id, "Browning", "William",
"1 Down Street", "Washington", "D.C.",
24675, 1712) );
sub_id++;
subscribers.push_back( Subscriber(sub_id, "Brown", "Maureen",
"9066 Osoyoo Crescent", "New York City", "New York",
10021, 1802) );
sub_id++;
}
//expired subscriptions
void SubscriberHandling::expiredSubscriptions()
{
std::vector<Subscriber>::iterator ite;
std::cout << "\nThe expired subscriptions are:\n";
for(ite = subscribers.begin(); ite != subscribers.end(); ++ite)
{
if(ite->expirationdate <= curDate) { ite->print(); std::cout << '\n'; }
}
}
//subscriptions expiring in 2 months
void SubscriberHandling::subscriptionExpiringInTwoMonths()
{
std::vector<Subscriber>::iterator ite;
std::cout << "\nThe subscriptions expiring in 2 months are:\n";
for(ite = subscribers.begin(); ite != subscribers.end(); ite++)
{
if(ite->expirationdate - curDate <= 2) { ite->print(); std::cout << '\n'; }
}
}
//search for a subscriber using id
void SubscriberHandling::searchSubscriber(int num)
{
std::vector<Subscriber>::iterator ite;
for(ite = subscribers.begin(); ite != subscribers.end(); ite++)
{
if(ite->subscriberNumber == num)
{
std::cout << "\nThe Subscriber with id " << num
<< " has information as follows:\n";
ite->print();
std::cout << '\n';
return;
}
}
std::cout << "No such subscriber with this ID exists.\n";
}
//subscriptions in a state
void SubscriberHandling::subscriptionsInState(std::string state)
{
std::vector<Subscriber>::iterator ite;
std::cout << "\nThe subsribers in state " << state << " are:\n";
for(ite = subscribers.begin(); ite!= subscribers.end(); ++ite)
{
if(ite->state == state) { ite->print(); std::cout << '\n'; }
}
}
// display subscriptions unexpired
void SubscriberHandling::unexpiredSubscriptions()
{
std::vector<Subscriber>::iterator ite;
std::cout << "\nThe Unexpired subscriptions are:\n";
for(ite = subscribers.begin(); ite != subscribers.end(); ++ite)
{
if(ite->expirationdate > curDate) { ite->print(); std::cout << '\n'; }
}
}
int main()
{
SubscriberHandling sh(2001);
sh.expiredSubscriptions();
SubscriberHandling sh1(1712);
sh1.unexpiredSubscriptions();
sh.searchSubscriber(105);
std::cout << '\n';
std::cin.get(); // to hold the console screen
return 0;
}
|