1
0
forked from s444409/POB_2019

Compare commits

..

7 Commits

Author SHA1 Message Date
78901ce84f added figures for Windows 2019-05-13 20:54:13 +02:00
f018058248 added java & fixed z7 2019-05-13 14:46:30 +02:00
d9bc3c5fa4 added java & fixed z7 2019-05-13 14:44:34 +02:00
1287b0deaa added java & fixed z7 2019-05-13 14:42:48 +02:00
Marcin Kostrzewski
be1ce93864 Added z7" 2019-05-05 21:01:16 +02:00
4fc3b7661f added java2 2019-04-14 13:42:06 +02:00
14a1b7186c added java 2019-04-14 12:05:09 +02:00
44 changed files with 846 additions and 18 deletions

27
Figures/Makefile Normal file
View File

@ -0,0 +1,27 @@
TARGET := figures
BUILD_DIR := bin
SRC_DIR := source
INC_DIR := include
SRCS := $(shell find $(SRC_DIR) -name *.cpp)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
INC_FLAGS := $(addprefix -I,$(INC_DIR))
CPPFLAGS := $(INC_FLAGS) --std=c++14
$(BUILD_DIR)/$(TARGET): $(OBJS)
echo $(LDFLAGS)
$(CXX) $(OBJS) -o $@ $(LDFLAGS)
$(BUILD_DIR)/%.cpp.o: %.cpp
mkdir -p $(dir $@)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)/*

BIN
Figures/bin/a.exe Normal file

Binary file not shown.

13
Figures/include/Circle.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "Figure.h"
#include <string>
class Circle : public Figure {
public:
float r;
Circle();
Circle(float _r);
virtual std::string type() const;
virtual float area() const;
};

9
Figures/include/Figure.h Normal file
View File

@ -0,0 +1,9 @@
#pragma once
#include <string>
class Figure {
public:
virtual std::string type() const = 0;
virtual float area() const = 0;
};

View File

@ -0,0 +1,13 @@
#pragma once
#include "Figure.h"
#include <string>
class Rectangle : public Figure {
public:
float w,h;
Rectangle();
Rectangle(float _w, float _h);
virtual std::string type() const;
virtual float area() const;
};

19
Figures/source/Circle.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "../include/Circle.h"
#include <string>
#define PI 3.141592653589793238463
using namespace std;
Circle::Circle(){r=0;}
Circle::Circle(float _r){r=_r;}
string Circle::type() const {
return "Circle";
}
float Circle::area() const {
return PI * r * r;
}

View File

@ -0,0 +1,16 @@
#include "../include/Rectangle.h"
#include <string>
using namespace std;
Rectangle::Rectangle() : w(0), h(0) {}
Rectangle::Rectangle(float _w, float _h) : w(_w), h(_h) {}
string Rectangle::type() const {
return "Rectangle";
}
float Rectangle::area() const {
return w * h;
}

18
Figures/source/main.cpp Normal file
View File

@ -0,0 +1,18 @@
#include "../include/Circle.h"
#include "../include/Rectangle.h"
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector<Figure*> figures = {
(Figure*)new Rectangle(10, 2),
(Figure*)new Rectangle(3, 3),
(Figure*)new Circle(5),
(Figure*)new Circle(1)
};
for (Figure *f : figures) {
cout << f->type() << ": area = " << f->area() << "\n";
}
return 0;
}

View File

@ -0,0 +1,11 @@
package POB_2019.Java.zad1_1;
public class Przedmiot {
private String subjectName;
public Przedmiot(String name){
this.subjectName=name;
}
public String toString(){
return this.subjectName + "JEchane";
}
}

16
Java/zad1_1/zad1_1.java Normal file
View File

@ -0,0 +1,16 @@
package POB_2019.Java.zad1_1;
import java.util.ArrayList;
import java.util.List;
public class zad1_1 {
public static void main(String[] args) {
List<Przedmiot> subjects = new ArrayList<Przedmiot>();
subjects.add(new Przedmiot("Ball"));
subjects.add(new Przedmiot("Chair"));
subjects.add(new Przedmiot("Table"));
for(Przedmiot p : subjects){
System.out.println(p);
}
}
}

27
Java/zad1_2/Vector2D.java Normal file
View File

@ -0,0 +1,27 @@
package POB_2019.Java.zad1_2;
public class Vector2D {
private int x, y;
public Vector2D(int _x, int _y){
this.x=_x;
this.y=_y;
}
public Vector2D add(Vector2D vec2){
int newX, newY;
newX=this.x + vec2.x;
newY=this.y + vec2.y;
return new Vector2D(newX, newY);
}
public Vector2D substract(Vector2D vec2){
int newX, newY;
newX=this.x - vec2.x;
newY=this.y - vec2.y;
return new Vector2D(newX, newY);
}
public double multiply(Vector2D vec2){
return (this.x*vec2.x + this.y*vec2.y);
}
public String toString(){
return String.format("[%s, %s]", this.x, this.y);
}
}

14
Java/zad1_2/zad1_2.java Normal file
View File

@ -0,0 +1,14 @@
package POB_2019.Java.zad1_2;
public class zad1_2 {
public static void main(String[] args){
Vector2D vec1 = new Vector2D(5, 11);
Vector2D vec2 = new Vector2D(-2, 4);
Vector2D vec3 = vec1.add(vec2);
Vector2D vec4 = vec2.substract(vec1);
double multiplicationResult = vec2.multiply(vec1);
System.out.println(vec3);
System.out.println(vec4);
System.out.println(multiplicationResult);
}
}

29
Java/zad2_1/Koszyk.java Normal file
View File

@ -0,0 +1,29 @@
package POB_2019.Java.zad2_1;
import java.util.List;
import java.util.ArrayList;
public class Koszyk {
private List<Produkt> products = new ArrayList<Produkt>();
private String name;
public Koszyk(String _name){
this.name=_name;
}
public void addProduct(Produkt product){
products.add(product);
}
private float totalCost(){
float sum=0;
for(Produkt p : products)
sum+=p.getPrice();
return sum;
}
public String toString(){
String fullDesc="Koszyk " + this.name + ":\n";
for(Produkt p : products)
fullDesc = fullDesc + p.toString();
fullDesc = fullDesc + "Total: " + totalCost() + "\n";
return fullDesc;
}
}

17
Java/zad2_1/Produkt.java Normal file
View File

@ -0,0 +1,17 @@
package POB_2019.Java.zad2_1;
public class Produkt {
private String name;
private float price;
public Produkt(String _name, float _price){
this.name=_name;
this.price=_price;
}
public String toString(){
return String.format("Nazwa: %s\nCena: %.2f\n\n", this.name, this.price);
}
public float getPrice(){
return this.price;
}
}

11
Java/zad2_1/zad2_1.java Normal file
View File

@ -0,0 +1,11 @@
package POB_2019.Java.zad2_1;
public class zad2_1 {
public static void main(String[] args){
Koszyk cart1 = new Koszyk("Marcin");
cart1.addProduct(new Produkt("Banan", 3.19f));
cart1.addProduct(new Produkt("Ananas", 5.69f));
cart1.addProduct(new Produkt("Pomarańcza", 2.99f));
System.out.println(cart1);
}
}

View File

@ -0,0 +1,18 @@
package POB_2019.Java.zad3_1;
import java.io.FileWriter;
import java.io.IOException;
public class FileLogger extends Logger {
private FileWriter fileWriter;
public FileLogger() throws IOException {
String fileName = "./log.txt";
this.fileWriter = new FileWriter(fileName);
}
@Override
public void log(String textToLog) throws IOException {
this.fileWriter.append(textToLog);
this.fileWriter.append("\n");
fileWriter.flush();
}
}

7
Java/zad3_1/Logger.java Normal file
View File

@ -0,0 +1,7 @@
package POB_2019.Java.zad3_1;
import java.io.IOException;
public class Logger {
public void log(String textToLog) throws IOException{};
}

View File

@ -0,0 +1,8 @@
package POB_2019.Java.zad3_1;
public class StdoutLogger extends Logger {
@Override
public void log(String textToLog){
System.out.println(textToLog);
}
}

20
Java/zad3_1/zad3_1.java Normal file
View File

@ -0,0 +1,20 @@
package POB_2019.Java.zad3_1;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
public class zad3_1 {
public static void main(String[] args) throws IOException {
Logger log1 = new StdoutLogger();
Logger log2 = new FileLogger();
List<String> texts = new ArrayList<String>();
texts.add("Jechane");
texts.add("ASDSAD");
texts.add("Jechane1");
for(String text : texts){
log1.log(text);
log2.log(text);
}
}
}

24
Jerzy/Okno.java Normal file
View File

@ -0,0 +1,24 @@
package POB_2019.Jerzy;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.*;
public class Okno extends JFrame {
public Okno(){
super("Moje okno");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setPreferredSize(new Dimension(500,500));
setLocation(100,100);
setVisible(true);
}
@Override
public void paintComponents(Graphics g){
super.paintComponents(g);
Graphics g2 = (Graphics2D) g;
g2.drawOval(10,10, 490, 490);
g2.drawRect(100,100, 400, 400);
setVisible(true);
}
}

13
Jerzy/main.java Normal file
View File

@ -0,0 +1,13 @@
package POB_2019.Jerzy;
import java.awt.EventQueue;
public class main {
public static void main (String[] args){
EventQueue.invokeLater(new Runnable(){
public void run(){
new Okno();
}
});
}
}

BIN
Kolokwium 15.04/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,2 @@
geometry: geometry.cpp
g++ --std=c++14 $< -o $@

View File

@ -0,0 +1,57 @@
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
class Geometry {
public:
virtual string type()=0;
virtual float volume()=0;
};
class Box : public Geometry {
private:
int dimX, dimY, dimZ;
public:
Box(int _dimX, int _dimY, int _dimZ){
dimX=_dimX;
dimY=_dimY;
dimZ=_dimZ;
}
virtual string type(){
return "Box";
}
virtual float volume(){
return(dimX*dimZ*dimY);
}
};
class Ball : public Geometry {
private:
int radius;
public:
Ball(int _radius){
radius=_radius;
}
virtual string type(){
return "Ball";
}
virtual float volume(){
return (float)4/3*M_PI*pow(radius, 3);
}
};
int main()
{
vector<Geometry*> geometries = {
(Geometry*)new Box(10, 2, 3),
(Geometry*)new Box(3, 3, 1),
(Geometry*)new Ball(5),
(Geometry*)new Ball(1)
};
for (Geometry *f : geometries) {
cout << f->type() << ": volume = " << f->volume() << "\n";
}
return 0;
}

View File

@ -0,0 +1,56 @@
#!/usr/bin/env python3
class Owner():
def __init__(self, _name, _surname):
self.name=_name
self.surname=_surname
def __str__(self):
return "%s %s" % (self.name, self.surname)
class Car(Owner):
def __init__(self, _brand, _owner):
self.brand=_brand
self.owner=_owner
def __str__(self):
return "%s, %s %s" % (self.brand, self.owner.name, self.owner.surname)
class Parking(Car):
def __init__(self, _parkingSpaces):
self.cars=[]
self.parkingSpaces=_parkingSpaces
def addCar(self, car):
if len(self.cars)>=self.parkingSpaces:
return;
else:
self.cars.append(car)
def removeCar(self, selectedCar):
if selectedCar in self.cars:
self.cars.remove(selectedCar)
def count(self):
return str(len(self.cars))
def freePlaces(self):
return str(self.parkingSpaces-len(self.cars))
def __str__(self):
sStream=''
sStream=sStream + str(len(self.cars)) + ' cars:\n'
for car in self.cars:
sStream=sStream + str(car) + '\n'
return sStream
parking = Parking(3)
owner1 = Owner("Jan", "Sienkiewicz")
owner2 = Owner("Marek", "Kowalski")
car1 = Car("Renault", owner1)
car2 = Car("BMW", owner2)
car3 = Car("Opel", owner1)
car4 = Car("Mercedes", owner1)
parking.addCar(car1)
parking.addCar(car2)
parking.addCar(car3)
parking.addCar(car4)
parking.removeCar(car3)
parking.addCar(car4)
print(parking)

Binary file not shown.

BIN
Kolokwium 15.04/zad1 Executable file

Binary file not shown.

57
Kolokwium 15.04/zad1.cpp Normal file
View File

@ -0,0 +1,57 @@
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;
class Geometry {
public:
virtual string type()=0;
virtual float volume()=0;
};
class Box : public Geometry {
private:
int dimX, dimY, dimZ;
public:
Box(int _dimX, int _dimY, int _dimZ){
dimX=_dimX;
dimY=_dimY;
dimZ=_dimZ;
}
virtual string type(){
return "Box";
}
virtual float volume(){
return(dimX*dimZ*dimY);
}
};
class Ball : public Geometry {
private:
int radius;
public:
Ball(int _radius){
radius=_radius;
}
virtual string type(){
return "Ball";
}
virtual float volume(){
return (float)4/3*M_PI*pow(radius, 3);
}
};
int main()
{
vector<Geometry*> geometries = {
(Geometry*)new Box(10, 2, 3),
(Geometry*)new Box(3, 3, 1),
(Geometry*)new Ball(5),
(Geometry*)new Ball(1)
};
for (Geometry *f : geometries) {
cout << f->type() << ": volume = " << f->volume() << "\n";
}
return 0;
}

56
Kolokwium 15.04/zad2.py Normal file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env python3
class Owner():
def __init__(self, _name, _surname):
self.name=_name
self.surname=_surname
def __str__(self):
return "%s %s" % (self.name, self.surname)
class Car(Owner):
def __init__(self, _brand, _owner):
self.brand=_brand
self.owner=_owner
def __str__(self):
return "%s, %s %s" % (self.brand, self.owner.name, self.owner.surname)
class Parking(Car):
def __init__(self, _parkingSpaces):
self.cars=[]
self.parkingSpaces=_parkingSpaces
def addCar(self, car):
if len(self.cars)>=self.parkingSpaces:
return;
else:
self.cars.append(car)
def removeCar(self, selectedCar):
if selectedCar in self.cars:
self.cars.remove(selectedCar)
def count(self):
return str(len(self.cars))
def freePlaces(self):
return str(self.parkingSpaces-len(self.cars))
def __str__(self):
sStream=''
sStream=sStream + str(len(self.cars)) + ' cars:\n'
for car in self.cars:
sStream=sStream + str(car) + '\n'
return sStream
parking = Parking(3)
owner1 = Owner("Jan", "Sienkiewicz")
owner2 = Owner("Marek", "Kowalski")
car1 = Car("Renault", owner1)
car2 = Car("BMW", owner2)
car3 = Car("Opel", owner1)
car4 = Car("Mercedes", owner1)
parking.addCar(car1)
parking.addCar(car2)
parking.addCar(car3)
parking.addCar(car4)
parking.removeCar(car3)
parking.addCar(car4)
print(parking)

1
POB_Java/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.class

BIN
POB_Java/Employee.class Normal file

Binary file not shown.

45
POB_Java/Employee.java Normal file
View File

@ -0,0 +1,45 @@
import java.io.*;
public class Employee {
String name;
int age;
String designation;
double salary;
// This is the constructor of the class Employee
public Employee(String name) {
this.name = name;
}
// Assign the age of the Employee to the variable age.
public void empAge(int empAge) {
age = empAge;
}
/* Assign the designation to the variable designation.*/
public void empDesignation(String empDesig) {
designation = empDesig;
}
/* Assign the salary to the variable salary.*/
public void empSalary(double empSalary) {
salary = empSalary;
}
/* Print the Employee details */
public void printEmployee() {
System.out.println("Name:"+ name );
System.out.println("Age:" + age );
System.out.println("Designation:" + designation );
System.out.println("Salary:" + salary);
}
public void compare(Employee emp){
if(emp.salary > this.salary){
System.out.println("Second employee earns more.");
} else if (emp.salary < this.salary){
System.out.println("First employee earns more.");
} else {
System.out.println("Both employees earn the same ammount.");
}
}
}

Binary file not shown.

View File

@ -0,0 +1,10 @@
public class Employee_main{
public static void main(String []args){
Employee emp1=new Employee("Marcin");
emp1.salary=1500;
Employee emp2=new Employee("Tomasz");
emp2.salary=1900;
emp1.compare(emp2);
}
}

View File

@ -1,9 +0,0 @@
cpp1
cpp2
ilovecpp
linuxoverwindows
123
456
789
abc
qwe

View File

@ -1,9 +0,0 @@
cpp1
cpp2
ilovecpp
linuxoverwindows
123
456
789
abc
qwe

BIN
zad2_2

Binary file not shown.

BIN
zad3_1

Binary file not shown.

BIN
zad5_1

Binary file not shown.

73
zad6_1.cpp Normal file
View File

@ -0,0 +1,73 @@
#include <vector>
#include <cstdio>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
class Shape
{
public:
virtual void draw(Mat &img) = 0;
};
class Circle : public Shape
{
public:
Circle(int x, int y, int r)
: _x(x), _y(y), _r(r) {}
virtual void draw(Mat &img) {
circle(img, Point(_x, _y), _r, Scalar(0,0,0));
}
private:
int _x, _y, _r;
};
class Rectangle : public Shape
{
public:
Rectangle(int x, int y, int w, int h)
: _x(x), _y(y), _w(w), _h(h) {}
virtual void draw(Mat &img) {
rectangle(img, Point(_x, _y),
Point(_x+_w, _y+_h), Scalar(0,0,0));
}
private:
int _x, _y, _w, _h;
};
int main()
{
const char wnd[] = "test";
namedWindow(wnd, WINDOW_AUTOSIZE);
int width = 1000, height = 800;
vector<Shape*> shapes {
new Circle(300, 200, 100),
new Rectangle(500, 200, 300, 100),
new Circle(500, 600, 100),
new Rectangle(100, 400, 100, 150)
};
Mat img = Mat::zeros(height, width, CV_8UC3);
while (true)
{
img = Scalar(255,255,255);
for (Shape* shape : shapes) {
shape->draw(img);
}
imshow(wnd, img);
int key = waitKey(40);
if ((key & 255) == 27) break;
}
for (Shape* shape : shapes) delete shape;
shapes.clear();
return 0;
}

40
zad6_2.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
from turtle import *
class Shape():
def __init__(self):
pass
def draw(self):
pass
class Circle(Shape):
def __init__(self, _posX, _posY, _size):
self.posX=_posX
self.posY=_posY
self.size=_size
def draw(self):
goto(self.posX, self.posY)
pendown()
circle(self.size)
penup()
class Rect(Shape):
def __init__(self, _posX, _posY, _sizeX, _sizeY):
self.posX=_posX
self.posY=_posY
self.sizeX=_sizeX
self.sizeY=_sizeY
def draw(self):
goto(self.posX, self.posY)
pendown()
for i in range(2):
forward(self.sizeX)
right(90)
forward(self.sizeY)
right(90)
penup()
penup()
shapes=[Circle(-200,100,100),
Rect(100,100,200,100)]
for shape in shapes:
shape.draw()

59
zad7_1.cpp Normal file
View File

@ -0,0 +1,59 @@
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
class Vec2 {
private:
int x,y;
public:
Vec2(int _x, int _y){
x=_x;
y=_y;
}
string toString(){
stringstream s;
s << "[" << x << ", " << y << "]";
return s.str();
}
friend Vec2 operator+(const Vec2& vec1, const Vec2& vec2){
return Vec2(vec1.x+vec2.x, vec1.y+vec2.y);
}
friend Vec2 operator-(const Vec2& vec1, const Vec2& vec2){
return Vec2(vec1.x-vec2.x, vec1.y-vec2.y);
}
Vec2& operator+=(const Vec2& vec){
x=vec.x+x;
y=vec.y+y;
return *this;
}
Vec2& operator-=(const Vec2& vec){
x=vec.x-x;
y=vec.y-y;
return *this;
}
friend float operator*(const Vec2& vec1, const Vec2& vec2){
return (float)vec1.x*vec2.x + (float)vec1.y+vec2.y;
}
bool operator==(const Vec2& vec){
if(x==vec.x && y==vec.y) return 1;
else return 0;
}
bool operator!=(const Vec2& vec){
if(x==vec.x && y==vec.y) return 0;
else return 1;
}
};
int main(){
Vec2 vec1 = Vec2(5,1);
Vec2 vec2 = Vec2(3,4);
Vec2 vec3 = vec1 + vec2;
cout << vec3.toString() << endl;
vec3+=vec2;
cout << vec3.toString() << endl;
vec3-=vec1;
cout << vec3.toString() << endl;
cout << vec3*vec2 << endl;
}

34
zad7_2.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
template <typename num>
class Vec2 {
private:
num x,y;
public:
Vec2(num _x, num _y){
x=_x;
y=_y;
}
string toString(){
stringstream s;
s << "[" << x << ", " << y << "]";
return s.str();
}
Vec2 add(const Vec2& vec){
return Vec2(x+vec.x, y+vec.y);
}
num multiply(const Vec2& vec){
return (float)x*vec.x + (float)y*vec.y;
}
};
int main(){
Vec2<float> vec1 = Vec2<float>(5.5f,1.2f);
Vec2<float> vec2 = Vec2<float>(3.4f,4.2f);
Vec2<float> vec3 = vec1.add(vec2);
cout << vec3.toString() << endl;
}

26
zad7_3.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <iostream>
using namespace std;
template <typename type>
class Array {
private:
type* basePtr;
Array(unsigned int n){
basePtr=(type*)malloc(sizeof(type)*n); //allocate the memory
}
~Array(){
free(basePtr);
}
public:
Array& operator new [](unsigned int n){
Array(n);
return *this;
}
void* operator delete [](unsigned int n){
~Array();
}
type operator[](){
return
}
};