The Wall
October 18, 2011
We’ll write a simple dialog in Scheme, but you could make a fancy graphical iPad application if it would please you. Our main program is lengthy but straight forward, and uses a Lisp-style format
function that is non-standard but common among most Scheme implementations:
(define (wall)
(let* ((composition (get 'composition))
(wall-length (get 'wall-length))
(wall-height (get 'wall-height))
(wall-thick (get 'wall-thick))
(cubic-feet (* wall-length wall-height wall-thick))
(cube-cost (get 'cube-cost))
(materials (* cube-cost cubic-feet))
(crew-size (get 'crew-size))
(work-days (get 'work-days))
(day-hours (get 'day-hours))
(work-hours (* crew-size work-days day-hours))
(wage-rate (get 'wage-rate))
(total-wages (* work-hours wage-rate))
(fringe-pcnt (get 'fringe-pcnt))
(benefits (* total-wages fringe-pcnt 1/100))
(labor (+ total-wages benefits))
(total-cost (+ materials labor))
(margin (get 'margin))
(markup (* total-cost margin 1/100))
(bid-price (+ total-cost markup)))
(format #t "~%Bid for ~a wall~%~%" composition)
(format #t "Materials~%")
(format #t " Length in feet ~4d~%" wall-length)
(format #t " Height in feet ~4d~%" wall-height)
(format #t " Thickness in feet ~4d~%" wall-thick)
(format #t " -------~%")
(format #t " Total cubic feet ~4d~%" cubic-feet)
(format #t " Cost per cubic foot ~7,2f~%" cube-cost)
(format #t " -------~%")
(format #t " Total material cost ~7,2f~%~%" materials)
(format #t "Labor~%")
(format #t " Crew size ~4d~%" crew-size)
(format #t " Days worked ~4d~%" work-days)
(format #t " Hours per day ~4d~%" day-hours)
(format #t " -------~%")
(format #t " Total hours ~4d~%" work-hours)
(format #t " Wage rate per hour ~7,2f~%" wage-rate)
(format #t " -------~%")
(format #t " Total wages ~7,2f~%" total-wages)
(format #t " Fringe benefits ~7,2f~%" benefits)
(format #t " -------~%")
(format #t " Total labor cost ~7,2f~%" labor)
(format #t " -------~%")
(format #t "Total cost ~7,2f~%" total-cost)
(format #t "Markup ~7,2f~%" markup)
(format #t " -------~%")
(format #t "Bid price ~7,2f~%" bid-price)
(format #t " =======~%")))
An alternate design would let the user input the type of material and look up the price in some kind of database. Here is the code to get the input parameters from the user:
(define (get parm)
(display (case parm
((composition) "Enter type of wall in quotes (for instance, \"Lava Rock\" or \"Brick\")")
((wall-length) "Enter length of wall in whole feet (for instance, 20)")
((wall-height) "Enter height of wall in whole feet (for instance, 6)")
((wall-thick) "Enter thickness of wall in whole feet (for instance, 2)")
((cube-cost) "Enter cost per cubic foot in dollars (for instance, 3 or 2)")
((crew-size) "Enter number of workmen in crew (for instance, 2)")
((work-days) "Enter number of days worked (for instance, 3)")
((day-hours) "Enter number of hours per day (for instance, 8)")
((wage-rate) "Enter wage rate in dollars per hour (for instance, 10)")
((fringe-pcnt) "Enter benefits rate as a percent (for instance, 20)")
((margin) "Enter markup rate as a percent (for instance, 30)")
(else (error 'get "unrecognized parameter"))))
(display ": ") (read))
Here’s a sample dialog:
> (wall)
Enter type of wall in quotes (for instance, "Lava rock" or "Brick"): "Lava Rock"
Enter length of wall in whole feet (for instance, 20): 20
Enter height of wall in whole feet (for instance, 6): 6
Enter thickness of wall in whole feet (for instance, 2): 2
Enter cost per cubic foot in dollars (for instance, 3 or 2): 3
Enter number of workmen in crew (for instance, 2): 2
Enter number of days worked (for instance, 3): 3
Enter number of hours per day (for instance, 8): 8
Enter wage rate in dollars per hour (for instance, 10): 10
Enter benefits rate as a percent (for instance, 20): 20
Enter markup rate as a percent (for instance, 30): 30
Bid for Lava Rock wall
Materials
Length in feet 20
Height in feet 6
Thickness in feet 2
-------
Total cubic feet 240
Cost per cubic foot 3.00
-------
Total material cost 720.00
Labor
Crew size 2
Days worked 3
Hours per day 8
-------
Total hours 48
Wage rate per hour 10.00
-------
Total wages 480.00
Fringe benefits 96.00
-------
Total labor cost 576.00
-------
Total cost 1296.00
Markup 388.80
-------
Bid price 1684.80
=======
You can run this program at http://programmingpraxis.codepad.org/F8sO8tLO.
Here is my solution in C++, I’m a beginner so I’m sure there are plenty of mistakes, but pointers would help me out!
#include “stdafx.h”
#include
float MaterialCost(int x)
{
using namespace std;
//This switch compares the choice selected previously by the user and then
//returns the appropriate price
switch (x)
{
case 1:
return 2.0;
break;
case 2:
return 3.0;
break;
default:
cout << "Error, closing!";
cin.get();
cin.ignore();
exit (1);
}
}
int main()
{
using namespace std;
//Getting material of wall
cout << "What will this wall be made of? Make a selection from the list below:\n\n";
cout << "1. Brick\n";
cout <> nMaterialType;
//Setting cost per cubic foot of materials
float fMaterialCost;
fMaterialCost = MaterialCost(nMaterialType);
//Getting height of wall
cout <> fWallHeight;
//Getting length of wall
cout <> fWallLength;
//Getting Width of wall
cout <> fWallWidth;
//Setting total cubic feet of wall
float fCubicFeet;
fCubicFeet = fWallLength*fWallHeight*fWallWidth;
//Get crew number
cout <> nLaborers;
//Get crew wages per hour
cout <> fWagesPerHour;
//get fringe benifits
cout <> nFringeBenefits;
//get days project will take
cout <> nDays;
//Calculates desired profit margin
cout <> nProfitMargin;
//Calculate total worker cost by taking workers times days times wages then adding benefits on top
float fTotalWages =((nLaborers*fWagesPerHour)*((float).01*nFringeBenefits+1))*(nDays*8);
//Calculate total material cost
float fTotalMaterialCost=(fMaterialCost*fCubicFeet);
//Calculate final project cost plus profit margin
float fProjectCost=((fTotalMaterialCost+fTotalWages)*(nProfitMargin*(float).01+1));
cout << "######################################################\n";
cout << "#\t\t—–Bid for Wall—–\n";
cout << "# Materials:\t\t\t\t\t\n";
cout << "#\tLength in feet:\t\t\t$" << fWallLength << "\n";
cout << "#\tHeight in feet:\t\t\t$" << fWallHeight << "\n";
cout << "#\tWidth in feet:\t\t\t$" << fWallWidth << "\n";
cout << "#\tTotal cubic feet:\t\t$" << fCubicFeet << "\n";
cout << "#\tCost per cubic foot:\t\t$" << fMaterialCost << "\n";
cout << "#\tTotal:\t\t\t\t$" << fTotalMaterialCost << "\n";
cout << "#—————————————————–\n";
cout << "# Labor\n";
cout << "#\tCrew Size:\t\t\t$" << nLaborers << endl;
cout << "#\tDays Worked:\t\t\t$" << nDays << endl;
cout << "#\tCrew Wages Per Hour:\t\t$" << fWagesPerHour << endl;
cout << "#\tTotal Wages:\t\t\t$" << fTotalWages/((float).01*nFringeBenefits+1) << endl;
cout << "#\tFringe benefits:\t\t$" << fTotalWages-(nLaborers*fWagesPerHour) << endl;
cout << "#\tTotal Labor Cost:\t\t$" << fTotalWages << endl;
cout << "#—————————————————–\n";
cout << "# Totals:\n";
cout << "#\tTotal Cost:\t\t\t$" << fTotalMaterialCost+fTotalWages << endl;
cout << "#\tMarkup:\t\t\t\t$" << fProjectCost-(fTotalMaterialCost+fTotalWages) << endl;
cout << "#\n";
cout << "#\tBid Price:\t\t\t$" << fProjectCost << endl;
cout << "#—————————————————–\n";
cout << "######################################################";
cin.get();
cin.ignore();
return 0;
}
I can’t believe I “forgot” to read your blog considering that I found it three months earlier. Also busy with do the job I guess. Anyways I have it bookmarked now to become confident that I get notified as soon as you put some new content up.