consolidate all repos to one for archive
This commit is contained in:
40
semester_2/programiranje_2/primeri/Example02/Point.cpp
Normal file
40
semester_2/programiranje_2/primeri/Example02/Point.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include "Point.h"
|
||||
|
||||
Point::Point() : x(0), y(0) {
|
||||
}
|
||||
|
||||
Point::Point(const Point& t) : x(t.x), y(t.y) {
|
||||
}
|
||||
|
||||
Point::Point(int xy) : x(xy), y(xy) {
|
||||
}
|
||||
|
||||
Point::Point(int xx, int yy) {
|
||||
//Point::Point(int x, int y) {
|
||||
//Point::Point(int x, int y) : x(x), y(y) {
|
||||
x=xx;
|
||||
y=yy;
|
||||
//this->x=x;
|
||||
//this->y=y;
|
||||
}
|
||||
|
||||
Point::~Point() {
|
||||
}
|
||||
|
||||
int Point::getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
int Point::getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
void Point::print() {
|
||||
std::cout << "(" << x << ", " << y << ") " << std::endl;
|
||||
}
|
||||
|
||||
double Point::distance(Point t) {
|
||||
return std::sqrt((double)(x - t.x)*(x - t.x)+(y - t.y)*(y - t.y));
|
||||
}
|
20
semester_2/programiranje_2/primeri/Example02/Point.h
Normal file
20
semester_2/programiranje_2/primeri/Example02/Point.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef EXAMPLE02_POINT_H
|
||||
#define EXAMPLE02_POINT_H
|
||||
|
||||
class Point {
|
||||
private:
|
||||
int x, y;
|
||||
public:
|
||||
Point(); // default constructor is needed when other than copy constructor is defined
|
||||
Point(const Point& t); // copy constructor
|
||||
Point(int xy); // conversion constructor
|
||||
Point(int x, int y); // other constructor
|
||||
~Point(); // destructor
|
||||
// methods
|
||||
int getX();
|
||||
int getY();
|
||||
void print();
|
||||
double distance(Point t);
|
||||
};
|
||||
|
||||
#endif //EXAMPLE02_POINT_H
|
39
semester_2/programiranje_2/primeri/Example02/main.cpp
Normal file
39
semester_2/programiranje_2/primeri/Example02/main.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <iostream>
|
||||
#include "Point.h"
|
||||
|
||||
int main() {
|
||||
Point a;
|
||||
Point b(5);
|
||||
Point c(4,3);
|
||||
Point d(c);
|
||||
a.print();
|
||||
b.print();
|
||||
c.print();
|
||||
d.print();
|
||||
std::cout << a.distance(c) << std::endl;
|
||||
//std::cout << a.distance(5) << std::endl;
|
||||
/*
|
||||
Point arr[3]; // default constructor is called
|
||||
for (int i=0; i < 3; i++)
|
||||
arr[i].print();
|
||||
*/
|
||||
/*
|
||||
std::cout << "-----Dynamic allocation-----" << std::endl;
|
||||
Point* e = new Point();
|
||||
Point* f = new Point(5);
|
||||
Point* g = new Point(2,3);
|
||||
Point* h = new Point(*g);
|
||||
//e.print();
|
||||
//*e.print();
|
||||
//(*e).print();
|
||||
e->print();
|
||||
f->print();
|
||||
g->print();
|
||||
h->print();
|
||||
delete e;
|
||||
delete f;
|
||||
delete g;
|
||||
delete h;
|
||||
*/
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user