Compare commits

..

2 Commits

Author SHA1 Message Date
Arkadiusz Hypki
c6e005ec1b 'Added C++ classes for the same task (Figure, Square...);' 2023-03-28 18:28:48 +02:00
Arkadiusz Hypki
2641e83667 Java related files moved to a separate folder; 2023-03-28 18:26:47 +02:00
18 changed files with 122 additions and 0 deletions

19
cpp/Figure.cpp Normal file
View File

@ -0,0 +1,19 @@
//
// Created by ahypki on 28.03.23.
//
#include "Figure.h"
namespace ahypki {
std::string Figure::getName() {
return this->name;
}
void Figure::setName(std::string newName) {
this->name = newName;
}
double Figure::computeArea() {
return 0.0;
}
} // ahypki

23
cpp/Figure.h Normal file
View File

@ -0,0 +1,23 @@
//
// Created by ahypki on 28.03.23.
//
#include <iostream>
#ifndef TESTCPPPROGOBIE_FIGURE_H
#define TESTCPPPROGOBIE_FIGURE_H
namespace ahypki {
class Figure {
private:
std::string name = "Unknown figure";
public:
std::string getName();
void setName(std::string newName);
virtual double computeArea();
virtual double pureVirtualComputeArea() = 0;
};
} // ahypki
#endif //TESTCPPPROGOBIE_FIGURE_H

32
cpp/Square.cpp Normal file
View File

@ -0,0 +1,32 @@
//
// Created by ahypki on 28.03.23.
//
#include "Square.h"
namespace ahypki {
Square::Square() {
setName("Square");
}
Square::Square(double x) {
setName("Square");
setX(x);
}
double Square::getX() {
return x;
}
void Square::setX(double newX) {
x = newX;
}
double Square::computeArea() {
return getX() * getX();
}
double Square::pureVirtualComputeArea() {
return getX() * getX();
}
} // ahypki

26
cpp/Square.h Normal file
View File

@ -0,0 +1,26 @@
//
// Created by ahypki on 28.03.23.
//
#include "Figure.h"
#ifndef TESTCPPPROGOBIE_SQUARE_H
#define TESTCPPPROGOBIE_SQUARE_H
namespace ahypki {
class Square : public Figure {
private:
double x;
public:
Square();
Square(double x);
void setX(double x);
double getX();
virtual double computeArea();
virtual double pureVirtualComputeArea();
};
} // ahypki
#endif //TESTCPPPROGOBIE_SQUARE_H

22
cpp/main.cpp Normal file
View File

@ -0,0 +1,22 @@
#include <iostream>
#include "Figure.h"
#include "Square.h"
int main() {
std::cout << "Hello, World!" << std::endl;
// ahypki::Figure figure = ahypki::Figure();
// std::cout << "Default name: " << figure.getName() << std::endl;
//
// figure.setName("Next name");
// std::cout << "New name: " << figure.getName() << std::endl;
ahypki::Square s = ahypki::Square(10);
std::cout << s.getName()
<< " has x= " << s.getX()
<< " has area= " << s.computeArea()
<< std::endl;
return 0;
}