Update Demo-Cases

This commit is contained in:
Matti 2024-11-11 21:37:51 +01:00
parent c27a71a56f
commit e274b6b218

View File

@ -106,6 +106,12 @@ void addContact(Kontaktdaten* person, std::vector<Kontaktdaten*> *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;
@ -179,31 +185,10 @@ void readContactsFromFile(std::vector<Kontaktdaten*> *Telefonbuch, std::string *
}
}
infile.close();
}
/*
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/Telefonbuch.txt";
std::vector<Kontaktdaten*> Telefonbuch;
for (int i=0; i<1; i++) {
readContactsFromFile(&Telefonbuch, &fileName);
std::cout << "Done with reading " << i << std::endl;
}
void addFirstSetOfContacts(std::vector<contacts*> * Telefonbuch) {
auto * Robin = new Kontaktdaten;
auto * Saxo = new Kontaktdaten;
auto * Jesus = new Kontaktdaten;
@ -220,6 +205,53 @@ void TelefonbuchMain() {
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";
@ -234,17 +266,26 @@ void TelefonbuchMain() {
Jesus->lastName = "Nazarett";
*/
addContact(Robin, &Telefonbuch);
addContact(Saxo, &Telefonbuch);
addContact(Jesus, &Telefonbuch);
// addFirstSetOfContacts(&Telefonbuch);
addSecondSetOfContacts(&Telefonbuch);
// printAllContacts(&Telefonbuch);
saveAllContacts(&Telefonbuch, &fileName);
deleteAllContacts(&Telefonbuch);
delete Robin;
delete Saxo;
delete Jesus;
}
/*
* 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