Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include "stdafx.h"
- #include "stdio.h"
- #include "string.h"
- #include "stdlib.h"
- #include "windows.h"
- #include <cstring>
- #include <iostream>
- using namespace std;
- #define MAX 50
- //int anz, nr, i;
- //char bez[MAX], search[MAX];
- //FILE *datei;
- //Struct für das Listenelement
- struct list_elem {
- struct list_elem *next; //Zeiger auf das nächste Listenelement
- int anz; //Anzahl
- int nr; //Teile-Nr.
- char bez[MAX]; //Bezeichnug
- list_elem* getNext()
- {
- return next;
- }
- void setNext(list_elem* next)
- {
- this->next = next;
- }
- };
- //Struct für Liste
- struct List {
- private:
- list_elem* head;
- public:
- List() { //Konstruktor
- head = NULL;
- }
- // Anhaengen eines Listenelements an das Ende
- // O(n)
- void append(list_elem* e) {
- if (head == NULL) { //Pruefen, ob Listenkopf auf NULL zeigt
- e->setNext(NULL);
- head = e;
- }
- else {
- list_elem* current = head;
- while (current->getNext() != NULL) {
- current = current->getNext();
- }
- current->setNext(e);
- e->setNext(NULL);
- }
- }
- list_elem* search_nr(int nr) {
- if (head == NULL) {
- return NULL;
- }
- else {
- list_elem* current = head;
- for (;current->getNext() != NULL; current = current->getNext()) {
- if(current->nr == nr) {
- return current;
- break;
- }
- }
- }
- }
- list_elem* search_bez(char bez[]) {
- if (head == NULL) {
- return NULL;
- }
- else {
- list_elem* current = head;
- for (;current != NULL; current = current->getNext()) {
- if (strcmp ( current->bez, bez ) == 0 ) {
- return current;
- break;
- }
- }
- }
- }
- /*Ausgabe des Headelementes*/
- //O(1)
- list_elem* getHead () {
- return head;
- }
- };
- int main(){
- printf("Erstellen der zwei Objekte");
- List *liste1 = new List();
- list_elem *el1 = new list_elem();
- el1->nr=100;
- // char name[MAX]="Testobj";
- strcpy(el1->bez, "Testobj");
- el1->anz=1;
- liste1->append(el1);
- el1 = new list_elem();
- el1->nr=101;
- strcpy(el1->bez, "Testobj2");
- el1->anz=1;
- liste1->append(el1);
- printf("Erfolgreich erstellt\n\n");
- cout << "Test der Ausgabe" << endl;
- for(list_elem* current = liste1->getHead();current != NULL; current = current->getNext()) {
- printf("Art#: %i \t Bezeichnung: %s \t Anzahl: %i",current->nr, current->bez, current->anz);
- }
- printf("Test der Suchfunktion\nSuche Objekt mit Bezeichnung Testobj2 und gebe Art# aus.");
- el1 = new list_elem();
- char temp[MAX];
- el1 = liste1->search_bez(strcpy(temp, "Testobj2"));
- printf("Art#: %i",el1->nr);
- cout << "Test der Suchfunktion#2 \n Suche Objekt mit Art#: 100 und gebe Bez. aus." << endl;
- el1 = new list_elem();
- el1 = liste1->search_nr(100);
- printf("Bez#: %s",el1->bez);
- system ("pause");
- }
- //liste, element0, element1, elementneu;
- /*
- //Eingabe von Teile-Nr., Bezeichnung, Anzahl
- void eingabe()
- {
- printf ("Teile-Nummer ... : ");
- scanf ("%s",liste.nr);
- printf ("Bezeichnug ..... : ");
- scanf ("%s",liste.bez);
- printf ("Anzahl ......... : ");
- scanf ("%s",liste.anz);
- }
- //in Datei schreiben
- void ausgabe_in_datei()
- {
- //Legt Datei mit "Bezeichnug" als Name an
- datei = fopen(("%s.txt",liste.bez), "a+");
- if (datei != NULL)
- {
- fprintf (datei, "Teile-Nr: %10s | Bezeichnug: %15s | Anzahl: %10s\n", liste.nr, liste.bez, liste.anz);
- fclose (datei);
- }
- //Legt Datei mit "Teile-Nr." als Name an
- datei = fopen(("%s.txt", liste.nr), "a+");
- if (datei != NULL)
- {
- fprintf (datei, "Teile-Nr: %8s | Bezeichnug: %13s | Anzahl: %4s\n", liste.nr, liste.bez, liste.anz);
- fclose (datei);
- }
- }
- //txt-Datei auslesen
- void lesen_aus_datei()
- {
- printf ("Bitte Bezeichnung ODER Teile-Nummer eingeben ... : ");
- scanf ("%s",search);
- char text[200+1];
- datei = fopen (("%s.txt",search),"r");
- if (datei != NULL)
- {
- fscanf (datei, "%200c", text);
- text[200] = '\0';
- printf ("\n\n%s\n", text);
- fclose (datei);
- } else
- if (datei == NULL)
- {
- printf("\n Eintrag nicht vorhanden! \n");
- }
- }
- //Hauptprogramm
- int main ()
- {
- printf("Teil eintragen ......... (1)\n");
- printf("Teil suchen ............ (2)\n");
- printf("Teileeintrag aendern ... (3) !!! funzt noch nicht !!! \n\n");
- printf("Ihre Auswahl .......... : ");
- scanf("%i",&i);
- printf("\n\n");
- if (i==1) {
- eingabe();
- ausgabe_in_datei();
- printf ("\n");
- } else
- if (i==2) {
- lesen_aus_datei();
- }
- printf ("\n\n");
- system ("pause");
- return 1;
- }
- */
Add Comment
Please, Sign In to add comment