Question

For this question you will write two (2) constructors in the implementation file: CylinderType.cpp (Assume that...

For this question you will write two (2) constructors in the implementation file: CylinderType.cpp

(Assume that the base class CircleType has a default constructor & assigns 1.0 to its private double radius)

part (a) // The first constructor is a default constructor. Please use height as the CylinderType's private member name in the body.

// It will create a CylinderType object with a radius of 1.0 and height of 1.0

part (b)    // The second constructor should have two formal parameters: (double rad and double heit).

// For full credit use these formal parameter names in your definition.

// Assume the base class CircleType header file has a mutator function named void setRadius (double); so its radius may be initialized

Homework Answers

Answer #1

CircleType header file (CircleType.h)

//CircleType header file

class CircleType

{

    private:

    double radius;

    public:

    //default constructor

    CircleType()

    {

        radius=1.0;

    }

    //mutator function

    void setRadius(double r)

    {

        radius=r;

    }

    double getRadius()

    {

        return radius;

    }

};

CylinderType Implementation file (CylinderType.cpp)

#include<iostream>

#include "CircleType.h" //including the circletype header file

using namespace std;

// CylinderType inherits CircleType

class CylinderType: public CircleType

{

    private:

    double height;

    public:

    //default constructor

    CylinderType()

    {

        height=1.0;

    }

    //parameterised constructor

    CylinderType(double r, double h)

    {

        height=h;

        //calling the mutator function to set the radius

        setRadius(r);

    }

    //function to display the radius and height

    void show()

    {

        cout<<"\nThe radius and height are: ";

        cout<<getRadius()<<" and "<<height;

    }

    

};

int main()

{

    CylinderType c, d(2.5,4.6);

    c.show();

    d.show();

    return 0;

}

OUTPUT:

Know the answer?
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
Similar Questions
1. Circle: Implement a Java class with the name Circle. It should be in the package...
1. Circle: Implement a Java class with the name Circle. It should be in the package edu.gcccd.csis. The class has two private instance variables: radius (of the type double) and color (of the type String). The class also has a private static variable: numOfCircles (of the type long) which at all times will keep track of the number of Circle objects that were instantiated. Construction: A constructor that constructs a circle with the given color and sets the radius to...
Attached is the file GeometricObject.java. Include this in your project, but do not change. Create a...
Attached is the file GeometricObject.java. Include this in your project, but do not change. Create a class named Triangle that extends GeometricObject. The class contains: Three double fields named side1, side2, and side3 with default values = 1.0. These denote the three sides of the triangle A no-arg constructor that creates a default triangle A constructor that creates a triangle with parameters specified for side1, side2, and side3. An accessor method for each side. (No mutator methods for the sides)...
do (iii) and (iv) (i) This is a simple Point class interface file whose objects represent...
do (iii) and (iv) (i) This is a simple Point class interface file whose objects represent points in the cartesian plane #include <iostream> using namespace std; class Point { public:     Point()      // default constructor         Point(double x, double y); // another constructor         double x() const; // get function, return _x         double y() const; // get function, return _y private:         double _x, _y; }; (ii) Here is a test driver file for the Point class...
we defined, implemented, and tested a class Time. In this lab, we will continue working with...
we defined, implemented, and tested a class Time. In this lab, we will continue working with the Time class. A. Separate the class definition and class implementation from the client program. Move the class definition into a header file named Time.h and move the class implementation into a cpp file named Time.cpp. Use preprocessor directive to include header files as needed. B. Modify the Time class as follows: 1. Replace the default constructor and overloaded constructor with a constructor with...
Write in Java (Not Javascript) Provide an implementation of priority queue using double-ended doubly linked lists....
Write in Java (Not Javascript) Provide an implementation of priority queue using double-ended doubly linked lists. Recall that double-ended means keeping first and last references and doubly linked feature allows us to go backwards, using a prev reference at each Link. Also, note that the greater the number, the lower the priority. For instance, 2 is of higher priority compared to 5. Specifically, write a class LinkedListPriorityQ which implements the priority queue methods: boolean isEmpty() void enqueue(int item) int dequeue()...
You are asked to implement a C++ class to model a sorted array of unsigned integers....
You are asked to implement a C++ class to model a sorted array of unsigned integers. The class is to be used in an embedded application that cannot assume the presence of the STL. The array has to be dynamically allocated in such a way that allows programmers using it to specify the required size. Your class should should: (1) provide the appropriate constructors and destructor; (2) provide methods for updating, and showing numbers in/to the array (e.g., to be...
IntNode class I am providing the IntNode class you are required to use. Place this class...
IntNode class I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined inline (within the class declaration). Do not write any other functions for the IntNode class. Use as is. struct IntNode { int data; IntNode *next;...
The Galactic Federation of Planets (GFP) maintains records on all planets that are applying to become...
The Galactic Federation of Planets (GFP) maintains records on all planets that are applying to become members of the GFP. A planet may make an application to become a member of the Galactic Federation of Planets when their technology has led them to develop Star Gate technology enabling them to travel to other planets in the galaxy outside their own solar system. Your assignment is to create a class that can be used to hold the basic information about a...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
IntList Lab Specifications You are required to come up with a single header file (IntList.h) that...
IntList Lab Specifications You are required to come up with a single header file (IntList.h) that declares and implements the IntNode class (just copy it exactly as it is below) as well as declares the IntList Class interface only. You are also required to come up with a separate implementation file (IntList.cpp) that implements the member functions of the IntList class. While developing your IntList class you must write your own test harness (within a file named main.cpp). Never implement...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT