Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Rothschildiuk committed Jul 21, 2017
0 parents commit f651b83
Show file tree
Hide file tree
Showing 49 changed files with 4,363 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .idea/Parkhaus.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

770 changes: 770 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.7)
project(Parkhaus)

set(CMAKE_CXX_STANDARD 11)

set(SOURCE_FILES main.cpp Stellplatz.cpp Parkhaus.cpp)
add_executable(Parkhaus ${SOURCE_FILES})
43 changes: 43 additions & 0 deletions Parkhaus.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include"Parkhaus.h"


Parkhaus::Parkhaus(string s, vector<Stellplatz> v) : adresse(s), v(v) {
if (s == "") throw runtime_error("error adresse");
}


vector<Stellplatz> Parkhaus::finde(Ptyp typ) const {

vector<Stellplatz> vv;
for (int i = 0; i < v.size(); ++i) {
if (v[i].passt(typ) && v[i].ist_frei()) {
vv.push_back(v[i]);
}
}
return vv;

}

bool Parkhaus::einfahren(Ptyp typ) {
for (int i = 0; i < v.size(); ++i) {
if (v[i].ist_frei() && v[i].passt(typ)) {
v[i].einparken(typ);
return true;
}

}
return false;

}

void Parkhaus::ausfahren(size_t no) {
if (v.size() < no) throw runtime_error("error 80");
// if(v[no].ist_frei()) throw runtime_error ("error 80");
v[no].ausparken();

}


ostream &operator<<(ostream &o, const Parkhaus &s) {
return s.print(o);
}
40 changes: 40 additions & 0 deletions Parkhaus.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef PARKHAUS_H
#define PARKHAUS_H

#include"Stellplatz.h"

#include<iostream>
#include<vector>
#include<string>
#include<stdexcept>

using namespace std;


class Parkhaus {
string adresse;
vector<Stellplatz> v;
public:
Parkhaus(string, vector<Stellplatz>);

vector<Stellplatz> finde(Ptyp typ) const;
bool einfahren(Ptyp typ);
void ausfahren(size_t no);

ostream &print(ostream &o) const{
o << "[" << adresse << "{";

for (int i = 0; i < v.size(); ++i) {
o << v[i];
if (i != v.size()-1) o << ", ";
}

return o << "}]";
}


};

ostream &operator<<(ostream &o, const Parkhaus &s);

#endif
21 changes: 21 additions & 0 deletions Stellplatz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include"Stellplatz.h"

Stellplatz::Stellplatz(Ptyp t){
ptyp = t;
frei = true;
}

//ostream& Stellplatz::print(ostream &o) const {
// o << "[";
// if (ptyp == Ptyp::pkw) o << "PKW";
// if (ptyp == Ptyp::bus) o << "BUS";
// if (ptyp == Ptyp::krad) o << "2RAD";
//
// if (frei == false) o << " belegt";
//
// return o << "]";
//}

ostream& operator<< (ostream& o, const Stellplatz& s) {
return s.print(o);
}
61 changes: 61 additions & 0 deletions Stellplatz.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef STELLPLATZ_H
#define STELLPLATZ_H

#include<iostream>
#include<stdexcept>

using namespace std;

enum class Ptyp {
pkw, bus, krad
};

class Stellplatz {
Ptyp ptyp;
bool frei;
public:

Stellplatz(Ptyp t = Ptyp::pkw);

bool ist_frei() const { return frei; }

bool passt(Ptyp typ) const {
if (typ == ptyp) return true;
else return false;
}

bool einparken(Ptyp typ) {

if (passt(typ) && ist_frei()) {
frei = false;
return true;

} else return false;

}

void ausparken() {
if (frei == true) throw runtime_error("error 2");
else frei = true;
}




ostream &print(ostream &o) const {
o << "[";
if (ptyp == Ptyp::pkw) o << "PKW";
if (ptyp == Ptyp::bus) o << "BUS";
if (ptyp == Ptyp::krad) o << "2RAD";

if (frei == false) o << " belegt";

return o << "]";
}

};

ostream& operator<< (ostream& o, const Stellplatz& s);


#endif
Loading

0 comments on commit f651b83

Please sign in to comment.