Hi,
I'm new here and pretty new to c++ and programming in general.
During one of my first excercises I tried to work with classes but I don't know how to output an class object in another class.
Here is my Code with the text in [] (Circle.cpp) where I'm stuck.
Would be great if anyone could help.
Thanks
Point.h
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Point
{
private:
int X;
int Y;
public:
Point();
Point(int, int);
~Point();
int getX();
int getY();
void setX(int);
void setY(int);
void Print();
};
Shapes.h (BASE)
#pragma once
#include <iostream>
#include <string>
using namespace std;
class Shapes
{
protected:
string name;
public:
Shapes();
Shapes(string);
~Shapes();
string getName();
void setName(string);
void Print();
};
Circle.h
#pragma once
#include <iostream>
#include <string>
#include "Point.h"
using namespace std;
class Circle: public Shape
{
private:
Circle Middle;
double Radius;
public:
Circle();
Circle(string);
~Circle();
void Print();
void SetPointRadius(Circle,double);
};
Point.cpp
#include <iostream>
#include <string>
#include "Shapes.h"
using namespace std;
Point::Point() {
X = 0;
Y = 0;
}
Point::Point(int X_, int Y_) {
X = X_;
Y = Y_;
}
Point::~Point() {
}
int Point::getX() {
return X;
}
int Point::getY() {
return Y_;
}
void Point::setX(int X_) {
X = X_;
}
void Point::setY(int Y_) {
Y = Y_;
}
void Point::Print() {
cout << "X: " << X << endl;
cout << "Y: " << Y << endl;
}
Circle.cpp
#include <iostream>
#include <string>
#include "Shapes.h"
#include "Circle.h"
using namespace std;
Circle::Circle() {
Radius = 0;
}
Circle::Circle(string name_) {
name = name_;
}
Circle::~Circle() {
}
void Circle::Print() {
[ Output: Shapes::Print() ] // void Shapes::Print() {cout << "Name is: " << name << endl;}
cout << "Point: " << endl;
[ Output: Point::getX() ] // int Point::getX() {return X;}
[ Output: Point::getY() ] // int Point::getY() {return Y;}
cout << endl;
cout << "Radius: " << Radius << endl;
}
void CKreis::SetPointRadius(CPunkt Mitte, double Radius) {
PMitte = Mitte;
myRadius = Radius;
}
Main.cpp
#include <iostream>
#include "Shapes.h"
#include "Circle.h"
#include "Point.h"
using namespace std;
int main() {
Circle C ("Circle 1");
Point P1(1, 3);
double Radius = 2.5;
P1.SetPointRadius(P1, Radius);
P1.Print();
cout << endl;
}