Answer to Question #253994 in C++ for Asyong

Question #253994

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:


1
Expert's answer
2021-10-20T14:30:14-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
New on Blog
APPROVED BY CLIENTS