You are here:

C++/Help with turning this Pseudo code into c++?


Hey, I have a c++ test in almost a week and am having trouble with this one question on functions on this review sheet my teacher gave us that didn't include answers.  

I really can't understand functions very well or how to code them.  

Basically, the questions ask the user to turn the given Pseudo code into c++ code.  the c++ program will calculate the installation cost and the total cost of installing carpeting.  Input of the program will be the length and width of each room, followed by the cost per square foot.  The total cost should include tax and labor cost.  

Here is the pseudo code:

//Shell for Carpet Cost program
//include libraries
Void getdata (int &length, int& width, float& costpersqfoot);
//read the length and width of the room and the cost per square foot
Float InstalledPrice (int length, int width, float costpersqfoot);
//calculate the installed price taking into account the labor
//cost.  The labor cost is a symbolic constant
Float totalprice (float installation);
//finds the total cost using the installed price and the tax rate
//taxrate is also a symbolic constant
Void printdata (int length, int width, float price);
//prints the length, width, and total cost for each data set
Const float LABOR+COST = 0.35; // $0.35 per square foot
Const float TAX_RATE = 0.05;
Int main()
{ // declare length and width of type int
// declare installation cost and total cost of type float.

//Read count for the loop
//for loop based on the count
//   call get_data
//   find installation cost
//   find total cost
//   Write the result with the printdata procedure
//return from main
} // end of main
// define functions here, two void and two regular

Like I said I'm horrible with functions having just studied them.  I would really like to study this code to try and understand them better.  Thank for any help you could provide.

I'll get you started on this homework.

#include <iostream>

void getdata( int& length, int& width, float& costpersqfoot ) ;

int main()
   int len, wdth ;
   float cost_sqft ;
   getdata( len, wdth, cost_sqft ) ;

   std::cout << "the room is " << len << "feet by " << wdth << "feet.\n"
         << "cost of carpeting per sqft: " << cost_sqft  ;
   int area = len * wdth ;
   std::cout << "the area of the room in sq feet is: " << area << '\n' ;

   // TODO:
   // calculate cost of carpeting for the room
   // add labour and tax
   // print total cost including labour and tax

void getdata( int& length, int& width, float& costpersqfoot )
   std::cout << "length? " ;
   std::cin >> length ;

   std::cout << "width? " ;
   std::cin >> width ;

   std::cout << "cost per sqfoot? " ;
   std::cin >> costpersqfoot ;


All Answers

Answers by Expert:

Ask Experts




my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.


about 15 years or so

post graduate engineer

©2016 All rights reserved.