This is my first ever OO program so please don't judge me lol. This program is meant to print out the area of a rectangle and triangle with the same width and height. I feel that my classes are correct, but i have no idea how to use them in the main. Thanks for the help in advance :)
Here is the task im trying to complete,
Write a program with a mother class and an inherited daugther class.Both of them should have a method void display ()that prints a message (different for mother and daugther).In the main define a daughter and call the display() method on it.
// OOP exercises.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
usingnamespace std;
class shape {
public:
shape(int height, int width) {
height = 5;
width = 4;
}
};
class rectangle {
public:
int area(int height, int width) {
int area = height * width;
cout << area << endl;
}
};
class triangle {
public:
int area(int height, int width) {
int area = height * width / 2;
cout << area << endl;
}
};
int main()
{
triangle obj;
rectangle myObj;
return 0;
}
#include <iostream>
class Shape
{
private:
int w, h;
public:
private:
Shape(int width, int height)
{
w = width;
h = height;
}
};
class Rectangle
{
public:
Rectangle(int width, int height) : Shape(width, height)
{
}
int area()
{
return width * height;
}
};
/*Do Triangle class in a similar way, only change the formula for the area*/
int main()
{
Rectangle rect(5, 4);
std::cout << rect.area();
}