Compare commits
2 Commits
b0458db743
...
c6e005ec1b
Author | SHA1 | Date | |
---|---|---|---|
|
c6e005ec1b | ||
|
2641e83667 |
19
cpp/Figure.cpp
Normal file
19
cpp/Figure.cpp
Normal 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
23
cpp/Figure.h
Normal 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
32
cpp/Square.cpp
Normal 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
26
cpp/Square.h
Normal 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
22
cpp/main.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user