Write a program to illustrate how to use the temporary class, designed in Exercises 13 and 14 of this chapter. Your program must contain statements that would ask the user to enter data of an object and use the setters to initialize the object. The header file for the class temporary from Exercise 13 has been provided. An example of the program is shown below: Enter object name (rectangle, circle, sphere, or cylinder: circle Enter object's dimensions: rectangle (length and width) circle (radius and 0) sphere (radius and 0) rectangle (base raidus and height) 10 0 After setting myObject: circle: radius = 10.00, area = 314.1

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter16: Graphics
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question

Instructions

Write a program to illustrate how to use the temporary class, designed in Exercises 13 and 14 of this chapter. Your program must contain statements that would ask the user to enter data of an object and use the setters to initialize the object.

The header file for the class temporary from Exercise 13 has been provided.

An example of the program is shown below:

Enter object name (rectangle, circle, sphere, or cylinder: circle Enter object's dimensions: rectangle (length and width) circle (radius and 0) sphere (radius and 0) rectangle (base raidus and height) 10 0 After setting myObject: circle: radius = 10.00, area = 314.1

 

 

I have already tried a code but I can't get it to do one of the steps right. I have added images of what cant be completed with my code now.

 

Here is my code : 

Main.cpp 

#include "temporary.h"
#include <string>
#include <iostream>
using namespace std;


int main(int argc, char** argv) {


   string desc;
   double first;
   double second;
  
   temporary temp;
  
   cout<<"Printing object before setting any values: "<<endl;
   temp.print();
   cout<<"Enter description: "; getline(cin,desc,'\n');
   cout<<"Enter first: "; cin>>first;
   cout<<"Enter second: "; cin>>second;
  
   temp.setDescription(desc);
   temp.setFirst(first);
   temp.setSecond(second);
   cout<<"Printing object after setting user values: "<<endl;
   temp.print();
  
   temp.manipulate();
   cout<<"After Manipulating object: "<<endl;
   temp.print();
  
  
  
}
 
 
temporary.h 
 
#ifndef TEMPORARY_H
#define TEMPORARY_H
#include <string>
using namespace std;

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, double = 0);

private:

string description;
double first;
double second;

};
#endif
 
 
temporaryImp.cpp
 
#include "temporary.h"
#include <string>
#include <iostream>

using namespace std;

   temporary::temporary(string desc, double first, double second)
   {
       description = desc;
       this->first = first;
       this->second = second;
   }

void temporary::set(string desc, double first, double second)
    {
       description = desc;
       this->first = first;
       this->second = second;
   }
void temporary::print(){
   cout<<"Description: "<<description<<", First: "<<first<<", Second: "<<second<<endl;
   }
double temporary::manipulate(){
   description = description+" " + description;
   first = first*2;
   second = second*3;
   }
void temporary::get(string& desc, double& f , double& s){
   desc = description;
   f = first;
   s = second;
   }
void temporary::setDescription(string desc){
   this->description = desc;
   }
void temporary::setFirst(double aFirst){
   first = aFirst;
   }
void temporary::setSecond(double aSecond){
   second = aSecond;
   }
string temporary::getDescription() const{
   return description;
   }
double temporary::getFirst() const{return first;}
double temporary::getSecond() const {return second;}

 

The program accepts input
and outputs the proper
0.00
out of
10.00
dimensions of the
indicated shape.
O out of 4 checks passed.
Review the results below for
more details.
Checks
Test Case
Incomplete
Circle object's dimensions were
printed to the console
Test Case
Incomplete
Sphere object's dimensions
were printed to the console
Test Case
Incomplete
Rectangle object's dimensions
were printed to the console
Test Case
Incomplete
Cylinder object's dimensions
were printed to the console
Transcribed Image Text:The program accepts input and outputs the proper 0.00 out of 10.00 dimensions of the indicated shape. O out of 4 checks passed. Review the results below for more details. Checks Test Case Incomplete Circle object's dimensions were printed to the console Test Case Incomplete Sphere object's dimensions were printed to the console Test Case Incomplete Rectangle object's dimensions were printed to the console Test Case Incomplete Cylinder object's dimensions were printed to the console
Test Case • Incomplete
Circle object's dimensions were
printed to the console
Input
circle
10
Output
Printing object before setting any
Description: , First: 0, Second: 0
Enter description: circle
Enter first: 10
Enter second: 0
Printing object after setting user
Description: circle, First: 10, Sec
After Mantpulating object:
Description: circle circle, First:
Results
radiusts*1-1s*18.88 areats*1=1s*314.16
Expected Output ®
radiusįs*1=1s*18 .00 areats*1=1s*314.16
Transcribed Image Text:Test Case • Incomplete Circle object's dimensions were printed to the console Input circle 10 Output Printing object before setting any Description: , First: 0, Second: 0 Enter description: circle Enter first: 10 Enter second: 0 Printing object after setting user Description: circle, First: 10, Sec After Mantpulating object: Description: circle circle, First: Results radiusts*1-1s*18.88 areats*1=1s*314.16 Expected Output ® radiusįs*1=1s*18 .00 areats*1=1s*314.16
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT