Hi i am trying to think of how the algorithm of how this question works but no matter how hard i tried, i cant think of it. Can anyone give me a hand?? Any help or tip would be greatly appreciated.

Question:

Given 3 classes, equilateral triangle, isosceles triangle and right-angled
triangle, find the relationship in terms of inheritance among them and a
generic triangle class. Define each class’s data members and member
functions, making clear which are mutator, accessor, or virtual functions.
Write functions to calculate area and perimeter, sharing code as much as
possible.

Isosceles triangles have 2 equal sides, equilateral triangles have 3 equal sides. Therefore, what can be said about equilateral triangles? Determine whether or not there is a relationship between right angle triangles and either of the other two.

Write out your thoughts and someone will be able to tell you if they are correct.

hint

class triangle  {
 protected:
   virtual int perim()=0;
   virtual int area()=0;
   ~triangle();
 };

class equil : protected triangle {
   int a,b,c;
 public:
   equil (int,int,int);
   int perim();
   int area();
 };

class squared : protected triangle  {
   int a,b,c;
 public:
   squared (int,int,int);
   int perim();
   int area();
 };
commented: STOP doing this. -1
commented: You've been warned about this before. :( -1

OP, please cover your ears for a second. :)


caut_baia, you have been asked repeatedly not to give the answer away. This teaches the OP nothing. Please let me know what your difficulty is in understanding this.

well they come here in search of help not riddles .. if you want to play the dungeon master do your thing but that was just a hint.You should know better that people learn by example in a much more effective way.

That's enough. Our rules say:

Do provide evidence of having done some work yourself if posting questions from schoolwork assignments

This OP hasn't done this and doesn't deserve a ready-made answer. Now I know that you're answer isn't complete, but it's close enough.

read this [Observational_learning]

So you think someone will be able to learn from the code you posted without any explanation form your side? That's like giving someone a car and expecting them to know how it works just by looking at it.

Now here's another rule:

Do not post insults or personal attacks aimed at another member

You're currently very close to breaking it, so I suggest you lose the attitude and start playing by DW-rules from here.

And that's enough of the of-topic ramblings, if anyone would like to discuss this further, feel free to PM me.

commented: Give it to him Nick! +4

Thank you very much Nick.If i find myself in car with a virtual steering wheel .. i can lookup the internet to find out that i can virtualy steer left and right and so forth.. but anyway "My difficulty" is in understanding how can the statement "a triangle has three sides" help someone who is looking for a virtual functions and inheritance hint.What i wrote should just put him on tracks .. the go is up to himself.I'm sorry if i sounded offensive but he did too.My post should've looked something like this then "A triangle has three points dude .. i've just enlightened yourself and you're just one step from transcendence".

@OP (on-topic):
Class inheritance is based on a "base" or "general" cases/classes and "derived" or "specialized" cases/classes. The properties of the base class are designed in such a way that it applies to all objects of that class. Conversely, the derived classes are designed in such a way as to account for objects that have unique operations and abilities that apply to only that type of object, not all. For example

class Animal {
  public:
    virtual void Breathe();
};

class Dog : public Animal {
  public:
    virtual void Bark();
    virtual void Wag();
};

class Bulldog : public Dog {
  private:
    bool JawIsLocked;
}

A Bulldog is a type of Dog that has a jaw that can lock shut. As a Dog, it also has the ability to Bark and Wag it's tail. Additionally, as a Dog it is a type of Animal. As an animal, it has the ability to Breathe.

Given that general synopsis, think about the information below, pay careful attention to the language used:

Every triangle has a collection of dimensions. The primary ones being width and height. The area of a triangle is always found using the same formula area = (1/2) * width * height.

Additionally, every triangle has a total included angle of 180-degrees. If it's more than that, the polygon is open and there is no area.

Different types of triangles require different types of geometry and trigonometry to solve them. For example, you can only use Pythagoras's Theorem (c^2 = a^2 + b^2)to find the sides of a right triangle, but you can't for any other type of triangle. For those, you get into the trigonometric laws, such as The Law of Cosines.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.