class temporary { public: void set(string, double, double); void print(); double manipulate(); void get(string&, double&, double&); void setDescription(string); void setFirst(double); void setSecond(double); string getDescription() const; double getFirst()const; double getSecond()const; temporary(string = "", double = 0.0, double = 0.0); private: string description; double first; double second; }; What are the members and functions in this example? I need help identifying how the members and functions work to answer the questions below. I am having troubles understanding this concept. I am learning constructors and deconstructors along with inline and hiding information. I feel lost trying to answer these questions. Can I get direction on how to proceed? Write the definition of the member function set so that the instance variables are set according to the parameters. Write the definition of the member function manipulate that returns a decimal number 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 the circle with radius first; if the value of description is "sphere", it returns the volume of the sphere with radius first; if the value of description is "cylinder", it returns the volume of the cylinder with radius first and height second; otherwise, it returns the value -1. Write the definition of the function print to print the values of the instance variables and the values returned by the function manipulate. For example, if description = "rectangle", first = 8.5, and second = 5, it should print: rectangle: length = 8.50, width = 5.00, area = 42.50
class temporary
{
public:
void set(string, double, double);
void print();
double manipulate();
void get(string&, double&, double&);
void setDescription(string);
void setFirst(double);
void setSecond(double);
string getDescription() const;
double getFirst()const;
double getSecond()const;
temporary(string = "", double = 0.0, double = 0.0);
private:
string description;
double first;
double second;
};
What are the members and functions in this example? I need help identifying how the members and functions work to answer the questions below. I am having troubles understanding this concept. I am learning constructors and deconstructors along with inline and hiding information. I feel lost trying to answer these questions. Can I get direction on how to proceed?
Write the definition of the member function set so that the instance variables are set according to the parameters.
Write the definition of the member function manipulate that returns a decimal number 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 the circle with radius first; if the value of description is "sphere", it returns the volume of the sphere with radius first; if the value of description is "cylinder", it returns the volume of the cylinder with radius first and height second; otherwise, it returns the value -1.
Write the definition of the function print to print the values of the instance variables and the values returned by the function manipulate. For example, if description = "rectangle", first = 8.5, and second = 5, it should print: rectangle: length = 8.50, width = 5.00, area = 42.50
Algorithm:
Include necessary libraries:
- Include the required C++ libraries for input and output (
iostream), string handling (string), and formatting (iomanip).
- Include the required C++ libraries for input and output (
Define the
temporaryclass:- Declare the
temporaryclass with public and private sections. - Inside the public section, declare member functions:
setfor setting instance variables.printfor printing values.manipulatefor calculating based on the description.
- Inside the private section, declare instance variables for description, first, and second.
- Declare the
Constructor for
temporaryclass:- Define a constructor for the
temporaryclass that initializes instance variables using thesetfunction.
- Define a constructor for the
Define the
setfunction:- Set the instance variables (description, first, and second) to the values passed as parameters.
Define the
manipulatefunction:- Check the value of the
descriptionmember variable and perform calculations accordingly. - Return the calculated value.
- Handle different shape cases: rectangle, circle, sphere, cylinder, and an unknown shape.
- Check the value of the
Define the
printfunction:- Print the shape's description.
- Print the length and width or radius, formatted with two decimal places.
- Print the area or volume calculated using the
manipulatefunction, also formatted with two decimal places.
In the
mainfunction:- Create instances of the
temporaryclass representing different shapes: rectangle, circle, sphere, cylinder, and an unknown shape. - Set their parameters using the constructor or the
setfunction. - Call the
printfunction on each instance to display the shape details and calculated area/volume.
- Create instances of the
Return 0:
- Exit the program with a return status of 0.
Step by step
Solved in 5 steps with 4 images









