help with c++ program. i need to generate the last 4 digit of possible phone num
ID: 3676130 • Letter: H
Question
help with c++ program. i need to generate the last 4 digit of possible phone number.
heres the question
https://www.dropbox.com/s/ty40tvc2ht85yv7/c%2B%2B.PNG?dl=0
write a C++ program for one of the options below: Option #1: For a maximum score of 1 digit phone number from 713-000-0000 thro m score of 115 points, write a C++ program that will output EVERY 10 rom 713-000-0000 through 713-000-0998 to a file called output.txt. 15 point These phone numbers can only have an for every missing false p odd number of even digits. 1 point will be deducted valid phone n ositive is a phone number that should not be in the file. An example of this is a phone number that has an even number of even digts number that has an even number of even digits. The following is an example of what your file should look like: 713-808-980 713-909-eee2 713 808-9684 713-909-8806 13-08-8ee8 713-809-9011 ·[Several numbers are not shown here]Explanation / Answer
main.cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
// open file for output
freopen("output.txt", "w", stdout);
// this is fixed for the given range
// this contains total 4 even numbers
// problem requires odd number of even digits
// so for remaining three digits we should have
// eigther 1 or 3 even digits
const string prefixPhoneNumber = "713-000-0";
// try each number from 0 to 998
for (int i = 0; i <= 998; ++i) {
int num = i;
int evenCount = 0;
for (int j = 0; j < 3; ++j) {
// get the remainder and update num
int r = num % 10;
num /= 10;
// if even increase even count
if (r % 2 == 0) ++evenCount;
}
// check if satisfies condition
if (evenCount == 1 || evenCount == 3) {
cout << prefixPhoneNumber << setfill('0') << setw(3) << i << endl;
}
}
return 0;
}
output.txt
713-000-0000
713-000-0002
713-000-0004
713-000-0006
713-000-0008
713-000-0011
713-000-0013
713-000-0015
713-000-0017
713-000-0019
713-000-0020
713-000-0022
713-000-0024
713-000-0026
713-000-0028
713-000-0031
713-000-0033
713-000-0035
713-000-0037
713-000-0039
713-000-0040
713-000-0042
713-000-0044
713-000-0046
713-000-0048
713-000-0051
713-000-0053
713-000-0055
713-000-0057
713-000-0059
713-000-0060
713-000-0062
713-000-0064
713-000-0066
713-000-0068
713-000-0071
713-000-0073
713-000-0075
713-000-0077
713-000-0079
713-000-0080
713-000-0082
713-000-0084
713-000-0086
713-000-0088
713-000-0091
713-000-0093
713-000-0095
713-000-0097
713-000-0099
713-000-0101
713-000-0103
713-000-0105
713-000-0107
713-000-0109
713-000-0110
713-000-0112
713-000-0114
713-000-0116
713-000-0118
713-000-0121
713-000-0123
713-000-0125
713-000-0127
713-000-0129
713-000-0130
713-000-0132
713-000-0134
713-000-0136
713-000-0138
713-000-0141
713-000-0143
713-000-0145
713-000-0147
713-000-0149
713-000-0150
713-000-0152
713-000-0154
713-000-0156
713-000-0158
713-000-0161
713-000-0163
713-000-0165
713-000-0167
713-000-0169
713-000-0170
713-000-0172
713-000-0174
713-000-0176
713-000-0178
713-000-0181
713-000-0183
713-000-0185
713-000-0187
713-000-0189
713-000-0190
713-000-0192
713-000-0194
713-000-0196
713-000-0198
713-000-0200
713-000-0202
713-000-0204
713-000-0206
713-000-0208
713-000-0211
713-000-0213
713-000-0215
713-000-0217
713-000-0219
713-000-0220
713-000-0222
713-000-0224
713-000-0226
713-000-0228
713-000-0231
713-000-0233
713-000-0235
713-000-0237
713-000-0239
713-000-0240
713-000-0242
713-000-0244
713-000-0246
713-000-0248
713-000-0251
713-000-0253
713-000-0255
713-000-0257
713-000-0259
713-000-0260
713-000-0262
713-000-0264
713-000-0266
713-000-0268
713-000-0271
713-000-0273
713-000-0275
713-000-0277
713-000-0279
713-000-0280
713-000-0282
713-000-0284
713-000-0286
713-000-0288
713-000-0291
713-000-0293
713-000-0295
713-000-0297
713-000-0299
713-000-0301
713-000-0303
713-000-0305
713-000-0307
713-000-0309
713-000-0310
713-000-0312
713-000-0314
713-000-0316
713-000-0318
713-000-0321
713-000-0323
713-000-0325
713-000-0327
713-000-0329
713-000-0330
713-000-0332
713-000-0334
713-000-0336
713-000-0338
713-000-0341
713-000-0343
713-000-0345
713-000-0347
713-000-0349
713-000-0350
713-000-0352
713-000-0354
713-000-0356
713-000-0358
713-000-0361
713-000-0363
713-000-0365
713-000-0367
713-000-0369
713-000-0370
713-000-0372
713-000-0374
713-000-0376
713-000-0378
713-000-0381
713-000-0383
713-000-0385
713-000-0387
713-000-0389
713-000-0390
713-000-0392
713-000-0394
713-000-0396
713-000-0398
713-000-0400
713-000-0402
713-000-0404
713-000-0406
713-000-0408
713-000-0411
713-000-0413
713-000-0415
713-000-0417
713-000-0419
713-000-0420
713-000-0422
713-000-0424
713-000-0426
713-000-0428
713-000-0431
713-000-0433
713-000-0435
713-000-0437
713-000-0439
713-000-0440
713-000-0442
713-000-0444
713-000-0446
713-000-0448
713-000-0451
713-000-0453
713-000-0455
713-000-0457
713-000-0459
713-000-0460
713-000-0462
713-000-0464
713-000-0466
713-000-0468
713-000-0471
713-000-0473
713-000-0475
713-000-0477
713-000-0479
713-000-0480
713-000-0482
713-000-0484
713-000-0486
713-000-0488
713-000-0491
713-000-0493
713-000-0495
713-000-0497
713-000-0499
713-000-0501
713-000-0503
713-000-0505
713-000-0507
713-000-0509
713-000-0510
713-000-0512
713-000-0514
713-000-0516
713-000-0518
713-000-0521
713-000-0523
713-000-0525
713-000-0527
713-000-0529
713-000-0530
713-000-0532
713-000-0534
713-000-0536
713-000-0538
713-000-0541
713-000-0543
713-000-0545
713-000-0547
713-000-0549
713-000-0550
713-000-0552
713-000-0554
713-000-0556
713-000-0558
713-000-0561
713-000-0563
713-000-0565
713-000-0567
713-000-0569
713-000-0570
713-000-0572
713-000-0574
713-000-0576
713-000-0578
713-000-0581
713-000-0583
713-000-0585
713-000-0587
713-000-0589
713-000-0590
713-000-0592
713-000-0594
713-000-0596
713-000-0598
713-000-0600
713-000-0602
713-000-0604
713-000-0606
713-000-0608
713-000-0611
713-000-0613
713-000-0615
713-000-0617
713-000-0619
713-000-0620
713-000-0622
713-000-0624
713-000-0626
713-000-0628
713-000-0631
713-000-0633
713-000-0635
713-000-0637
713-000-0639
713-000-0640
713-000-0642
713-000-0644
713-000-0646
713-000-0648
713-000-0651
713-000-0653
713-000-0655
713-000-0657
713-000-0659
713-000-0660
713-000-0662
713-000-0664
713-000-0666
713-000-0668
713-000-0671
713-000-0673
713-000-0675
713-000-0677
713-000-0679
713-000-0680
713-000-0682
713-000-0684
713-000-0686
713-000-0688
713-000-0691
713-000-0693
713-000-0695
713-000-0697
713-000-0699
713-000-0701
713-000-0703
713-000-0705
713-000-0707
713-000-0709
713-000-0710
713-000-0712
713-000-0714
713-000-0716
713-000-0718
713-000-0721
713-000-0723
713-000-0725
713-000-0727
713-000-0729
713-000-0730
713-000-0732
713-000-0734
713-000-0736
713-000-0738
713-000-0741
713-000-0743
713-000-0745
713-000-0747
713-000-0749
713-000-0750
713-000-0752
713-000-0754
713-000-0756
713-000-0758
713-000-0761
713-000-0763
713-000-0765
713-000-0767
713-000-0769
713-000-0770
713-000-0772
713-000-0774
713-000-0776
713-000-0778
713-000-0781
713-000-0783
713-000-0785
713-000-0787
713-000-0789
713-000-0790
713-000-0792
713-000-0794
713-000-0796
713-000-0798
713-000-0800
713-000-0802
713-000-0804
713-000-0806
713-000-0808
713-000-0811
713-000-0813
713-000-0815
713-000-0817
713-000-0819
713-000-0820
713-000-0822
713-000-0824
713-000-0826
713-000-0828
713-000-0831
713-000-0833
713-000-0835
713-000-0837
713-000-0839
713-000-0840
713-000-0842
713-000-0844
713-000-0846
713-000-0848
713-000-0851
713-000-0853
713-000-0855
713-000-0857
713-000-0859
713-000-0860
713-000-0862
713-000-0864
713-000-0866
713-000-0868
713-000-0871
713-000-0873
713-000-0875
713-000-0877
713-000-0879
713-000-0880
713-000-0882
713-000-0884
713-000-0886
713-000-0888
713-000-0891
713-000-0893
713-000-0895
713-000-0897
713-000-0899
713-000-0901
713-000-0903
713-000-0905
713-000-0907
713-000-0909
713-000-0910
713-000-0912
713-000-0914
713-000-0916
713-000-0918
713-000-0921
713-000-0923
713-000-0925
713-000-0927
713-000-0929
713-000-0930
713-000-0932
713-000-0934
713-000-0936
713-000-0938
713-000-0941
713-000-0943
713-000-0945
713-000-0947
713-000-0949
713-000-0950
713-000-0952
713-000-0954
713-000-0956
713-000-0958
713-000-0961
713-000-0963
713-000-0965
713-000-0967
713-000-0969
713-000-0970
713-000-0972
713-000-0974
713-000-0976
713-000-0978
713-000-0981
713-000-0983
713-000-0985
713-000-0987
713-000-0989
713-000-0990
713-000-0992
713-000-0994
713-000-0996
713-000-0998
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.