-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
174 lines (161 loc) · 5.73 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//============================================================================
// Name : main.cpp
// Author : Alexander M. Westphal / Paul Schröder
// Version : Version 1.0
// Copyright : Alexander M. Westphal / Paul Schröder
// Description : Main Program
// Compiler and C++ Version: GNU GCC / C++11 Standard
//============================================================================
#include <iostream>
#include "student.h"
#include "student.cpp"
#include "CursorList.h"
CursorList<Student> curs;
int input();
void createStudent();
void deleteStudent();
void createStudentBeforePosition();
void deleteStudentWithStartAndStop();
int finde();
int main() {
int eingabe = -1;
std::cout << "Das Programm funktioniert nur mit gueltigen Eingaben!!" << std::endl;
while (eingabe != 0){
std::cout << "Aktuell passen noch " << curs.array_size_start - curs.get_counter() << " Studenten in die Liste"<< std::endl << "Studenten: " << std::endl;
for(CursorList<Student>::iterator it = curs.begin(); it != CursorList<Student>::iterator(-1, curs.arr); ++it) {
std::cout << it.m_index << " " << *it << std::endl;
}
eingabe = input();
switch(eingabe){
case 1:
createStudent();
break;
case 2:
createStudentBeforePosition();
break;
case 3:
curs.pop_front();
break;
case 4:
deleteStudent();
break;
case 5:
deleteStudentWithStartAndStop();
break;
case 6:
std::cout << curs.front() << std::endl;
break;
case 7:
std::cout << curs.get_counter() << std::endl;
break;
case 8:
std::cout << "Student ist an Position: " << finde() << std::endl;
break;
case 9:
eingabe = 0;
break;
default:
std::cout << "falsche Eingabe";
break;
}
}
return 0;
}
/**
* Inputmenu for the user to enter a option on the commandline and execute this point.
* @return will return the entered value as Integer.
*/
int input() {
using namespace std;
int eingabe;
cout << "Menue:" << endl;
cout << "(1) Student hinzufuegen am Anfang der Liste" << endl;
cout << "(2) Student hinzufuegen an bestimmter Stelle" << endl;
cout << "(3) Student entfernen am Anfang der Liste" << endl;
cout << "(4) Student an bestimmter Stelle entfernen " << endl;
cout << "(5) mehrere Studenten an bestimmter Stelle entfernen" << endl;
cout << "(6) Wie lautet der erste Student in der Liste " << endl;
cout << "(7) aktuelle Studentenanzahl in CursorList" << endl;
cout << "(8) finde einen Studenten" << endl;
cout << "(9) Fertig" << endl;
cout << "Eingabe: ";
cin >> eingabe;
return eingabe;
}
/**
* Method to create a Student and put it in the Datastructur.
*/
void createStudent(){
using namespace std;
int i,k;
char u[10],j[10];
cout << "Geben sie eine Matrikelnummer, einen Geburtstag sowie einen Namen und einen Vornamen ein" << endl;
cout << "Beispiel: 111 04021998 Paula Schrot \n";
cin >> i >> k >> u >> j;
Student abc(i, u, j ,k);
try {
curs.push_front(abc);
} catch (...) {
cout << "Error Occured Data Struct is full" << endl;
}
}
/**
* Method to delete a Student.
*/
void deleteStudent(){
using namespace std;
int position;
cout << "Geben sie die Position eines Studenten ein, der geloescht werden soll" << endl;
cin >> position;
try {
curs.erase(CursorList<Student>::ListIterator(position, curs.arr)); //CursorList<Student>::ListIterator(position, curs.arr) ::find(curs.begin(), curs.end(), curs.get_value(position))
} catch (...) {
cout << "Error Occured Data Struct is full" << endl;
}
}
/**
* Method to delete a bunch of Students from a start until a specefied end.
*/
void deleteStudentWithStartAndStop(){
using namespace std;
int start, stop;
cout << "Geben Sie einen Start und Endpunkt ein, in dem alle Studenten geloescht werden" << endl;
cin >> start >> stop;
try {
curs.erase(CursorList<Student>::ListIterator(start, curs.arr), CursorList<Student>::ListIterator(stop, curs.arr));
} catch (...) {
cout << "Error Occured Data Struct is full" << endl;
}
}
/**
* Create a Student at a specified position.
*/
void createStudentBeforePosition(){
using namespace std;
int i,k, position;
char u[10],j[10];
cout << "Geben sie eine Matrikelnummer, einen Geburtstag, einen Namen, einen Vornamen und eine Position ein" << endl;
cout << "Beispiel: 111 04021998 Paula Schrot \n";
cin >> i >> k >> u >> j >> position;
Student abc(i, u, j ,k);
try {
curs.insert(CursorList<Student>::ListIterator(position, curs.arr), abc);
} catch (...) {
cout << "Error Occured Data Struct is full" << endl;
}
}
int finde() {
using namespace std;
int i,k;
char u[10],j[10];
cout << "Geben sie eine Matrikelnummer, einen Geburtstag, einen Namen, einen Vornamen" << endl;
cout << "Beispiel: 111 04021998 Paula Schrot \n";
cin >> i >> k >> u >> j;
Student abc(i, u, j ,k);
try {
return ::find(curs.begin(), curs.end(), abc).m_index;
} catch (...) {
cout << "Error Occured Data Struct is full" << endl;
}
return 0;
}