struct and arrays

when i run the program it only display the info of 8 subscriptions
then the program exit
I want to know how to use simple array to store 8 subscriptions and let user enter a new subscription. Can some one do some necessary changes

It does not allow user to enter new subscribers
It doesn't display mailing labels of all the expired subscriptions for the company to send out an
enticement to re-subscribe
It doesn't display mailing labels of all subscriptions due to expire in two months so the company can send out reminders to re-subscribe.

Since the id of subscriptions should be unique, you should keep track of ids used and then to increment it as you add a new subscription. That is, you do not need user to enter the id. The same for expiry, which you may assume annual subscription, so if the current date entered is 1712, you may use a formula to make the expiry to be 1812.

If your program assigns the subscription id instead of user input, you can safely use the getline() in the string library to read in the string values (refer to lecture slides if you are unsure) by asking the user to enter them in separate lines, then finally, you just need to use the familiar cin >> to capture the zip code. In this way, there's no need to use the cstring library.

As for the index of the Subscription array, you should keep track of the index already used, then you will know the next index to insert a new subscription. Note, you should use a function to hard-code the first 8 subscriptions in the array, then start with the index of 8 to enter a new subscription.
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
  #include <iostream>
#include <iomanip>
#include <string>
#include <vector>

using namespace std;

class Subscriber{
private:
    int subscriberNumber;
    string lastName;
    string firstName;
    string streetAddress;
    string city;
    string state;
    int zipcode;
    int expirationdate;

public:    
    Subscriber() : subscriberNumber(0),  zipcode(0),  expirationdate(0) {  }  
    
    Subscriber(int number, string last, string first, string address, 
               string cty, string st, int zip, int expdate) : 
        subscriberNumber(number), lastName(last), firstName(first), 
        streetAddress(address), city(cty), state(st), zipcode(zip), 
        expirationdate(expdate) {  }  
        
    void print() const;  
    
};

class SubscriberHandling {
private :
    int sub_id;
    int curDate;
    vector<Subscriber> subscribers;
public:
    SubscriberHandling(int date);
    void hardCode();
    void printAll();
    void addSubscriber();
    void expiredSubscriptions();
    void unexpiredSubscriptions();
    void subscriptionsInState(string state);
    void subscriptionExpiringInTwoMonths();
    void searchSubscriber(int num);
};

//driver function
int main()
{
    SubscriberHandling sh(2001);//set current date as 2001
    sh.printAll();
    sh.expiredSubscriptions();
    SubscriberHandling sh1(1712);
    sh1.unexpiredSubscriptions();
    sh.searchSubscriber(105);
    cin.get();//to hold the console screen
    return 0;
}

void Subscriber::print() const 
{
    cout << left << setw(19) << "Id:"         << subscriberNumber
         << setw(20) << "\nFirst name: "      << firstName
         << setw(20) << "\nLast name: "       << lastName
         << setw(20) << "\nStreet Address: "  << streetAddress
         << setw(20) << "\nCity: "            << city
         << setw(20) << "\nState: "           << state
         << setw(20) << "\nZip-code: "        << zipcode
         << setw(20) << "\nExpiration date: " << expirationdate
         << "\n\n" << right;
}


//parameterised constructor
SubscriberHandling::SubscriberHandling(int date)
{
    curDate=date;//set current date
    sub_id=101;//initial value of subscriber
    hardCode();
}

// hardcode method
void SubscriberHandling:: hardCode()
{
    // add the subscribers into the list
    subscribers.push_back( Subscriber(101, "Gray", "John", "233 Parkview Road", "Flushing", "Michigan", 47489, 1809) );
    subscribers.push_back( Subscriber(102, "Tang", "Charlotte", "303 E. Kearsley Street", "Flint", "Michigan", 48502, 1712) );
    subscribers.push_back( Subscriber(103, "Brown", "Coral", "8890 Holly Road", "Grand Blanc", "Michigan", 48439, 1709) );
    subscribers.push_back( Subscriber(104, "Arai", "Hugh", "77 Riverside Walk", "San Antonio", "Texas", 25786, 1805) );
    subscribers.push_back( Subscriber(105, "Blackett", "Kevin", "125 Picking Circle", "San Jose", "California", 60089, 1704) );
    subscribers.push_back( Subscriber(106, "Achtemichuk", "Mark", "3987 143 St", "Flint", "Michigan", 48503, 1810) );
    subscribers.push_back( Subscriber(107, "Browning", "William", "1 Down Street", "Washington", "D.C.", 24675, 1712) );
    subscribers.push_back( Subscriber(108, "Brown", "Maureen", "9066 Osoyoo Crescent", "New York City", "New York", 10021, 1802) );    
}

//add subscriber function
void SubscriberHandling::addSubscriber()
{
}

//expired subscriptions
void SubscriberHandling::expiredSubscriptions()
{
}

//subscriptionsexpiring in 2 months
void SubscriberHandling::subscriptionExpiringInTwoMonths()
{
}

//search for a subscriber using id
void SubscriberHandling::searchSubscriber(int num)
{
}

//subscriptions in a state
void SubscriberHandling::subscriptionsInState(string state)
{
}

//display subscriptions unexpired
void SubscriberHandling::unexpiredSubscriptions()
{
}

// Print All Subsribers 
void SubscriberHandling::printAll()
{
    for (const auto & s : subscribers)
        s.print();       
}
Last edited on
s = struct creates a scalar (1-by-1) structure with no fields. s = struct( field , value ) creates a structure array with the specified field and values. The value input argument can be any data type, such as a numeric, logical, character, or cell array. ... Each element of s contains the corresponding element of value .

Get to touch with the :- http://www.cetpainfotech.com/technology/c-language-training
Hello polip,

when i run the program it only display the info of 8 subscriptions
then the program exit
That is because all you have is eight elements in the vector to display.

I want to know how to use simple array to store 8 subscriptions and let user enter a new subscription.
You do not need an array you already have a vector for this. What you do not have is code, an add function, that will add to the vector.

1
2
3
4
It does not allow user to enter new subscribers
It doesn't display mailing labels of all the expired subscriptions for the company to send out an
enticement to re-subscribe
It doesn't display mailing labels of all subscriptions due to expire in two months so the company can send out reminders to re-subscribe.


Line 1. You have no function to add a new subscriber.

Line 2. You have no function or other code to do this.

Line 4. Same as line 2.

Since the id of subscriptions should be unique, you should keep track of ids used and then to increment it as you add a new subscription. That is, you do not need user to enter the id. The same for expiry, which you may assume annual subscription, so if the current date entered is 1712, you may use a formula to make the expiry to be 1812.
The ID can be retrieved from the last element in the vector or you could create a variable to hold the last ID used and increment this when you need a new ID. For the second part it should not be hard to code. I am not sure yet where it would go until I dig into the program more.

As for the index of the Subscription array, you should keep track of the index already used, then you will know the next index to insert a new subscription. Note, you should use a function to hard-code the first 8 subscriptions in the array, then start with the index of 8 to enter a new subscription.
Although a vector has a base based on an array it is not really considered an array. Keeping track of an index to know where to add to the vector is not necessary because you just add to the end unless you need to insert at a specific point. To use an array it would have to larger than you need then an "index" variable will be needed to keep track of where the last position is.

Hope that helps,

Andy
Below is my new program. Can some one help me to run this program and see if my new program satisfy all requirement. If not can someone fix it.
The program will allow users
• to enter new subscribers,
• to search and display subscriber information by subscriber number,
• to display all subscriptions in a particular state,
• to display mailing labels (as shown below) of all the unexpired subscriptions,
• to display mailing labels of all the expired subscriptions for the company to send out an
enticement to re-subscribe, and
• to display mailing labels of all subscriptions due to expire in two months so the company can
send out reminders to re-subscribe.

One more thing is I want to reduce the hard code part.
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
#include<iostream>

#include<string>

#include<vector>

using namespace std;

struct Subscriber{

public :

int subscriberNumber;

string lastName;

string firstName;

string streetAddress;

string city;

string state;

int zipcode;

int expirationdate;

};

struct SubscriberHandling{

private :

int sub_id;

int curDate;

vector<Subscriber> subscribers;

public:

SubscriberHandling(int date);

void hardCode();

void addSubscriber();

void expiredSubscriptions();

void unexpiredSubscriptions();

void subscriptionsInState(string state);

void subscriptionExpiringInTwoMonths();

void searchSubscriber(int num);

};


int main()

{

SubscriberHandling sh(2001);

sh.expiredSubscriptions();

SubscriberHandling sh1(1712);

sh1.unexpiredSubscriptions();

sh.searchSubscriber(105);

cin.get();//to hold the console screen

return 0;

}

//parameterised constructor

SubscriberHandling::SubscriberHandling(int date){

curDate=date;//set current date

sub_id=101;//initial value of subscriber

hardCode();

}

//hardcode method

void SubscriberHandling:: hardCode()

{
    Subscriber one;

one.subscriberNumber=sub_id;

sub_id++;

one.lastName="Gray";

one.firstName="John";

one.streetAddress="233 Parkview Road ";
one.city="Flushing";

one.state="Michigan";

one.zipcode=47489;

one.expirationdate=1809;

Subscriber two;

two.subscriberNumber=sub_id;

sub_id++;

two.lastName="Tang";

two.firstName="Charlotte";

two.streetAddress="303 E. Kearsley Street ";

two.city,"Flint";

two.state,"Michigan";

two.zipcode=48502;

two.expirationdate=1712;

Subscriber three;

three.subscriberNumber=sub_id;

sub_id++;

three.lastName="Brown";

three.firstName="Coral";

three.streetAddress="8890 Holly Road";
three.city="Grand Blanc";

three.state="Michigan";

three.zipcode=48439;

three.expirationdate=1709;

Subscriber four;

four.subscriberNumber=sub_id;

sub_id++;

four.lastName="Arai";

four.firstName="Hugh";

four.streetAddress="77 Riverside Walk ";

four.city="San Antonio";

four.state="Texas";

four.zipcode=25786;

four.expirationdate=1805;

Subscriber five;

five.subscriberNumber=sub_id;

sub_id++;

five.lastName="Blackett";

five.firstName="Kevin";

five.streetAddress="125 Picking Circle ";

five.city="San Jose";

five.state="California";

five.zipcode=60089;

five.expirationdate=1704;

Subscriber six;

six.subscriberNumber=sub_id;

sub_id++;

six.lastName="Achtemichuk";

six.firstName="Mark";

six.streetAddress="3987 143 St ";

six.city="Flint";

six.state="Michigan";

six.zipcode=48503;

six.expirationdate=1810;

Subscriber seven;

seven.subscriberNumber=sub_id;

sub_id++;

seven.lastName="Browning";

seven.firstName="William";

seven.streetAddress="1 Down Street ";

seven.city="Washington";

seven.state="D.C.";

seven.zipcode=24675;

seven.expirationdate=1712;

Subscriber eight;

eight.subscriberNumber=sub_id;

sub_id++;

eight.lastName="Brown";

eight.firstName="Maureen";

eight.streetAddress="9066 Osoyoo Crescent ";

eight.city="New York City";

eight.state="New York";

eight.zipcode=10021;

eight.expirationdate=180;

subscribers.push_back(one);

subscribers.push_back(two);

subscribers.push_back(three);

subscribers.push_back(four);

subscribers.push_back(five);

subscribers.push_back(six);

subscribers.push_back(seven);

subscribers.push_back(eight);

}

//expired subscriptions

void SubscriberHandling::expiredSubscriptions()

{



vector<Subscriber> :: iterator ite;//get an iterator of subscriber type

cout<<"\nThe expired subscriptions are :"<<endl;

//from begin to end of list

for(ite=subscribers.begin();ite!=subscribers.end();ite++)

{

if((*ite).expirationdate<=curDate)

{//found the subscriber

//print the info



cout<<"\nfirst name: "<<(*ite).firstName<<endl;

cout<<"last name: "<<(*ite).lastName<<endl;

cout<<"street Address: "<<(*ite).streetAddress<<endl;

cout<<"city: "<<(*ite).city<<endl;

cout<<"state: "<<(*ite).state<<endl;

cout<<"zip-code: "<<(*ite).zipcode<<endl;

cout<<"expiration date: "<<(*ite).expirationdate<<endl<<endl;



}

}

}

//subscriptionsexpiring in 2 months

void SubscriberHandling::subscriptionExpiringInTwoMonths()

{

vector<Subscriber> :: iterator ite;//get an iterator of subscriber type

cout<<"\nThe subscriptions expiring in 2 months are :"<<endl;

//from begin to end of list

for(ite=subscribers.begin();ite!=subscribers.end();ite++)

{

if((*ite).expirationdate-curDate<=2)

{//found the subscriber

//print the info



cout<<"\nfirst name: "<<(*ite).firstName<<endl;

cout<<"last name: "<<(*ite).lastName<<endl;

cout<<"street Address: "<<(*ite).streetAddress<<endl;

cout<<"city: "<<(*ite).city<<endl;

cout<<"state: "<<(*ite).state<<endl;

cout<<"zip-code: "<<(*ite).zipcode<<endl;

cout<<"expiration date: "<<(*ite).expirationdate<<endl<<endl;

}

}

}

//search for a subscriber using id

void SubscriberHandling::searchSubscriber(int num)

{

vector<Subscriber> :: iterator ite;//get an iterator of subscriber type

//from begin to end of list

for(ite=subscribers.begin();ite!=subscribers.end();ite++)

{

if((*ite).subscriberNumber==num)

{//found the subscriber

//print the info

cout<<"\nThe Subscriber with id "<<num<<" has information as follows :\n"<<endl;

cout<<"first name: "<<(*ite).firstName<<endl;

cout<<"last name: "<<(*ite).lastName<<endl;

cout<<"street Address: "<<(*ite).streetAddress<<endl;

cout<<"city: "<<(*ite).city<<endl;

cout<<"state: "<<(*ite).state<<endl;

cout<<"zip-code: "<<(*ite).zipcode<<endl;

cout<<"expiration date: "<<(*ite).expirationdate<<endl;

return;//return from the function

}

}

cout<<"No such subscriber with this ID exists"<<endl;//else there is not subscriber with id

}

//subscriptions in a state

void SubscriberHandling::subscriptionsInState(string state)

{

vector<Subscriber> :: iterator ite;//get an iterator of subscriber type

cout<<"\nThe subsribers in state "<<state<<" are :\n"<<endl;

//from begin to end of list

for(ite=subscribers.begin();ite!=subscribers.end();ite++)

{

if((*ite).state==state)

{//found the subscriber

//print the info

//cout<<"The Subscriber with id "<<num<<" has information as follows :"<<endl;

cout<<"\nfirst name: "<<(*ite).firstName<<endl;

cout<<"last name: "<<(*ite).lastName<<endl;

cout<<"street Address: "<<(*ite).streetAddress<<endl;

cout<<"city: "<<(*ite).city<<endl;

cout<<"state: "<<(*ite).state<<endl;

cout<<"zip-code: "<<(*ite).zipcode<<endl;

cout<<"expiration date: "<<(*ite).expirationdate<<endl<<endl;

}

}

}

//display subscriptions unexpired

void SubscriberHandling::unexpiredSubscriptions()

{

vector<Subscriber> :: iterator ite;//get an iterator of subscriber type

cout<<"\nThe Unexpired subscriptions are :"<<endl;

//from begin to end of list

for(ite=subscribers.begin();ite!=subscribers.end();ite++)

{

if((*ite).expirationdate>curDate)

{//found the subscriber

//print the info



cout<<"\nfirst name: "<<(*ite).firstName<<endl;

cout<<"last name: "<<(*ite).lastName<<endl;

cout<<"street Address: "<<(*ite).streetAddress<<endl;

cout<<"city: "<<(*ite).city<<endl;

cout<<"state: "<<(*ite).state<<endl;

cout<<"zip-code: "<<(*ite).zipcode<<endl;

cout<<"expiration date: "<<(*ite).expirationdate<<endl<<endl;

string x;

cout<<"Please enter a new subscriber:";

cin>>x;

string y;

cout<<"Please use the name using:";

cin>>y;

cout<<"This person is in our database.";
}

}

}
Last edited on
For what I can see you’re doing well by your own. You really don’t seem to need any help to finish your assignment.
Anyway, from my point of view, you could have kept two functions you dropped, Subscriber::Subscriber(<a lot of arguments>) and void Subscriber::print(). In my opinion, they help you write a simpler code.
Even about the “hardcode” method... to me, you’ve changed from a clearer one to a more obscure one. To what avail, if I may ask?

The only advice I think I could give is is to keep your syntax simple, if you can, i.e. avoid code such as “(*ite).” in favour of “ite->”.
I’d also try to shorten the class and function names, because the more you need to write and read, the more errors you can make.

This is how I could re-write your code, but that’s just a matter of personal preferences:
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;
}

Topic archived. No new replies allowed.