1 object oriented programming class hierarchies

Assignment Help Application Programming
Reference no: EM13346891

1. Object Oriented Programming: Class hierarchies, inheritance and virtual functions

In this part of the assignment you are asked to develop a class structure that can be used to represent closed curves in a two-dimensional plane. Examples of such curves are rectangles, ellipses, squares, triangles, general polygons, etc. To limit the scope of the assignment, we will focus on four special types of curves: ellipses, circles, rectangles and squares. Moreover, we will only work with curves with axes that are parallel to the axes of the coordinate system. In the figure below, you see examples of these objects, as well as example of an object that is not allowed, since it is not parallel to the coordinate axis.

2470_Object Oriented Programming.png

Each object has a position, which can be represented by a coordinate in the (x,y) plane. For example, the place of a circle can be represented by the coordinate of its center. The place of a square can, e.g., be represented by the coordinate of its lower left corner. Further, each object has a size. The size of a circle can be represented by its radius, whereas two numbers are needed to represent the size of a rectangle - its lengths in the x and y direction respectively.

Moreover, there are several common fundamental properties that any closed curve has, e.g., an area and a circumference (i.e., the length of the curve).

It also has a parametric representation, which can be defined as a (non-unique) function p, which takes a number between 0 and 1 and
returns a coordinate, such that the whole curve can be "drawn" by plotting all p(a) for all a between 0 and 1. For example, a circle with center at (x,y) and radius r has the parametric representation p(a) = (x + rx*(2Πa),y + ry*(2Πa).


a) Define classes for a coordinate and for generic closed curves. You may use the following declarations if you wish

class coordinate
{
public:
coordinate() {}
coordinate(double xin,double yin) {x=xin;y=yin;}
double x;
double y;
};

class closedcurve
{
public:
closedcurve();
~closedcurve();
double area();
double circumference();
coordinate place(double a);
};


b) Define child classes ellipse, circle, rectangle and square. The class hierarchy should
be as follows:
class ellipse: public closedcurve
{ ...
}
class circle: public ellipse
{...
}
class rectangle: public closedcurve
{...
}
class square:public rectangle
{...
}

These definitions capture the fact that all these objects are closed curves, that a circle is a special case of an ellipse and that a square is a special case of a rectangle. Implement constructors and destructors, as well as the methods for area and circumference for each of these four object types. The formulas for these methods are standard (e.g., the area of a circle is Πr2 ), except for the formula for the circumference of an ellipse, which is nontrivial.

There are many methods to approximate the circumference of a general ellipse, with major radius of length a and minor radius of length b. One such formula, that you can use, is the so-called Hölder approximation, 4(as+ bs)1/s, where s = ln(2)/ ln? (Π/2)(feel free to use other approximations). Although this formula is, in fact, exact for the case where the ellipse is a circle, the precision will be much lower than the standard formula for the circle's circumference, 2Πr. You are therefore recommended to use the latter formula for circle objects.

c) Implement the method, coordinate place(double a), for the parametric representation, which takes a number between 0 and 1, and returns the coordinate of the curve, for each of the four types of objects. The formulas for rectangles and squares are easy and the formula for the circle was described above. For the ellipse, one parameterization is:

p(a) = (x + rx*(2Πa),y + ry*(2Πa)), where rx and ry are the radiuses in the x and y direction respectively.

d) Add a method void printcurve(int N,char Name[]) to the closedcurve class, which takes a number of points, N, and a file name, Name, as arguments and outputs (x,y) coordinates for N points on the curve to a file with name "Name." For example, in the figures below, the resulting points from a square and a circle were printed to files, using N=200 points. The points were then imported to Excel, and shown using a scatter chart.

When implementing the method, use the ofstream class.

Remember to add #include <fstream> and using namespace std; in the header.

If you have implemented your class hierarchy correctly you should only have to write one method, which works for any object of type closedcurve.

1319_Object Oriented Programming1.png

 
e) Implement a less-than (<) operator for the class that compares the area of one curve to another. As with printcurve above, you should only need to implement a single method.

f) Write a program that uses the curve class hierarchy. The program should define several different objects, output their area, circumference, etc. It should also use the printcurve function. Please provide charts of a couple of objects, similar to the ones above.

g) Incorporate virtual functions to get late binding of objects (if you haven't done so yet). Write a program that asks the user what type of object is needed, e.g., a circle or a square, and then calculates the area of that object. In the spirit of true polymorphism, only one
object should be defined in the program. You are allowed to use terminal input and output in this exercise.

Reference no: EM13346891

Questions Cloud

Theory of interest- non-annual interest rates and : theory of interest- non-annual interest rates and annuitiesfind the annual effective rate of interest equivalent to a
Describe concepts of database-orientated programming : describe concepts of database-orientated programming language plsql as well as of data analysis techniques for
Scanning and parsingimplement the lexical and syntactic : scanning and parsingimplement the lexical and syntactic analysis of minifun programming language. the scanner splits up
Question 1which of the following statements is true for a : question 1which of the following statements is true for a trapdoor function f?answer a.the function f can be computed
1 object oriented programming class hierarchies : 1. object oriented programming class hierarchies inheritance and virtual functions in this part of the assignment you
Describe and evaluate this type of internal audit what : describe and evaluate this type of internal audit. what types of organisation would it be most useful for?required1
Build the gui layout of the gamecreate a class called : build the gui layout of the gamecreate a class called pipegameapp.java which will be the main game user interface. the
Offered a 20 million commercial loan priced using a 3month : offered a 20 million commercial loan priced using a 3month libor index100bp. after some preliminary research using a
Analyze the processed data in statistical survey below are : analyze the processed data in statistical survey. below are the results of the processed data.question 1 yes p 0.1986

Reviews

Write a Review

Application Programming Questions & Answers

  In this project you will create an application to run in

in this project you will create an application to run in the amazon ec2 service and you will also create a client that

  Imagine that your company has decided to expand to the web

imagine that your company has decided to expand to the web. you want to reuse some data entry code that has been

  1 here is a short program it prints out the value of a

1. here is a short program. it prints out the value of a variable x. ernie and bert disagree about what will be printed

  If the user wants to read the input from a file then the

if the user wants to read the input from a file then the output will also go into a different file. if the user wants

  Question 1we are given the following knowledge base of

question 1we are given the following knowledge base of travel informationnbspbycaraucklandhamilton.

  Basic requirementsscreen one has three edittext views and

basic requirementsscreen one has three edittext views and one button.the edittext views allow you to enter a students

  Create a application using the mvc architecture no

create a application using the mvc architecture. no scripting elements are allowed in jsp

  Rtl sa is a company which develops bespoke solutions for

rtl sa is a company which develops bespoke solutions for the rubber industry. they produce both rubber compound which

  Design a program that models the worms behavior in the

design a program that models the worms behavior in the subsequent scenarioa worm is moving toward an apple. each time

  Problem build a class for a type called fractionnbspthis

problem build a class for a type called fraction.nbspthis class is used to show a ration of two integers.nbsp include

  Part - 1 object-oriented designwrite a program that allows

part - 1 object-oriented designwrite a program that allows an instructor to keep a grade book. each students has scores

  Soda vending machine designnbsp design a soda vending

soda vending machine designnbsp design a soda vending machine that can deliver three kinds of soda a b and c. allnbsp

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