-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsis112Lab1.cpp
More file actions
157 lines (120 loc) · 8.44 KB
/
Copy pathcsis112Lab1.cpp
File metadata and controls
157 lines (120 loc) · 8.44 KB
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
//Ceramic Tile -- calculate number of tiles necessary to tile a given size rectangular room
//CSIS 112-002
//<Sources if necessary>
//Include statements
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
//Global declarations: Constants and type definitions only -- NO variables
//Function prototypes
int CalculateTiles(int roomNum, int tileSize);
void CalculateBoxes(int totalTiles);
int InputFilter(bool& error, int filterOption = 1);
void BoolValChange(bool& var, bool value);
int main()
{
//In cout statement below substitute your name and lab number
cout << "Cody Moore -- Lab Number 1" << endl << endl;
//Variable declarations
int roomNum;
int tileSize;
int numTiles;
//Program logic
cout << "Welcome to the Ceramic Tile Planner. Please enter an integer. Decimals will be ignored and truncated."<< endl << endl;
cout << "Please enter the amount of rooms you would like to tile." << endl;
roomNum = InputFilter();
cout << "Please enter the size of a tile in square inches." << endl;
tileSize = InputFilter();
numTiles = CalculateTiles(roomNum, tileSize);
CalculateBoxes(numTiles);
//Closing program statements
system("pause");
return 0;
}
//Function definitions
int CalculateTiles(int roomNum, int tileSize)
{
double ftx;
double fty;
double inx;
double iny;
double magnitudex;
double magnitudey;
int tilesX;
int tilesY;
int amountTiles = 0;
int totalAmountTiles = 0;
bool inputError = false;
for (int i = 0; i < roomNum; i++)
{
tilesX = 0;
tilesY = 0;
cout << "Please enter the length of the room in feet and inches, separated by a space. (Example: 17 4)" << endl; // gets x size of room
do
{
ftx = InputFilter(inputError);
inx = InputFilter(inputError, 2);
} while (inputError);
cout << "Please enter the width of the room in feet and inches, separated by a space. (Example: 17 4)" << endl; // gets y size of room
do
{
ftx = InputFilter(inputError);
inx = InputFilter(inputError, 2);
} while (inputError);
magnitudex = (ftx * 12) + inx; // gets total size in inches for x and y
magnitudey = (fty * 12) + iny;
tilesX = ceil(magnitudex / tileSize); // must be ceil otherwise rounding will be off
tilesY = ceil(magnitudey / tileSize);
amountTiles = tilesX * tilesY; // finds total amount of tiles for the entire room, given the amount of tiles necessary for the x-axis and y-axis
totalAmountTiles += amountTiles;
cout << "Amount of tiles needed: " << amountTiles << endl;
}
cout << "Total amount of tiles needed: " << totalAmountTiles << endl;
return totalAmountTiles;
}
void CalculateBoxes(int totalTiles)
{
int numBoxes = ceil(totalTiles / 20.0);
cout << "The needed number of boxes is " << numBoxes << endl;
cout << "There are " << (numBoxes * 20) - totalTiles << " wasted tiles." << endl;
}
int InputFilter(bool& error, int filterOption)
{
double placeholder;
string filterStatement = "Your input must be a positive integer"; // custom error message
cin >> placeholder;
error = false;
// experiment getline to check whole given value for acceptability, remove double and float issue
switch (filterOption) // allows additional hints to user for input by allowing additional error statements or additional errors
{
case 1:
while (cin.fail() || placeholder < 0)
{
cout << filterStatement << "." << endl; // period allows additional statements to be added to error message before final printing
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin >> placeholder;
error = true;
}
break;
case 2:
filterStatement = "Your inches must be a positive integer and less than 12"; // this prompts the user to use a number less than 12, although this function does not cause the logic to loop if it is less than 12
while (cin.fail() || placeholder < 0 || placeholder >= 12)
{
cout << filterStatement << "." << endl;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin >> placeholder;
error = true;
}
break;
default:
break;
}
return floor(placeholder);
}
void BoolValChange(bool & var, bool value)
{
var = value;
}