1. Engineering
  2. Computer Science
  3. consider the following statements include ltstringgt include ltcmathgt class temporary...

Question: consider the following statements include ltstringgt include ltcmathgt class temporary...

Question details

Consider the following statements:

#include <string>
#include <cmath>

class Temporary
{
private:
  string description;
  double first;
  double second;
public:
  Temporary(string = "", double = 0.0, double = 0.0);
  void set(string, double, double);
  double manipulate();
  void get(string&, double&, double&);
  void setDescription(string);
  void setFirst(double);
  void setSecond(double);
};
  1. Write the definition of the member function set() so that the instance variables are set according to the parameters.
  2. Write the definition of the constructor so that it initializes the instance variables using the function set()
  3. Write the definition of the member function manipulate() that returns a decimal number (double) as follows:
    • If the value of description is "rectangle", it returns first * second
    • If the value of description is "circle" it returns the area of a circle with radius first
    • if the value of description is "cylinder" it returns the volume of a cylinder with radius first and height second. HINT: the volume of a cylinder is simply the area of the circle at the base times the height.
    • If the value of description is "sphere" it returns the volume of the sphere with radius first.
    • Otherwise it returns -1.0;
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution