Question

In C++

Amanda and Tyler opened a business that specializes in shipping liquids, such as milk, juice, and water, in cylindrical containers. The shipping charges depend on the amount of the liquid in the container. (For simplicity, you may assume that the container is filled to the top.) They also provide the option to paint the outside of the container for a reasonable amount. Write a program that does the following:

  1. Prompts the user to input the dimensions (in feet) of the container (radius of the base and the height).
  2. Prompts the user to input the shipping cost per liter.
  3. Prompts the user to input the paint cost per square foot. (Assume that the entire container including the top and bottom needs to be painted.)
  4. Separately outputs the shipping cost and the cost of painting. Your program must use the class cylinderType (designed in Programming Exercise 3) to store the radius of the base and the height of the container. (Note that 1 cubic feet = 28.32 liters or 1 liter = 0.353146667 cubic feet.)

Format your output with setprecision(2) to ensure the proper number of decimals for testing! Also, beware of floating-point errors in your calculations.

Theres error or incomplete in the codes below. This are the errors or incomplete.

The codes did not output for the 471.24.
Test Case Incomplete Cheap shipping test Input un 10 2 1 Output Enter the radius :5 Enter the Height of the cylinder 10 Enter

Also for the test case 2

< Test Case Incomplete Expensive shipping cost Input 10 30 4 1.2 Output Enter the radius : 10 Enter the Height of the cylinde


Guide codes:

circleType.h

#ifndef circleType_H
#define circleType_H
class circleType
{
public:
void print();
void setRadius(double r);
//Function to set the radius.
//Postcondition: if (r >= 0) radius = r;
// otherwise radius = 0;
double getRadius();
//Function to return the radius.
//Postcondition: The value of radius is returned.
double area();
//Function to return the area of a circle.
//Postcondition: Area is calculated and returned.
double circumference();
//Function to return the circumference of a circle.
//Postcondition: Circumference is calculated and returned.
circleType(double r = 0);
//Constructor with a default parameter.
//Radius is set according to the parameter.
//The default value of the radius is 0.0;
//Postcondition: radius = r;
private:
double radius;
};
#endif

_________________

circleTypeImpl.cpp

#include <iostream>
#include "circleType.h"
using namespace std;
void circleType::print()
{
cout << "Radius = " << radius
<< ", area = " << area()
<< ", circumference = " << circumference();
}

void circleType::setRadius(double r)
{
if (r >= 0)
radius = r;
else
radius = 0;
}
double circleType::getRadius()
{
return radius;
}
double circleType::area()
{
return 3.1416 * radius * radius;
}
double circleType::circumference()
{
return 2 * 3.1416 * radius;
}
circleType::circleType(double r)
{
setRadius(r);
}

__________________

cylinderType.h

#ifndef cylinderType_H
#define cylinderType_H
#include "circleType.h"
class cylinderType: public circleType
{
public:
void print();
void setHeight(double);
double getHeight();
double volume();
double area();
//returns surface area
cylinderType(double = 0, double = 0);
private:
double height;
};
#endif

________________

cylinderTypeImpl.cpp

#include <iostream>
#include "circleType.h"
#include "cylinderType.h"
using namespace std;
cylinderType::cylinderType(double r, double h)
: circleType(r)
{
setHeight(h);
}
void cylinderType::print()
{
cout << "Radius = " << getRadius()
<< ", height = " << height
<< ", surface area = " << area()
<< ", volume = " << volume();
}
void cylinderType::setHeight(double h)
{
if (h >= 0)
height = h;
else
height = 0;
}
double cylinderType::getHeight()
{
return height;
}
double cylinderType::area()
{
return 2 * 3.1416 * getRadius() * (getRadius() + height);
}
double cylinderType::volume()
{
return 3.1416 * getRadius() * getRadius() * height;
}

_________________

main.cpp

#include <iostream>
#include <iomanip>
using namespace std;

#include "cylinderType.h"

int main()
{
//Declaring variables
double radius,height;
double shippingCostPerLi,paintCost,shippingCost=0.0;
  
//Setting the precision to two decimal places
cout << fixed << showpoint;
cout << setprecision(2);


//Getting the inputs entered by the user
cout<<"Enter the radius :";
cin>>radius;
  
cout<<"Enter the Height of the cylinder :";
cin>>height;
  
  
cout<<"Enter the shipping cost per liter :$";
cin>>shippingCostPerLi;
  
  
//Creating an instance of CylinderType by passing the radius and height as arguments
cylinderType ct(radius,height);
  
//Getting the area and volume of the cylinder
double surfaceArea=ct.area();
double vol=ct.volume();
  
  
//calculating the shipping cost
shippingCost+=vol*28.32*shippingCostPerLi;
  
char ch;
  
//Prompting the user to paint the container or not
cout<<"Do you want the paint the container (y/n)?";
cin>>ch;
  
if(ch=='y' || ch=='Y')
{
cout<<"Enter the paint cost per sq foot :$";
cin>>paintCost;   
shippingCost+=surfaceArea*paintCost;   
}   

//Displaying the total shipping cost
cout<<"Total Shipping Cost :$"<<shippingCost<<endl;
  
return 0;
}

0 1
Add a comment Improve this question Transcribed image text
Answer #1

circleType.h

#ifndef circleType_H
#define circleType_H
class circleType
{
public:
void print();
void setRadius(double r);
//Function to set the radius.
//Postcondition: if (r >= 0) radius = r;
// otherwise radius = 0;
double getRadius();
//Function to return the radius.
//Postcondition: The value of radius is returned.
double area();
//Function to return the area of a circle.
//Postcondition: Area is calculated and returned.
double circumference();
//Function to return the circumference of a circle.
//Postcondition: Circumference is calculated and returned.
circleType(double r = 0);
//Constructor with a default parameter.
//Radius is set according to the parameter.
//The default value of the radius is 0.0;
//Postcondition: radius = r;
private:
double radius;
};
#endif

_________________

circleTypeImpl.cpp

#include <iostream>
#include "circleType.h"
using namespace std;
void circleType::print()
{
cout << "Radius = " << radius
<< ", area = " << area()
<< ", circumference = " << circumference();
}

void circleType::setRadius(double r)
{
if (r >= 0)
radius = r;
else
radius = 0;
}
double circleType::getRadius()
{
return radius;
}
double circleType::area()
{
return 3.1416 * radius * radius;
}
double circleType::circumference()
{
return 2 * 3.1416 * radius;
}
circleType::circleType(double r)
{
setRadius(r);
}

__________________

cylinderType.h

#ifndef cylinderType_H
#define cylinderType_H
#include "circleType.h"
class cylinderType: public circleType
{
public:
void print();
void setHeight(double);
double getHeight();
double volume();
double area();
//returns surface area
cylinderType(double = 0, double = 0);
private:
double height;
};
#endif

________________

cylinderTypeImpl.cpp

#include <iostream>
#include "circleType.h"
#include "cylinderType.h"
using namespace std;
cylinderType::cylinderType(double r, double h)
: circleType(r)
{
setHeight(h);
}
void cylinderType::print()
{
cout << "Radius = " << getRadius()
<< ", height = " << height
<< ", surface area = " << area()
<< ", volume = " << volume();
}
void cylinderType::setHeight(double h)
{
if (h >= 0)
height = h;
else
height = 0;
}
double cylinderType::getHeight()
{
return height;
}
double cylinderType::area()
{
return 2 * 3.1416 * getRadius() * (getRadius() + height);
}
double cylinderType::volume()
{
return 3.1416 * getRadius() * getRadius() * height;
}

_________________

main.cpp

#include <iostream>
#include <iomanip>
using namespace std;

#include "cylinderType.h"

int main()
{
//Declaring variables
double radius,height;
double shippingCostPerLi,paintCost,shippingCost=0.0;
  
//Setting the precision to two decimal places
cout << fixed << showpoint;
cout << setprecision(2);


//Getting the inputs entered by the user
cout<<"Enter the radius :";
cin>>radius;
  
cout<<"Enter the Height of the cylinder :";
cin>>height;
  
  
cout<<"Enter the shipping cost per liter :$";
cin>>shippingCostPerLi;
  
  
//Creating an instance of CylinderType by passing the radius and height as arguments
cylinderType ct(radius,height);
  
//Getting the area and volume of the cylinder
double surfaceArea=ct.area();
double vol=ct.volume();
  
  
//calculating the shipping cost
shippingCost+=vol*28.32*shippingCostPerLi;
  
char ch;
  
//Prompting the user to paint the container or not
cout<<"Do you want the paint the container (y/n)?";
cin>>ch;
  
if(ch=='y' || ch=='Y')
{
cout<<"Enter the paint cost per sq foot :$";
cin>>paintCost;   
shippingCost+=surfaceArea*paintCost;   
}   

//Displaying the total shipping cost
cout<<"Total Shipping Cost :$"<<shippingCost<<endl;
  
return 0;
}

___________________

Output:

./CircleTypeCylinder Type Enter the radius :5.5 Enter the Height of the cylinder :5 Enter the shipping cost per liter :$0.25

_______________Thank YOu

Add a comment
Know the answer?
Add Answer to:
In C++ Amanda and Tyler opened a business that specializes in shipping liquids, such as milk,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add t...

    C++ Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in chapter 10.   Some of the...

  • C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a...

    C++ problem 11-3 Chapter 10 defined the class circleType to implement the basic properties of a circle. (Add the function print to this class to output the radius, area, and circumference of a circle.) Now every cylinder has a base and height, where the base is a circle. Design a class cylinderType that can capture the properties of a cylinder and perform the usual operations on the cylinder. Derive this class from the class circleType designed in Chapter 10. Some...

  • I need to implement a program that requests a x,y point and the radius of a...

    I need to implement a program that requests a x,y point and the radius of a circle. then it figures out the area and circumference using an overloaded operation. The full instructions, what I have and the errors I have are below. A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x-y plane. You should then perform operations on the point, such as...

  • A) One of the problems that have been discussed in the class is to write a simple C++ program to ...

    C++ programming question will upvote A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following int main //the radius of the...

  • A) One of the problems that have been discussed in the class is to write a...

    A) One of the problems that have been discussed in the class is to write a simple C++ program to determine the area and circumference of a circle of a given radius. In this lab you will be rewriting the program again but this time you will be writing some functions to take care of the user input and math. Specifically, your main function should look like the following: int main() { double radius; double area; double circumference; //the radius...

  • #include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius;...

    #include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius; // get function for radius public: double getRadius(){ return radius; } // set function for radius void setRadius(double rad){ radius=rad; } // returning area = 3.14159 * radius * radius double getArea(){ return (3.14159 * radius * radius); } }; // Sample run int main() { // Declaring object of Circle Circle myCircle; myCircle.setRadius(5); // printing radius of circle cout<<"Radius of circle is: "<<(myCircle.getRadius())<<endl;...

  • PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program...

    PLEASE TYPE OUT IN TEXT (please no pdf or writing) C++ CODE Consider the following program in which the statements are in the incorrect order. Rearrange the statements in the following order so that the program prompts the user to input: The height of the base of a cylinder The radius of the base of a cylinder The program then outputs (in order): The volume of the cylinder. The surface area of the cylinder Format the output to two decimal...

  • Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use...

    Extend the code from Lab6.A template is given to you with CircleHeader.h, Circle.cpp and CircleMain.cpp Use the same Circle UML as below and make extensions as marked and as needed. Given below is a UML for the Painting Class. You will need to write PaintingHeader.h and Painting.cpp. The Painting Class UML contains a very basic skeleton. You will need to flesh out this UML and add more instance variables and methods as needed. You do NOT need to write a...

  • Write a java class definition for a circle object. The object should be capable of setting...

    Write a java class definition for a circle object. The object should be capable of setting radius, and computing its area and circumference. Use this to create two Circle objects with radius 10 and 40.5, respectively. Print their areas and circumference. Here is the Java class file (Circle.java). Compile it. public class Circle{ //Instance Variables private double PI = 3.1459; private double radius; //Methods public Circle ( ) { }    //get method (Accessor Methods ) public double getRadius (...

  • Consider the following program in which the statements are in the incorrect order. Rearrange the statements...

    Consider the following program in which the statements are in the incorrect order. Rearrange the statements so that the program prompts the user to input the height and the radius of the base of a cylinder and outputs the volume and surface area of the cylinder. Formant the output to two decimal places. #include <iomanip> #include <cmath> int main () {} double height; cout << ”Volume of the cylinder = “ <<PI * pow(radius, 2.0) * height << endl; cout...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT