Answer to Question #258123 in UNIX/Linux Programming for qweqweqw

Question #258123

Create a program that calculates the cost of building a desk. The main() function calls four other functions. Pass all variables so that the function makes copies of any variables they receive:

a. A function to accept as input from the keyboard the number of drawers in the desk. This function returns the number of drawers to the main program. 

b. A function to accept as input the type of wood –‘m’ for mahogany, ‘o’ for oak, or ‘p’ for pine 

c. A function that receives the drawer number and wood type, and calculate the cost of the desk based on the following: 

  1. Pine desk are 100. 
  2. Oak desk are 140 
  3. All other woods are 180 
  4. A 30 subcharge is added for each drawer 

This function returns the cost of the main() function. 

d. A function to display the final price. 


1
Expert's answer
2021-10-29T00:54:35-0400


#include <iostream>
#include <fstream>
using namespace std;


const int SURCHARGE=30;
 const int PINE=100;
const int OTHERS=180;
 const int OAK=140;


 
 char deskType();
int numDeskDrawers();
int calculate(int num_drawers,char wood_type);
void display(int num_drawers,char wood_type);
int main( )
{
 int n = numDeskDrawers();
 char h = deskType();
 display(n,h);


 return 0;
}
int numDeskDrawers(){


 cout<<"Enter the number of drawers:\n";
 int n;
 cin>>n;
 return n;
}


char deskType(){
 cout<<"Enter the type of wood like 'm' for mahogany, 'o'' for oak, or 'p' for pine:\n";
 char n;
 cin>>n;
 return n; 
}


 int calculate(int num_drawers,char wood_type){
 
int total;
 if (wood_type=='o'){
 total = OTHERS * num_drawers + SURCHARGE;
 }
 else if(wood_type=='p'){
 total = PINE * num_drawers + SURCHARGE;
 }
 else {
 total = num_drawers * OTHERS + SURCHARGE;
 }
 return total;
 }
 
 void display(int num_drawers,char wood_type){
 cout<<"The cost of building a desk is: "<<calculate(num_drawers,wood_type )<<endl;
 }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS