Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is the assignment: a. The program has no functions. Modify the program so t

ID: 3627487 • Letter: H

Question

Here is the assignment:
a. The program has no functions. Modify the program so that it uses only void functions. You need:
1. one function to get the data from the user
2. three functions for the calculations (wood, canvas, total)
3. one function to print the output.
b. Write each function parameter on a line by itself and indicate with a comment if the parameter is /*in*/ or /*out*/
c. Write preconditions and postconditions for each function
(I can't use arrays)

This is what I got so far:

//******************************************************************
// Canvas program
// This program computes the dimensions and costs of materials
// to build a painting canvas of given dimensions. The user is
// asked to enter the length and width of the painting and the
// costs of the wood (per inch) and canvas (per square inch)
//******************************************************************
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <fstream>

using namespace std;

void FindData(double, double, double, double);
void FindWood(double&, double&, double);
void FindCanvas(double&, double&);
void FindTotalCost(double&, double&, double&);
void PrintResults();

const int OVERLAP = 5; // Extra inches needed for canvas overlap on frame

int main()
{
double length; // Length of painting in inches
double width; // Width of painting in inches
double woodCost; // Cost of wood per inch in dollars
double canvasCost; // Cost of canvas per square foot
double lengthOfWood; // Amount of wood to buy
double canvasWidth; // Width of canvas to buy
double canvasLength; // Length of canvas to buy
double canvasAreaInches; // Area of canvas in square inches
double totalCanvasCost; // Total cost of canvas being bought
double totalWoodCost; // Total cost of wood being bought
double totalCost; // Total cost of materials

cout << fixed << showpoint;
FindData(length, width, woodCost, canvasCost);
FindWood(lengthOfWood, totalWoodCost, woodCost);
FindCanvas(canvasAreaInches, totalCanvasCost);
FindTotalCost(totalCanvasCost, totalWoodCost, totalCost);
PrintResults();


getch();
return 0;
}

void FindData(double length, double width, double woodCost, double canvasCost)
{
cout << "Enter length and width of painting:" << endl;
cin >> length >> width;

cout << "Enter cost per inch of the framing wood in dollars:"
<< endl;
cin >> woodCost;

cout << "Enter cost per square inch of canvas in dollars:"
<< endl;
cin >> canvasCost;
}

void FindWood(double& lengthOfWood, double& totalWoodCost, double woodCost, double& length, double& width)
{
lengthOfWood = (length + width) * 2;
totalWoodCost = lengthOfWood * woodCost;
}

void FindCanvas(double& canvasAreaInches, double& totalCanvasCost, double& width, double& length, double& canvasCost, double& canvasWidth, double& canvasLength)
{
canvasWidth = width + OVERLAP;
canvasLength = length + OVERLAP;
canvasAreaInches = canvasWidth * canvasLength;
totalCanvasCost = canvasAreaInches * canvasCost;
}

void FindTotalCost(double& totalCanvasCost, double& totalWoodCost, double& totalCost)
{

totalCost = totalWoodCost + totalCanvasCost;
}

void PrintResult(double& length, double& width, double& lengthOfWood, double& canvasLength, double& canvasWidth, double& woodCost, double& canvasCost, double& totalWoodCost, double& totalCanvasCost, double& totalCost)
{
// Print the dimensions
cout << endl << setprecision(1);
cout << "Painting is " << length << " in. long and "
<< width << " in. wide." << endl;
cout << setw(5) << ' ' << "Buy " << lengthOfWood << " in. of wood." << endl;
cout << setw(5) << ' ' << "Buy a " << canvasLength << " in. by "
<< canvasWidth << " in. canvas" << endl;

//Print the costs
cout << endl << setprecision(2);
cout << "The wood costs $" << woodCost << " per in." << endl;
cout << "The canvas costs $" << canvasCost << " per sq. in." << endl;
cout << endl;
cout << "Your costs will be: " << endl;
cout << setw(5) << ' ' << "Wood cost - $" << totalWoodCost << endl;
cout << setw(5) << ' ' << "Canvas cost - $" << totalCanvasCost << endl;
cout << "Total cost of materials $" << totalCost << endl;
}

But I keep getting errors
Please help.

Explanation / Answer

A lot of your errors were because the functions weren't consistent on top and bottom.

//****************************************************************** // Canvas program // This program computes the dimensions and costs of materials // to build a painting canvas of given dimensions. The user is // asked to enter the length and width of the painting and the // costs of the wood (per inch) and canvas (per square inch) //****************************************************************** #include <iostream> #include <conio.h> #include <iomanip> #include <fstream> using namespace std; const int OVERLAP = 5; // Extra inches needed for canvas overlap on frame double length; // Length of painting in inches double width; // Width of painting in inches double woodCost; // Cost of wood per inch in dollars double canvasCost; // Cost of canvas per square foot double lengthOfWood; // Amount of wood to buy double canvasWidth; // Width of canvas to buy double canvasLength; // Length of canvas to buy double canvasAreaInches; // Area of canvas in square inches double totalCanvasCost; // Total cost of canvas being bought double totalWoodCost; // Total cost of wood being bought double totalCost; // Total cost of materials void FindData(double&, double&, double&, double&); void FindWood(double&, double&); void FindCanvas(double&, double&, double&); void FindTotalCost(double&); void PrintResults(); int main() { cout << fixed << showpoint; FindData(length, width, woodCost, canvasCost); FindWood(lengthOfWood, totalWoodCost); FindCanvas(canvasWidth, canvasLength, totalCanvasCost); FindTotalCost(totalCost); PrintResults(); system("pause"); return 0; } void FindData(double &length, double &width, double &woodCost, double &canvasCost) { cout << "Enter length and width of painting:" << endl; cin >> length >> width; cout << "Enter cost per inch of the framing wood in dollars:" << endl; cin >> woodCost; cout << "Enter cost per square inch of canvas in dollars:" << endl; cin >> canvasCost; } void FindWood(double &lengthOfWood, double &totalWoodCost) { lengthOfWood = (length + width) * 2; totalWoodCost = lengthOfWood * woodCost; } void FindCanvas(double &canvasWidth, double &canvasLength, double &totalCanvasCost) { canvasWidth = width + OVERLAP; canvasLength = length + OVERLAP; canvasAreaInches = canvasWidth * canvasLength; totalCanvasCost = canvasAreaInches * canvasCost; } void FindTotalCost(double &totalCost) { totalCost = totalWoodCost + totalCanvasCost; } void PrintResults() { // Print the dimensions cout << endl << setprecision(1); cout << "Painting is " << length << " in. long and " << width << " in. wide." << endl; cout << setw(5) << ' ' << "Buy " << lengthOfWood << " in. of wood." << endl; cout << setw(5) << ' ' << "Buy a " << canvasLength << " in. by " << canvasWidth << " in. canvas" << endl; //Print the costs cout << endl << setprecision(2); cout << "The wood costs $" << woodCost << " per in." << endl; cout << "The canvas costs $" << canvasCost << " per sq. in." << endl; cout << endl; cout << "Your costs will be: " << endl; cout << setw(5) << ' ' << "Wood cost - $" << totalWoodCost << endl; cout << setw(5) << ' ' << "Canvas cost - $" << totalCanvasCost << endl; cout << "Total cost of materials $" << totalCost << endl; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote