-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadsPRJ2-1.cpp
1223 lines (1076 loc) · 42.8 KB
/
adsPRJ2-1.cpp
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*Project 2 "ACME Flooring Company”
© Alicia D. St Clair Dec 12, 2019*/
#include "Project2_2019_Header.h";
ACME::ACME(char A, int room, double wdth, double lngth, string invld) //constructor
{
floor = A;
id = room;
width = wdth;
length = lngth;
type = invld;
Ccount++; //increment counter of complex objects
}
double ACME::area() //calculates the area of the selected room
{
double area = length * width;
return area; //return nothing
}
void ACME::numC() //counts the total number of rooms
{
cout << "There are " << Ccount << " rooms in this building.";
return; //return nothing
}
/*-----------------Friend Case Functions----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
vector<ACME> finput() //Part 1
{
vector<ACME>p(0);
string fstring; //floor string
string rstring; //room string
string wstring; //width string
string lstring; //length string
string type; //floor type string
string filename; //filename if file is in project
int room;
double width, length;
char floor;
ifstream inFile; //open a file stream for input
ofstream outFile; //open a file stream for output
cout << "Please enter a filename without its sufix '.txt': "; //user instructions
getline(cin, filename); //user input
filename += ".txt"; //open filename
inFile.open(filename.c_str()); //attempt to open the file file1_F19.txt
if (inFile.fail()) //check if the file failed to open
{
cout << "\nThe file could not be opened successfully." //user insructions if the file does not open
<< "\nPlease check that the file currently exists.\n";
system("pause"); //waits for user input
exit(1); //if file could not be opened, quit the program
}
cout << "The file has been successfully opened for reading.\n"; //user instructions if the program opens
while (!inFile.eof())
{
inFile >> fstring >> rstring >> wstring >> lstring >> type; //inputs strings
if (isvalidInt(rstring) && isvalidReal(wstring) && isvalidReal(lstring)) //checks for real or valid integrs
{
//convert these to int to double
floor = fstring.at(0);
room = atoi(rstring.c_str()); //converts an int to a string
width = atof(wstring.c_str()); //converts a double into a string
length = atof(lstring.c_str()); //converts a double into a string
p.push_back({ floor, room, width, length, type }); //adds the entered variables to the end of the file
rstring = "x";
}
}
ACME::numC(); //display total number of ACME objects
inFile.close(); //closes file
cin.ignore(); //ignores 'enter'
cout << endl << endl;
return p;
}
void update(vector<ACME>& up) //Part 2
{
int i; //counter variable
int r;
char flr;
int person, user; //user input
double width, length;
string type;
string option;
string select;
string rm;
string w;
string l;
do
{
do
{
cout << "Room Update Menu\n"
<< "Item 1: Display room information\n"
<< "Item 2: Change room specifications\n"
<< "Item 3: Quit modifications" << endl;
//enter the number but read it in as a string
cout << "Please enter an option: ";
getline(cin, option);
cout << endl;
if (isvalidInt(option))
{
//convert string to char array to int
person = atoi(option.c_str());
break; //escape loop if we have a valid awnser
}
else
{
cout << "The number you have entered is an invalid variable." //error message
<< "Please enter a number between 1-3." << endl;
}
} while (1);
//switch case for each option
switch (person)
{
case 1: //Display room info
cout << "What floor would you like to display?\n";
cin >> flr; //user input
cin.ignore();
//counts for every floor and room
for (i = 0; i < up.size(); i++)
{
if (up.at(i).floor == flr)
cout << up.at(i) << endl;
}
break;
case 2: //Change room specifications
/*-----------------Ask the user for a floor level-------------------------------------*/
cout << "Please enter a floor level: ";
cin >> flr;
cin.ignore();
//counts for every floor and room
for (i = 0; i < up.size(); i++)
{
if (up.at(i).floor == flr); //forces the program to close
}
cout << endl;
/*-----------------------Ask the user for a room number-----------------------------------*/
cout << "Please enter a room number 1-10: ";
getline(cin, rm);
cin.ignore();
if (!isvalidReal(rm))
{
cout << "The room number you entered in not a valid integer." << endl;
}
else
{
r = atoi(rm.c_str());
cout << "What would you like to change about the room:\n"
<< "Item 1: Width\n"
<< "Item 2: Length\n"
<< "Item 3: Flooring\n"
<< "Item 4: Quit Modifications" << endl;
//enter the number but read it in as a string
cout << "Please enter an option: ";
getline(cin, select);
cin.ignore();
cout << endl;
if (isvalidInt(select))
{
//convert string to char array to int
user = atoi(select.c_str());
//switch-case
switch (user)
{
case 1: //Width
cout << "What would you like the new width to be? ";
getline(cin, w);
width = atof(w.c_str());
cin.ignore();
for (i = 0; i < up.size(); i++)
{
if (up.at(i).floor == flr && up.at(i).id == r)
{
up.at(i).width = width;
}
}
break;
case 2: //Length
cout << "What would you like the new length to be? ";
getline(cin, l);
length = atof(l.c_str());
cin.ignore();
for (i = 0; i < up.size(); i++)
{
if (up.at(i).floor == flr && up.at(i).id == r)
{
up.at(i).length = length;
}
}
break;
case 3: //Flooring
cout << "What would you like the new flooring to be? ";
getline(cin, type);
cin.ignore();
for (i = 0; i < up.size(); i++)
{
if (up.at(i).floor == flr && up.at(i).id == r)
{
up.at(i).type = type;
}
}
break;
default: //Quit
break;
}
}
else
{
cout << "The number you have entered is an invalid variable." //error message
<< "Please enter a number between 1-4." << endl;
}
}
cout << endl;
break;
default: //Quit modifications
break;
}
} while (person != 3);
cout << endl << endl;
return; //return nothing
}
void stats(vector<ACME>& s) //Part 3
{
double max = 0; //maximum variable
double min = 10000; //minimun variable
int i; //counter
int CarpetTotal = 0; //total carpet variable
int TileTotal = 0; //total tile variable
int WoodTotal = 0; //total wood variable
double CarpetArea = 0; //total carpet area variable
double TileArea = 0; //total tile area variable
double WoodArea = 0; //total wood area variable
char pple; //user input
char umin; //user minimum input
char umax; //user maximum input
char in; //user input
string people; //user input string
string userMinimum; //user minimum input string
string userMaximum; //user maximum input string
string inuser; //user input string
do
{
cout << "What would you like to check?\n"
<< "1. Total Flooring Type\n"
<< "2. Minimum Room Size\n"
<< "3. Maximum Room Size\n"
<< "4. Average Room size\n"
<< "5. Quit" << endl;
getline(cin, people);
pple = atoi(people.c_str()); //converts an int to a string
cin.ignore();
switch (pple)
{
case 1:
//menu options
cout << "Which flooring type would you like to search for?\n"
<< "1. Carpet\n"
<< "2. Tile\n"
<< "3. Wood\n"
<< "4. Quit" << endl;
getline(cin, inuser);
in = atoi(inuser.c_str()); //converts an int to a string
cin.ignore();
switch (in)
{
case 1:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Carpet")
{
CarpetTotal++; //total wood rooms with carpet flooring
cout << "There are " << CarpetTotal << " rooms with carpet flooring";
cout << endl;
}
}
break;
case 2:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Tile")
{
TileTotal++; //total wood rooms with tile flooring
cout << "There are " << TileTotal << " rooms with tile flooring";
cout << endl;
}
}
break;
case 3:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Wood")
{
WoodTotal++; //total wood rooms with wood flooring
cout << "There are " << WoodTotal << " rooms with wood flooring";
cout << endl;
}
}
break;
default:
break;
}
case 2:
//menu options
cout << "Which flooring type would you like to find the minimum for?\n"
<< "1. Carpet\n"
<< "2. Tile\n"
<< "3. Wood\n"
<< "4. Quit" << endl;
getline(cin, userMinimum);
umin = atoi(userMinimum.c_str()); //sconverts an int into a string
cin.ignore();
switch (umin)
{
case 1:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Carpet" && s.at(i).area() < min)
min = s.at(i).area(); //finds min carpet room(s)
}
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Carpet" && s.at(i).area() == min)
cout << s.at(i).area() << endl; //finds matching min carpet room(s)
}
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Carpet" && s.at(i).area() == min)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with min carpet area
}
break;
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Carpet" && s.at(i).area() < min)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with min carpet area
}
break;
case 2:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Tile" && s.at(i).area() < min)
min = s.at(i).area(); //finds matching min tile room(s)
}
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Tile" && s.at(i).area() == min)
cout << s.at(i).area() << endl; //finds matching min tile room(s)
}
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Tile" && s.at(i).area() == min)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with min tile area
}
break;
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Tile" && s.at(i).area() < min)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with min tile area
}
break;
case 3:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Wood" && s.at(i).area() < min)
min = s.at(i).area(); //finds min carpet room(s)
}
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Wood" && s.at(i).area() == min)
cout << s.at(i).area() << endl; //finds matching min wood room(s)
}
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Wood" && s.at(i).area() == min)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with min wood area
}
break;
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Wood" && s.at(i).area() < min)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with min wood area
}
break;
default:
break;
}
case 3:
//menu options
cout << "Which flooring type would you like to find the maximum for?\n"
<< "1. Carpet\n"
<< "2. Tile\n"
<< "3. Wood\n"
<< "4. Quit" << endl;
getline(cin, userMaximum);
umax = atoi(userMaximum.c_str()); //converts an int into a string
cin.ignore();
switch (umax)
{
case 1:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Carpet" && s.at(i).area() > max)
max = s.at(i).area(); //finds max carpet room(s)
}
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Carpet" && s.at(i).area() == max)
cout << s.at(i).area() << endl; //finds matching max carpet room(s)
}
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Carpet" && s.at(i).area() == max)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with max carpet area
}
break;
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Carpet" && s.at(i).area() > max)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with max carpet area
}
break;
case 2:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Tile" && s.at(i).area() > max) //finds max tile room(s)
max = s.at(i).area();
}
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Tile" && s.at(i).area() == max)
cout << s.at(i).area() << endl; //finds matching max tile room(s)
}
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Tile" && s.at(i).area() == max)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with max tile area
}
break;
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Tile" && s.at(i).area() > max) //diplays room(s) and floor(s) with max tile area
cout << s.at(i) << endl;
}
break;
case 3:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Wood" && s.at(i).area() > max) //finds max wood room
max = s.at(i).area();
}
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Wood" && s.at(i).area() == max)
cout << s.at(i).area() << endl; //finds matching max wood room(s)
}
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Wood" && s.at(i).area() == max)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with max wood area
}
break;
//counts for every floor and room
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Wood" && s.at(i).area() > max)
cout << s.at(i) << endl; //diplays room(s) and floor(s) with max wood area
}
break;
default:
break;
}
case 4:
//menu options
cout << "Which flooring type would you like to solve for?\n"
<< "1. Carpet\n"
<< "2. Tile\n"
<< "3. Wood\n"
<< "4. Quit" << endl;
getline(cin, inuser); //user input
in = atoi(inuser.c_str()); //converts an int to a string
cin.ignore(); //ignore 'enter';
switch (in)
{
case 1:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Carpet")
{
CarpetTotal++; //total rooms with carpet flooring
CarpetArea += s.at(i).area(); //total carpet flooring area
cout << "The average area for the rooms with Carpet is: " << CarpetArea / CarpetTotal; //calculates the total average area
cout << endl;
}
}
break;
case 2:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Tile")
{
TileTotal++; //total rooms with tile flooring
TileArea += s.at(i).area(); //total tile flooring area
cout << "The average area for the rooms with Tile is: " << TileArea / TileTotal; //calculates the total average area
cout << endl;
}
}
break;
case 3:
for (i = 0; i < s.size(); i++)
{
if (s.at(i).type == "Wood")
{
WoodTotal++; //total rooms with wood flooring
WoodArea += s.at(i).area(); //total wood flooring area
cout << "The average area for the rooms with Wood is: " << WoodArea / WoodTotal; //calculates the total average area
cout << endl;
}
}
break;
default:
break;
}
default:
break;
}
} while (pple != 5);
return;
}
void floorplan(vector<ACME>& f) //Part 4
{
int i; //counter
//Carpet variables
double totalCarpetA = 0, totalCarpetB = 0, totalCarpetC = 0, totalCarpetD = 0, totalCarpetE = 0;
double totalCarpet = totalCarpetA + totalCarpetB + totalCarpetC + totalCarpetD + totalCarpetE;
double percentACarpet, percentBCarpet, percentCCarpet, percentDCarpet, percentECarpet; //total area of Carpet flooring in the building *10%
//Wood variables
double totalWoodA = 0, totalWoodB = 0, totalWoodC = 0, totalWoodD = 0, totalWoodE = 0;
double totalWood = totalWoodA + totalWoodB + totalWoodC + totalWoodD + totalWoodE;
double percentAWood, percentBWood, percentCWood, percentDWood, percentEWood; //total area of Wood flooring in the building *10%
//Tile variables
double totalTileA = 0, totalTileB = 0, totalTileC = 0, totalTileD = 0, totalTileE = 0;
double percentATile, percentBTile, percentCTile, percentDTile, percentETile; //total area of Tile flooring in the building *10%
double totalTile = totalTileA + totalTileB + totalTileC + totalTileD + totalTileE;
//Total area percent variables
double totalPercentCarpet, totalPercentWood, totalPercentTile; //total percent
/*-----------------------Total Carpet--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
for (i = 0; i < f.size(); i++) //Carpet 'A'
{
if (f.at(i).type == "Carpet" && f.at(i).floor == 'A')
{
totalCarpetA += f.at(i).area(); //calculates the total area of rooms with carpet on floor 'A'
}
percentACarpet = (totalCarpetA * 0.1) + totalCarpetA; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Carpet 'B'
{
if (f.at(i).type == "Carpet" && f.at(i).floor == 'B')
{
totalCarpetB += f.at(i).area(); //calculates the total area of rooms with carpet on floor 'B'
}
percentBCarpet = (totalCarpetB * 0.1) + totalCarpetB; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Carpet'C'
{
if (f.at(i).type == "Carpet" && f.at(i).floor == 'C')
{
totalCarpetC += f.at(i).area(); //calculates the total area of rooms with carpet on floor 'C'
}
percentCCarpet = (totalCarpetC * 0.1) + totalCarpetC; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Carpet 'D'
{
if (f.at(i).type == "Carpet" && f.at(i).floor == 'D')
{
totalCarpetD += f.at(i).area(); //calculates the total area of rooms with carpet on floor 'D'
}
percentDCarpet = (totalCarpetD * 0.1) + totalCarpetD; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) // Carpet 'E'
{
if (f.at(i).type == "Carpet" && f.at(i).floor == 'E')
{
totalCarpetE += f.at(i).area(); //calculates the total area of rooms with carpet on floor 'E'
}
percentECarpet = (totalCarpetE * 0.1) + totalCarpetE; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Total Carpet
{
if (f.at(i).type == "Carpet")
{
totalCarpet += f.at(i).area(); //calculates the total area of rooms with carpet
}
totalPercentCarpet = (totalCarpet * 0.1) + totalCarpet; //calcultes 10% of the total amount of tile
}
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/*---------------------Total Wood------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
for (i = 0; i < f.size(); i++) //Wood 'A'
{
if (f.at(i).type == "Wood" && f.at(i).floor == 'A')
{
totalWoodA += f.at(i).area(); //calculates the total area of rooms with wood on floor 'A'
}
percentAWood = (totalWoodA * 0.1) + totalWoodA; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Wood 'B'
{
if (f.at(i).type == "Wood" && f.at(i).floor == 'B')
{
totalWoodB += f.at(i).area(); //calculates the total area of rooms with wood on floor 'B'
}
percentBWood = (totalWoodB * 0.1) + totalWoodB; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Wood 'C'
{
if (f.at(i).type == "Wood" && f.at(i).floor == 'C')
{
totalWoodC += f.at(i).area(); //calculates the total area of rooms with wood on floor 'C'
}
percentCWood = (totalWoodC * 0.1) + totalWoodC; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Wood 'D'
{
if (f.at(i).type == "Wood" && f.at(i).floor == 'D')
{
totalWoodD += f.at(i).area(); //calculates the total area of rooms with wood on floor 'D'
}
percentDWood = (totalWoodD * 0.1) + totalWoodD; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Wood 'E'
{
if (f.at(i).type == "Wood" && f.at(i).floor == 'E')
{
totalWoodE += f.at(i).area(); //calculates the total area of rooms with wood on floor 'E'
}
percentEWood = (totalWoodE * 0.1) + totalWoodE; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Total Wood
{
if (f.at(i).type == "Wood")
{
totalWood += f.at(i).area(); //calculates the total area of rooms with wood
}
totalPercentWood = (totalWood * 0.1) + totalWood; //calcultes 10% of the total amount of tile
}
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/*---------------------Total Tile------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
for (i = 0; i < f.size(); i++) //Tile 'A'
{
if (f.at(i).type == "Tile" && f.at(i).floor == 'A')
{
totalTileA += f.at(i).area(); //calculates the total area of rooms with tile on floor 'A'
}
percentATile = (totalTileA * 0.1) + totalTileA; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //'Tile 'B'
{
if (f.at(i).type == "Tile" && f.at(i).floor == 'B')
{
totalTileB += f.at(i).area(); //calculates the total area of rooms with tile on floor 'B'
}
percentBTile = (totalTileB * 0.1) + totalTileB; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Tile 'C'
{
if (f.at(i).type == "Tile" && f.at(i).floor == 'C')
{
totalTileC += f.at(i).area(); //calculates the total area of rooms with tile on floor 'C'
}
percentCTile = (totalTileC * 0.1) + totalTileC; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Tile 'D'
{
if (f.at(i).type == "Tile" && f.at(i).floor == 'D')
{
totalTileD += f.at(i).area(); //calculates the total area of rooms with tile on floor 'D'
}
percentDTile = (totalTileD * 0.1) + totalTileD; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Tile 'E'
{
if (f.at(i).type == "Tile" && f.at(i).floor == 'E')
{
totalTileE += f.at(i).area(); //calculates the total area of rooms with tile on floor 'E'
}
percentETile = (totalTileE * 0.1) + totalTileE; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Total Tile
{
if (f.at(i).type == "Tile")
{
totalTile += f.at(i).area(); //calculates the total area of rooms with tile
}
totalPercentTile = (totalTile * 0.1) + totalTile; //calcultes 10% of the total amount of tile
}
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/*------------------------Table--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
cout << "Square Area in ft^2 by floor and floor type.\n\n"
<< "Floor Carpet (+10%) Wood (+10%) Tile (+10%)\n"
<< "----------------------------------------------------------------\n"
<< " A" << setw(10) << fixed << setprecision(0) << totalCarpetA << setw(10) << fixed << setprecision(0) << percentACarpet << setw(10) << fixed << setprecision(0) << totalWoodA << setw(10) << fixed << setprecision(0) << percentAWood << setw(10) << fixed << setprecision(0) << totalTileA << setw(10) << fixed << setprecision(0) << percentATile << "\n"
<< " B" << setw(10) << fixed << setprecision(0) << totalCarpetB << setw(10) << fixed << setprecision(0) << percentBCarpet << setw(10) << fixed << setprecision(0) << totalWoodB << setw(10) << fixed << setprecision(0) << percentBWood << setw(10) << fixed << setprecision(0) << totalTileB << setw(10) << fixed << setprecision(0) << percentBTile << "\n"
<< " C" << setw(10) << fixed << setprecision(0) << totalCarpetC << setw(10) << fixed << setprecision(0) << percentCCarpet << setw(10) << fixed << setprecision(0) << totalWoodC << setw(10) << fixed << setprecision(0) << percentCWood << setw(10) << fixed << setprecision(0) << totalTileC << setw(10) << fixed << setprecision(0) << percentCTile << "\n"
<< " D" << setw(10) << fixed << setprecision(0) << totalCarpetD << setw(10) << fixed << setprecision(0) << percentDCarpet << setw(10) << fixed << setprecision(0) << totalWoodD << setw(10) << fixed << setprecision(0) << percentDWood << setw(10) << fixed << setprecision(0) << totalTileD << setw(10) << fixed << setprecision(0) << percentDTile << "\n"
<< " E" << setw(10) << fixed << setprecision(0) << totalCarpetE << setw(10) << fixed << setprecision(0) << percentECarpet << setw(10) << fixed << setprecision(0) << totalWoodE << setw(10) << fixed << setprecision(0) << fixed << setprecision(0) << percentEWood << setw(10) << fixed << setprecision(0) << totalTileE << setw(10) << fixed << setprecision(0) << percentETile << "\n"
<< "----------------------------------------------------------------\n"
<< "Totals" << setw(7) << fixed << setprecision(0) << totalCarpet << setw(10) << fixed << setprecision(0) << totalPercentCarpet << setw(10) << fixed << setprecision(0) << totalWood << setw(10) << fixed << setprecision(0) << totalPercentWood << setw(10) << totalTile << setw(10) << fixed << setprecision(0) << totalPercentTile << endl << endl;
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
return;
}
void output(vector <ACME>& f) //Part 5
{
/*----------Part 4 variables---------------------------------------------------------------------------*/
int i; //counter
double totalCarpetA = 0, totalCarpetB = 0, totalCarpetC = 0, totalCarpetD = 0, totalCarpetE = 0;
double totalCarpet = totalCarpetA + totalCarpetB + totalCarpetC + totalCarpetD + totalCarpetE;
double percentACarpet, percentBCarpet, percentCCarpet, percentDCarpet, percentECarpet;
//Wood variables
double totalWoodA = 0, totalWoodB = 0, totalWoodC = 0, totalWoodD = 0, totalWoodE = 0;
double totalWood = totalWoodA + totalWoodB + totalWoodC + totalWoodD + totalWoodE;
double percentAWood, percentBWood, percentCWood, percentDWood, percentEWood;
//Tile variables
double totalTileA = 0, totalTileB = 0, totalTileC = 0, totalTileD = 0, totalTileE = 0;
double percentATile, percentBTile, percentCTile, percentDTile, percentETile;
double totalTile = totalTileA + totalTileB + totalTileC + totalTileD + totalTileE;
//Total area percent variables
double totalPercentCarpet, totalPercentWood, totalPercentTile;
/*-------------------------------------------------------------------------------------------------------*/
ifstream inFile; //input file stream
ofstream outFile; //output file stream
char response; //user input variable
string filename; //file name
cout << "Please enter a filename without including the .txt extension.\n";
getline (cin, filename);
filename += ".txt"; //open filename
cin.ignore(); //in case we need to use getline() later
inFile.open(filename.c_str()); //open file as input file to test
if (!inFile.fail()) //check if the file opened
{
cout << "A file by the name " << filename << " exists.\n\n"
<< "Do you want to continue and overwrite it "
<< "with the new data (y or n): " << endl;
cin >> response; //user input
cin.ignore(); //ignore rest of input buffer
if (tolower(response) != 'y') //if the user did not say yes
{
cout << "The existing file will not be overwritten.\n";
system("pause");
exit(1); //if file exists and user wants to keep
}
}
inFile.close(); //close the input stream
//end of input file section
//beginning of output file section
outFile.open(filename.c_str()); //open file for writing
if (outFile.fail()) //if the files could not be opened for writing
{
cout << "The file was not successfully opened for writing.\n";
system("pause");
exit(1); //if file was not opened, quit program
}
cout << "The file is ready for writing.\n"; //successfully opened
//Code Copied from Part 4
/*-----------------------Total Carpet--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
for (i = 0; i < f.size(); i++) //Carpet 'A'
{
if (f.at(i).type == "Carpet" && f.at(i).floor == 'A')
{
totalCarpetA += f.at(i).area(); //calculates the total area of rooms with carpet on floor 'A'
}
percentACarpet = (totalCarpetA * 0.1) + totalCarpetA; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Carpet 'B'
{
if (f.at(i).type == "Carpet" && f.at(i).floor == 'B')
{
totalCarpetB += f.at(i).area(); //calculates the total area of rooms with carpet on floor 'B'
}
percentBCarpet = (totalCarpetB * 0.1) + totalCarpetB; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Carpet'C'
{
if (f.at(i).type == "Carpet" && f.at(i).floor == 'C')
{
totalCarpetC += f.at(i).area(); //calculates the total area of rooms with carpet on floor 'C'
}
percentCCarpet = (totalCarpetC * 0.1) + totalCarpetC; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Carpet 'D'
{
if (f.at(i).type == "Carpet" && f.at(i).floor == 'D')
{
totalCarpetD += f.at(i).area(); //calculates the total area of rooms with carpet on floor 'D'
}
percentDCarpet = (totalCarpetD * 0.1) + totalCarpetD; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) // Carpet 'E'
{
if (f.at(i).type == "Carpet" && f.at(i).floor == 'E')
{
totalCarpetE += f.at(i).area(); //calculates the total area of rooms with carpet on floor 'E'
}
percentECarpet = (totalCarpetE * 0.1) + totalCarpetE; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Total Carpet
{
if (f.at(i).type == "Carpet")
{
totalCarpet += f.at(i).area(); //calculates the total area of rooms with carpet
}
totalPercentCarpet = (totalCarpet * 0.1) + totalCarpet; //calcultes 10% of the total amount of tile
}
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/*---------------------Total Wood------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
for (i = 0; i < f.size(); i++) //Wood 'A'
{
if (f.at(i).type == "Wood" && f.at(i).floor == 'A')
{
totalWoodA += f.at(i).area(); //calculates the total area of rooms with wood on floor 'A'
}
percentAWood = (totalWoodA * 0.1) + totalWoodA; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Wood 'B'
{
if (f.at(i).type == "Wood" && f.at(i).floor == 'B')
{
totalWoodB += f.at(i).area(); //calculates the total area of rooms with wood on floor 'B'
}
percentBWood = (totalWoodB * 0.1) + totalWoodB; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Wood 'C'
{
if (f.at(i).type == "Wood" && f.at(i).floor == 'C')
{
totalWoodC += f.at(i).area(); //calculates the total area of rooms with wood on floor 'C'
}
percentCWood = (totalWoodC * 0.1) + totalWoodC; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Wood 'D'
{
if (f.at(i).type == "Wood" && f.at(i).floor == 'D')
{
totalWoodD += f.at(i).area(); //calculates the total area of rooms with wood on floor 'D'
}
percentDWood = (totalWoodD * 0.1) + totalWoodD; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Wood 'E'
{
if (f.at(i).type == "Wood" && f.at(i).floor == 'E')
{
totalWoodE += f.at(i).area(); //calculates the total area of rooms with wood on floor 'E'
}
percentEWood = (totalWoodE * 0.1) + totalWoodE; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //Total Wood
{
if (f.at(i).type == "Wood")
{
totalWood += f.at(i).area(); //calculates the total area of rooms with wood
}
totalPercentWood = (totalWood * 0.1) + totalWood; //calcultes 10% of the total amount of tile
}
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
/*---------------------Total Tile------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
for (i = 0; i < f.size(); i++) //Tile 'A'
{
if (f.at(i).type == "Tile" && f.at(i).floor == 'A')
{
totalTileA += f.at(i).area(); //calculates the total area of rooms with tile on floor 'A'
}
percentATile = (totalTileA * 0.1) + totalTileA; //calcultes 10% of the total amount of tile
}
for (i = 0; i < f.size(); i++) //'Tile 'B'
{
if (f.at(i).type == "Tile" && f.at(i).floor == 'B')
{
totalTileB += f.at(i).area(); //calculates the total area of rooms with tile on floor 'B'
}
percentBTile = (totalTileB * 0.1) + totalTileB; //calcultes 10% of the total amount of tile
}