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
|
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<cmath>
#include<math.h>
using namespace std;
void get_data(double& val1, double& val2, bool& error, ifstream&);
double convert_to_feet(double val);
int calculate_sheets(double& perimeter, int length);
void calculate_drywall(int& num_8ft, int& num_10ft,
int& num_12ft, int& num_14ft,
int& num_16ft, double& perimeter,
double& in_feet_width, double& in_feet_length,
int& tot8, int& tot10, int& tot12,
int& tot14, int& tot16);
void calculate_material(int& tot8, int& tot10, int& tot12,
int& tot14, int& tot16, int& cans_mud,
int& lbs_screws, int& num_5lb, int& num_25lb,
double& sqr_ft, int& tot_sheets,
double& totcost);
void print_output(double room_num, double in_feet_width,
double in_feet_length, bool error,
ofstream&, double perimeter,
double sqr_ft, int num_16ft, int num_14ft,
int num_12ft, int num_10ft, int num_8ft,
int tot16, double val1, double val2);
int main()
{
double val1, val2, room_num = 0, in_feet_width,
in_feet_length, perimeter = 0, sqr_ft = 0, totcost;
int num_8ft, num_10ft, num_12ft, num_14ft, num_16ft, tot8 = 0,
tot10 = 0, tot12 = 0, tot14 = 0, tot16 = 0, cans_mud,
lbs_screws, num_5lb = 0, num_25lb = 0, tot_sheets;
bool error;
string proj_title;
ifstream infile;
ofstream outfile;
infile.open("proj_info.txt");
outfile.open("supplies.txt");
getline(infile, proj_title);
outfile << "Project: " << proj_title << endl
<< setw(70) << right << "8' " << "10' "
<< "12' " << "14' " << "16' " << endl;
get_data(val1, val2, error, infile);
while (infile)
{
room_num++;
in_feet_width = convert_to_feet(val1);
in_feet_length = convert_to_feet(val2);
calculate_drywall(num_8ft, num_10ft, num_12ft, num_14ft,
num_16ft, perimeter, in_feet_width,
in_feet_length, tot8, tot10, tot12,
tot14, tot16);
tot8 += num_8ft;
tot10 += num_10ft;
tot12 += num_12ft;
tot14 += num_14ft;
tot16 += num_16ft;
calculate_material(tot8, tot10, tot12, tot14, tot16,
cans_mud, lbs_screws, num_5lb,
num_25lb, sqr_ft, tot_sheets, totcost);
print_output(room_num, in_feet_width, in_feet_length,
error, outfile, perimeter, sqr_ft,
num_16ft, num_14ft, num_12ft,
num_10ft, num_8ft, tot16, val1, val2);
get_data(val1, val2, error, infile);
}
outfile << "House Totals: " << setw(54) << right
<< tot8 << " " << tot10 << " " << tot12
<< " " << tot14 << " " << tot16 << endl
<< "Total Materials" << endl << endl
<< "Drywall Sheets " << tot_sheets << endl
<< "Drywall Square Feet " << sqr_ft << endl
<< "Drywall Screws " << num_25lb
<< " 25 lb Boxes" << endl << " "
<<num_5lb
<< " 5 lb Boxes" << endl
<< "Drywall Mud " << cans_mud
<< " Cans Mud" << endl << endl
<< "Total Cost: $" << totcost << endl;
}
void get_data(double& val1, double& val2, bool& error, ifstream& in)
{
in >> val1 >> val2;
if (val1 <= 0 || val2 <= 0)
error = 0;
else
error = 1;
}
double convert_to_feet(double val)
{
double in_feet;
in_feet = val * 3.28;
return in_feet;
}
int calculate_sheets(double& perimeter, int length)
{
int cnt = 0;
if (perimeter >= 16)
{
cnt = (int)((perimeter / 16) * 2);
perimeter -= (length * cnt);
}
return cnt;
}
void calculate_drywall(int& num_8ft, int& num_10ft,
int& num_12ft, int& num_14ft,
int& num_16ft, double& perimeter,
double& in_feet_width,
double& in_feet_length,
int& tot8, int& tot10, int& tot12,
int& tot14, int& tot16)
{
perimeter = 2 * (in_feet_width + in_feet_length);
num_16ft = calculate_sheets(perimeter, 16);
num_14ft = calculate_sheets(perimeter, 14);
num_12ft = calculate_sheets(perimeter, 12);
num_10ft = calculate_sheets(perimeter, 10);
num_8ft = calculate_sheets(perimeter, 8);
if (perimeter > 0)
num_8ft++;
}
void calculate_material(int& tot8, int& tot10, int& tot12,
int& tot14, int& tot16, int& cans_mud,
int& lbs_screws, int& num_5lb, int& num_25lb,
double& sqr_ft, int& tot_sheets,
double& totcost)
{
sqr_ft = (tot8 * (8 * 4)) + (tot10 * (10 * 4)) +
(tot12 * (12 * 4)) + (tot14 * (14 * 4)) +
(tot16 * (16 * 4));
cans_mud = ceil(sqr_ft / 350);
lbs_screws = ceil(sqr_ft / 185);
if (lbs_screws >= 25)
{
num_25lb = (lbs_screws / 25);
lbs_screws -= num_25lb;
}
else
num_5lb = (lbs_screws / 5);
tot_sheets = tot16 + tot14 + tot12 + tot10 + tot8;
totcost = (num_25lb * 50.00) + (num_5lb * 14.00) + (cans_mud * 13.50);
}
void print_output(double room_num, double in_feet_width,
double in_feet_length, bool error, ofstream& out,
double perimeter, double sqr_ft, int num_16ft,
int num_14ft, int num_12ft,
int num_10ft, int num_8ft, int tot16, double val1,
double val2)
{
out << "Room: " << setw(2) << right << room_num
<< setw(15) << right << in_feet_width
<< " ft by " << in_feet_length << " ft"
<< setw(30) << right << num_8ft << " "
<< num_10ft << " " << num_12ft << " "
<< num_14ft << " " << num_16ft << endl;
}
|