Define a class named circle

Assignment Help Basic Computer Science
Reference no: EM13215189

Define a pure abstract base class called BasicShape. The BasicShape class should have the following members:

Private Member Variable:

area, a double used to hold the shape s area.

Public Member Functions:

getArea. This function should return the value in the member variable area.
calcArea. This function should be a pure virtual function.

Next, define a class named Circle. It should be derived from the BasicShape class. It should have the following members:

Private Member Variables:

centerX, a long integer used to hold the x coordinate of the circle s center.
centerY, a long integer used to hold the y coordinate of the circle s center.
radius, a double used to hold the circle s radius.

Public Member Functions:

constructor accepts values for centerX, centerY, and radius. Should call the
overridden calcArea function described below.
getCenterX returns the value in centerX.
getCenterY returns the value in centerY.
calcArea calculates the area of the circle (area = 3.14159 * radius * radius) and stores the result in the inherited member area.

Next, define a class named Rectangle. It should be derived from the BasicShape class. It should have the following members:

Private Member Variables:

width, a long integer used to hold the width of the rectangle.
length, a long integer used to hold the length of the rectangle.

Public Member Functions:
constructor accepts values for width and length. Should call the overridden
calcArea function described below.

getWidth returns the value in width.
getLength returns the value in length.
calcArea calculates the area of the rectangle (area = length * width) and stores the result in the inherited member area.

After you have created these classes, create a driver program that defines a Circle object and a Rectangle object. Demonstrate that each object properly calculates and reports its area.

Starter: lab14_ex1_starter.cpp

Submit: lab14_ex1.cpp

lab14_ex1_starter.cpp is

// Chapter 13, Programming Challenge 13: Pure Abstract Base Class Project

// Driver program is used to test the BasicShape (Abstract Base Class), Circle
// (Derived Class) and Rectangle (Derived class).
// The program asks for needed information for both a circle and rectangle and
// returns the area.

#include <iostream>

using namespace std;

class BasicShape
{

};

class Circle : public BasicShape
{

};

class Rectangle : public BasicShape
{

};

int main()
{
long x, y, length, width;
double rad;

// Demonstrate a Circle.
cout << "Please enter the x coordinate of the circle's center: ";
cin >> x;
cout << "Please enter the y coordinate of the circle's center: ";
cin >> y;
cout << "Please enter the radius of the circle: ";
cin >> rad;
Circle c(x,y,rad);
cout << "The area of the circle is " << c.getArea() << ".";

// Demonstrate a Rectangle.
cout << "nnPlease enter the length of the rectangle: ";
cin >> length;
cout << "Please enter the width of the rectangle: ";
cin >> width;
Rectangle r(width, length);
cout << "The area of the rectangle is " << r.getArea() << ".n";

return 0;
}

 

Reference no: EM13215189

Questions Cloud

Use a random-number generator to pick each card : Your program must incorporate a two-dimensional array to represent the suit and the value of each card dealt to a player, keep track of which cards have been dealt to which player, and use a random-number generator to pick each card to be dealt to..
What will be callies initial capital balance : Callie is admitted to the Adams & Beal Partnership under the bonus method. Callie contributes cash of $20,000 and non-cash assets with a market value of $30,000 and book value of $15,000 in exchange for a 20% ownership interest in the new partners..
Explain what does this indicate the firm''s expected ebitda : Assume that in five years, DigiVault will have an expected exit enterprise value of $48 million, based on an EBITDA multiple of 5.0 from similar exit transactions. What does this indicate the firm's expected EBITDA will be at that time?
Pricing a first to default derivative : Examine the sensitivity of your answers as you vary the number of simulations from 1000, 10,000, 100,000 and 250,000, Pricing a Second to Default Derivative - Pricing a Second to Default Derivative
Define a class named circle : Define a pure abstract base class called BasicShape. The BasicShape class should have the following members.
Show on the console the sum of all non-inherited data member : show on the console the sum of all non-inherited data members of every instance in the program by Display() function.
Prepare all entries required to properly record the sale : On April 1, 2014, West Company purchased $476,000 of 5.25% bonds for $494,790 plus accrued interest as an available-for-sale security. Interest is paid on July 1 and January 1 and the bonds mature on July 1, 2019.
What are the main disadvantages of hypermedia : What are the main disadvantages of hypermedia when compared with conventional media such as books and videos?
How could the company have reduced the costs : In a recent year, an oil refinery in Texas City, Texas, on the Houston Ship Channel exploded. The explosion killed 14 people and sent a plume of smoke hundreds of feet into the air. The blast started as a fire in the section of the plant that incr..

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Explain change like that for business purposes

This adaptation of gaming by seniors was due in large part to ease of use. The Wii controller changed everything. Take a look at the news article and imagine a change like that for business purposes. Will it happen?

  Random string of 100,000 characters is written

A random string of 100,000 characters is written down, where each character is independently, equally likely to be any of the upper-case letters A through Z in English.

  Incorporate the method into an application that reads

Incorporate the method into an application that reads two value from the user and displays the result

  Explain why companies get better results-information system

Using three components of information systems and complementary assets concepts, explain why some companies achieve better results with information systems than others.

  Structured and object-oriented designs

Structured and object-oriented designs are the two main contenders for programming methodologies relevant to the creation of documentation for application programs. The choice of methodologies will greatly affect how we approach the challenge and ..

  A direct-mapped cache with 8 two-word blocks

Based on the following sequence of word addresses generated by the processor:1, 134, 212, 1, 135, 213, 162, 161, 2, 44, 41, 221a) Given a direct-mapped cache with 8 two-word blocks that is initially empty

  How many times new flash drive is bigger than old

The program asks the speed v in km/h and transforms it to m/s. Please solve one program ...C , Java it doesnt matter

  Problem of traveling from one city to another

Describe how the problem of traveling from one city to another could be framed as a production system. What are the states? What are the productions?

  Determine present worth-future worth of soldering machine

The initial cost is in week 0 and the payments are in years 1-4. Determine the present worth, future worth, and annual worth for.

  Hierarchy chart and then plan the logic

Draw the hierarchy chart and then plan the logic for a program needed by the sales manager of The Henry Used Car Dealership. The program will determine the profit on any car sold

  Consider the following code fragment

Consider the following code fragment: for (int i = 0; i = 0; j--) { System.out.println(i + " " + j); } } How would i revise this fragment to output this: 0 0 1 1 1 0 2 2 2 1 2 0 3 3 3 2 3 1 3 0

  What these three things(rob, rs, rsr) explain

What these three things(ROB, RS, RSR)  explain  ?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd