Suppose a class polygon has been defined as follows:
1. Data member defined to be available to descendants
• The length coordinate of the polygon.
• The width coordinate of the polygon.
• Print info() declare as Constant, to print (l,w) coordinate explicitly; use the dereferences this pointer and the dot operator to access the member.
-Define a class Triangle that inherits from class polygon; that contains the methods/data members as following:
Triangle
-height : int
“ constructor ”+ Triangle(w: int,int h)
+setheight(h : int )
+getheight ():int “const”
+printinfo()
+area():int
-Write main code in order to test your work with:
A. constant object
B. non constant object
Hint:
Rectangle area=(length*width)
Triangle area= (length*height)/2
i wish at least you give me the main idea and how suppose it is work
Please note, that it is not a homework site. We won't do your homework for you. However we are always willing to help solve problems you encountered, correct mistakes you made in your code and answer your questions.
We didn't see your attemts to solve this youself and so we cannot correct mistakes you didn't made and answer questions you didn't ask. To get help you should do something yourself and get real problems with something. If your problem is "I don't understand a thing", then you should go back to basics and study again. As it is impossible to find deriviative of function without knowledge in ariphmetics, you cannot do more complex tasks in programming without clear understanding of basics
Your assigment clearly states what do you need to do. It deals with basic stuff you should know if you attend any lessons.
And please, do not crosspost your questions across different subforums. It clutters them; annoys people and makes them less likely to help you.
int get_length() const {return length;}
int get_width() const {return width;}
+print info()
• Print info() declare as Constant, to print (l,w) coordinate explicitly; use the dereferences this pointer and the dot operator to access the member.
#include <iostream>
#include "polygon.h"
using namespace std ;
class tringle: public polygon
{
private:
int height;
public:
tringle (int w , int h);
void setheight (int h);
int getheight (); const
void printinfo ();
int area ();
};
_______________________________________
#include <iostream>
#include "polygon.h"
#include "tringle.h"
using namespace std ;