So im trying to code this inheritance thing with Point, square and cube (for a homework). Thing is im having a problem: I want the class square to get the area from the 2 points (0,0) and (5,0) for example. But im currently stuck. I dont know what to put in int area and int volume. Im a beginner so it might be something very easy.
#include <iostream>
#include <math.h>
usingnamespace std;
class Point {
public:
int x1,y1;
void set_values (int x, int y)
{x1=x; y1=y;}
};
class Square: public Point {
public:
int area()
{return ;}
};
class Cube: public Square {
public:
int volume()
{return ;}
};
int main()
{
int cote;
cout << "Point, square and cube" << endl;
Point p1,p2;
Square square1;
Cube cube1;
p1.set_values(0,0);
p2.set_values(5,0);
cout <<square1.area() << endl;
cout <<cube1.volume() << endl;
}
Yes, thats why I put: p1.set_values(0,0); p2.set_values(5,0);
From there I could get the distance between the 2 points and get the area and the volume, but how to use the class point for square?
Error at line 16: Class Point has no member named 'x'
But thanks for the help, im getting closer (had a problem with lenght, tried to use pow function and didnt work properly.
NEVERMIND, I MANAGED TO GET IT (there was a small error on line 16 ((p2.x1 - p1.y1));}
Yea I solved it thank you very much! Now ill work on improving the program. For example, I would like the user to choose the coordinates of the 2 points.