Question

In a c++ program, Implement a Pyramid class with base and height as data members and...

In a c++ program, Implement a Pyramid class with base and height as data members and surface area() and volume() calculations as member functions.

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

// C++ code
#include <iostream>
#include <cstdlib>
#include <math.h>
using namespace std;

class Pyramid
{
   private:
       double base;
       double height;
       double length;
   public:
       Pyramid()
       {
           base = 0 ;
           height = 0;
       }

       Pyramid(double b, double ht)
       {
           base = b;
           height = ht;
       }

       double surface_area()
       {
           return 0.5*(base*height);
       }

       double volume()
       {
           return (base*height);
       }

};

int main()
{
   Pyramid p(3,4);

   cout << "surface_area: " << p.surface_area() << endl;
   cout << "volume: " << p.volume() << endl;

}
/*
output:

surface_area: 6
volume: 12


*/

Add a comment
Know the answer?
Add Answer to:
In a c++ program, Implement a Pyramid class with base and height as data members and...
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
  • Write a C# application that implements a class ‘Prism’ with the following members. Five private data...

    Write a C# application that implements a class ‘Prism’ with the following members. Five private data members ‘length’, ‘height’, ‘width’, ‘Volume’ and ‘Area’ of double data type. Implement the constructor Prism( ) to accept the length, height, and width of the rectangular prism from the user. Implement three methods, Vol(), Area(), and Result() Vol() – to calculate the volume of the prism using the formulae Volume= length ×height ×width Area() – to calculate the surface area of the prism using...

  • This Program should run in C++ In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleTyp...

    This Program should run in C++ In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleType class and overload the following operators: +, -, *, ++, --, ==, !=, >>, and <<. Your program should contain the following features: a. Create a base class named rectangleType with following private data members: • length with double type • width with double type b. rectangleType class...

  • (a) A pyramid has a height of 458 ft and its base covers an area of...

    (a) A pyramid has a height of 458 ft and its base covers an area of 14.0 acres (see figure below). The volume of a pyramid is given by the expression where B is the area of the base and h is the height. Find the volume of this pyramid in cubic meters. (1 acre 43,560 ft) m3 What If? If the height of the pyramid were increased to 517 ft and the height to base area ratio of the...

  • In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we...

    In an effort to develop in-depth knowledge of base class, derived class, and operator overloading, we will expand on our in-class exercise of developing the rectangleType class and overload the following operators: +, -, *, ++, --, ==, !=, >>, and <<. Your program should contain the following features: a. Create a base class named rectangleType with following private data members: • length with double type • width with double type b. rectangleType class should contain the following functions: •...

  • A pyramid has a height of 455 ft and its base covers an area of 12.0...

    A pyramid has a height of 455 ft and its base covers an area of 12.0 acres (see figure below). The volume of a pyramid is given by the expression V =1/3Bh where B is the area of the base and h is the height. Find the volume of this pyramid in cubic meters. (1 acre = 43,560 ft2)

  • in c++ Define and implement the class Employee with the following requirements: private data members string...

    in c++ Define and implement the class Employee with the following requirements: private data members string type name a. b. double type hourlyRate 2. public member functions a. default constructor that sets the data member name to blank"and hourlyRate to zero b. A constructor with parameters to initialize the private data members c. Set and get methods for all private data members d. A constant method weeklyPay() that receives a parameter representing the number of hours the employee worked per...

  • 17.A pyramid has a height of 481 ft. and the base covers an area of 13.0...

    17.A pyramid has a height of 481 ft. and the base covers an area of 13.0 acres. The volume Vof a pyramid is given by the expression V-Bh, where B is the area of the base and h is the height. a) Find the volume of the pyramid in cubic meters. (1 acre 43,560 ft2) b) Assume the pyramid above contains exactly 2 million stone blocks that average 2.50 tons each. Determine the weight of the pyramid in pounds. (1...

  • Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class...

    Construct a C++ class named Rectangle that has floating-point data members named length and width.  The class should have a zero-argument constructor that initializes each data member to 0. It should have member functions named calcPerimeter() and calcArea() that calculate the perimeter and area of a rectangle respectively, a member function setLength() and setWidth() to set the length and width, member functions getLength() and getWidth() to return the length and width, and a member function showData() that displays the rectangle’s length,...

  • Write a program using the class to find out the area of a circle and volume...

    Write a program using the class to find out the area of a circle and volume of a cylinder. [* area of a circle=πr2, the volume of a cylinder=πr2*h where h is the height of the cylinder and r is the radius of the circular end of the cylinder] 1. The member variable should be private 2. Use public member functions to execute your program. 3. Use set ( ) function to access the private members 4. Use another approach...

  • I am having difficulty with completing this task. thank you. Task 10.1 (a) Define a C++...

    I am having difficulty with completing this task. thank you. Task 10.1 (a) Define a C++ base class named Rectangle containing length and width data members. From this class, derive a class named Box with another data member named depth. The member functions for the base class Rectangle should consist of a constructor and an area() function. The derived class Box should have a constructor, a volume() function and an override function named area() that returns the surface area of...

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