Delete old Main
This commit is contained in:
parent
a071a17043
commit
1c704a5ede
315
Main.cpp
315
Main.cpp
@ -1,315 +0,0 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#pragma region Aufgabe1
|
||||
/*
|
||||
Ouput der Zahlen 10 bis 0 an die Konsole
|
||||
Ouput aller Buchstaben des Alphabets
|
||||
*/
|
||||
|
||||
void counter() {
|
||||
for (int i = 10; i > 0; i--)
|
||||
{
|
||||
printf("%d\n", i);
|
||||
}
|
||||
}
|
||||
|
||||
void alphabet() {
|
||||
char alpha[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
|
||||
for (char letter : alpha)
|
||||
{
|
||||
printf("%c ", letter);
|
||||
}
|
||||
}
|
||||
|
||||
void Aufg1Main()
|
||||
{
|
||||
counter();
|
||||
alphabet();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Aufgabe2
|
||||
/*
|
||||
* GästeListe
|
||||
*
|
||||
* Konsoleninput zur Wahl Liste verlängern/ausgeben/Ende
|
||||
*/
|
||||
|
||||
|
||||
void showMenu() {
|
||||
std::cout << "1 to add Guest"
|
||||
<< std::endl
|
||||
<< "2 to print all Guests"
|
||||
<< std::endl
|
||||
<< "0 to exit"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
void getInput(int &input) {
|
||||
|
||||
std::cin >> input;
|
||||
}
|
||||
|
||||
void printAllInVector(std::vector<std::string> &Myvector) {
|
||||
for (std::string name : Myvector)
|
||||
{
|
||||
std::cout << name
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Aufg2Main()
|
||||
{
|
||||
std::vector<std::string> guestList;
|
||||
|
||||
while (true) {
|
||||
showMenu();
|
||||
|
||||
int input;
|
||||
getInput(input);
|
||||
|
||||
std::string name;
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case 0:
|
||||
return;
|
||||
case 1:
|
||||
std::cin >> name;
|
||||
guestList.push_back(name);
|
||||
break;
|
||||
case 2:
|
||||
printAllInVector(guestList);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Telefonbuch
|
||||
|
||||
typedef struct contacts{
|
||||
std::string firstName;
|
||||
std::string lastName;
|
||||
int number;
|
||||
} Kontaktdaten;
|
||||
|
||||
|
||||
void addContact(Kontaktdaten* person, std::vector<Kontaktdaten*> *Telefonbuch) {
|
||||
Telefonbuch->push_back(person);
|
||||
// std::vector<Kontaktdaten *> buch = *Telefonbuch;
|
||||
// buch.push_back(person);
|
||||
}
|
||||
|
||||
void deleteAllContacts(std::vector<Kontaktdaten*> *Telefonbuch) {
|
||||
for (Kontaktdaten* pointer: *Telefonbuch) {
|
||||
delete pointer;
|
||||
}
|
||||
}
|
||||
|
||||
void printAllContacts(std::vector<Kontaktdaten*> *Telefonbuch) {
|
||||
for (Kontaktdaten * personpointer: *Telefonbuch) {
|
||||
Kontaktdaten person = *personpointer;
|
||||
std::cout << person.firstName << " " << person.lastName << " " << person.number << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void saveAllContacts(std::vector<Kontaktdaten*> *Telefonbuch, std::string *fileName) {
|
||||
std::ofstream outfile;
|
||||
outfile.open(*fileName);
|
||||
|
||||
for (Kontaktdaten * personpointer: *Telefonbuch) {
|
||||
Kontaktdaten person = *personpointer;
|
||||
outfile << person.firstName << std::endl << person.lastName << std::endl << person.number << std::endl;
|
||||
}
|
||||
|
||||
outfile.close();
|
||||
}
|
||||
|
||||
int exponentiate(int base, int exponent) {
|
||||
int result = 1;
|
||||
while (exponent > 0) {
|
||||
result *= base;
|
||||
exponent--;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int intStringToInt(std::string input) {
|
||||
int result = 0;
|
||||
|
||||
int size = input.length();
|
||||
for(int i = 0; i < size; i++) {
|
||||
int digit = input[size - 1 - i] - '0'; // -1 to consider 0-index // -'0' to get ascii indicies right
|
||||
result += digit * exponentiate(10, i); // shift digit
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void readContactsFromFile(std::vector<Kontaktdaten*> *Telefonbuch, std::string *fileName) {
|
||||
std::ifstream infile;
|
||||
infile.open(*fileName);
|
||||
|
||||
if (!infile.is_open()) {
|
||||
std::cout << "File does not exist" << std::endl;
|
||||
}
|
||||
|
||||
std::string line;
|
||||
int counter = 0;
|
||||
Kontaktdaten * personpointer = new Kontaktdaten;
|
||||
while (std::getline(infile, line)) {
|
||||
|
||||
int attribute = counter % 3;
|
||||
counter++;
|
||||
|
||||
switch (attribute) {
|
||||
case 0:
|
||||
personpointer->firstName = line;
|
||||
break;
|
||||
case 1:
|
||||
personpointer->lastName = line;
|
||||
break;
|
||||
case 2:
|
||||
personpointer->number = intStringToInt(line);
|
||||
addContact(personpointer, Telefonbuch);
|
||||
personpointer = new Kontaktdaten;
|
||||
break;
|
||||
default:
|
||||
std::cout << "This should never happen" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
infile.close();
|
||||
}
|
||||
|
||||
void addFirstSetOfContacts(std::vector<contacts*> * Telefonbuch) {
|
||||
auto * Robin = new Kontaktdaten;
|
||||
auto * Saxo = new Kontaktdaten;
|
||||
auto * Jesus = new Kontaktdaten;
|
||||
|
||||
Robin->number = 123456;
|
||||
Robin->firstName = "Robin";
|
||||
Robin->lastName = "Schnaiter";
|
||||
|
||||
Saxo->number = 987654;
|
||||
Saxo->firstName = "Saxobastian";
|
||||
Saxo->lastName = "Brosch";
|
||||
|
||||
Jesus->number = 666;
|
||||
Jesus->firstName = "Jesus";
|
||||
Jesus->lastName = "Nazarett";
|
||||
|
||||
addContact(Robin, Telefonbuch);
|
||||
addContact(Saxo, Telefonbuch);
|
||||
addContact(Jesus, Telefonbuch);
|
||||
}
|
||||
|
||||
void addSecondSetOfContacts(std::vector<contacts*> * Telefonbuch) {
|
||||
auto * Bruno = new Kontaktdaten;
|
||||
auto * Peter = new Kontaktdaten;
|
||||
auto * Ralf = new Kontaktdaten;
|
||||
|
||||
Bruno->number = 462581;
|
||||
Bruno->firstName = "Bruno";
|
||||
Bruno->lastName = "Braunbär";
|
||||
|
||||
Peter->number = 110;
|
||||
Peter->firstName = "Peter";
|
||||
Peter->lastName = "Polizei";
|
||||
|
||||
Ralf->number = 9999;
|
||||
Ralf->firstName = "Ralf";
|
||||
Ralf->lastName = "Rotbart";
|
||||
|
||||
addContact(Bruno, Telefonbuch);
|
||||
addContact(Peter, Telefonbuch);
|
||||
addContact(Ralf, Telefonbuch);
|
||||
}
|
||||
/*
|
||||
Kontaktdaten * createContact(std::string firstName, std::string lastName, int number) {
|
||||
Kontaktdaten person = new Kontaktdaten;
|
||||
|
||||
person.firstName = firstName;
|
||||
person.lastName = lastName;
|
||||
person.number = number;
|
||||
|
||||
return & person;
|
||||
}
|
||||
*/
|
||||
|
||||
void TelefonbuchMain() {
|
||||
std::string fileName = "../IO-Files/phonebook.thorsten";
|
||||
std::vector<Kontaktdaten*> Telefonbuch;
|
||||
|
||||
for (int i=0; i<1; i++) {
|
||||
readContactsFromFile(&Telefonbuch, &fileName);
|
||||
std::cout << "Done with reading " << i << std::endl;
|
||||
}
|
||||
|
||||
/*
|
||||
*Robin->number = 123456;
|
||||
Robin->firstName = "Robin der Neue";
|
||||
Robin->lastName = "Schnaiter";
|
||||
|
||||
Saxo->number = 987654;
|
||||
Saxo->firstName = "Saxobastian";
|
||||
Saxo->lastName = "Broschianer";
|
||||
|
||||
Jesus->number = 6666666;
|
||||
Jesus->firstName = "Jesus";
|
||||
Jesus->lastName = "Nazarett";
|
||||
*/
|
||||
|
||||
// addFirstSetOfContacts(&Telefonbuch);
|
||||
addSecondSetOfContacts(&Telefonbuch);
|
||||
|
||||
// printAllContacts(&Telefonbuch);
|
||||
saveAllContacts(&Telefonbuch, &fileName);
|
||||
deleteAllContacts(&Telefonbuch);
|
||||
|
||||
/*
|
||||
* IDE beschwert sich bei Erstellen von * Robin über leaked Memory
|
||||
* deleteAllContacts() sollte den Speicher befreien
|
||||
*
|
||||
* Zugriff auf *Robin nach delete Statement führt zu Fehler?
|
||||
* -> IDE ist zu dumm?
|
||||
*/
|
||||
|
||||
//
|
||||
// std::cout << Robin << std::endl;
|
||||
// auto test = *Robin;
|
||||
// std::cout << test.firstName << std::endl;
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
// Telefonnummern sollen in Datei gespeichert werden
|
||||
// Beim Start vorhandene Einträge laden
|
||||
|
||||
// Typen sortieren mit Counter und Modulo
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
TelefonbuchMain();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Programm ausführen: STRG+F5 oder Menüeintrag "Debuggen" > "Starten ohne Debuggen starten"
|
||||
// Programm debuggen: F5 oder "Debuggen" > Menü "Debuggen starten"
|
||||
|
||||
// Tipps für den Einstieg:
|
||||
// 1. Verwenden Sie das Projektmappen-Explorer-Fenster zum Hinzufügen/Verwalten von Dateien.
|
||||
// 2. Verwenden Sie das Team Explorer-Fenster zum Herstellen einer Verbindung mit der Quellcodeverwaltung.
|
||||
// 3. Verwenden Sie das Ausgabefenster, um die Buildausgabe und andere Nachrichten anzuzeigen.
|
||||
// 4. Verwenden Sie das Fenster "Fehlerliste", um Fehler anzuzeigen.
|
||||
// 5. Wechseln Sie zu "Projekt" > "Neues Element hinzufügen", um neue Codedateien zu erstellen, bzw. zu "Projekt" > "Vorhandenes Element hinzufügen", um dem Projekt vorhandene Codedateien hinzuzufügen.
|
||||
// 6. Um dieses Projekt später erneut zu öffnen, wechseln Sie zu "Datei" > "Öffnen" > "Projekt", und wählen Sie die SLN-Datei aus.
|
Loading…
Reference in New Issue
Block a user