This commit is contained in:
Daniel Hladek 2019-11-04 10:36:45 +01:00
parent 522da030c1
commit d8b812d9dc
5 changed files with 102 additions and 2 deletions

13
Makefile Normal file
View File

@ -0,0 +1,13 @@
CFLAGS= -std=c99 -g -Wall
all: train
%.o: %.c
gcc -c -o $@ $< $(CFLAGS)
train: main.o a_train.o
gcc main.o a_train.o -o train
clean:
rm *.o train

View File

@ -1,3 +1,5 @@
# usaa19cv7 # Vlak do neba
Šablóna úlohy z siedmeho cvičenia Šablóna úlohy zo siedmeho cvičenia.
Úlohu vypracujte do súboru `a_train.c` podľa dokumentácie v súbore `a_train.h`.

18
a_train.c Normal file
View File

@ -0,0 +1,18 @@
#include "a_train.h"
#include <stdio.h>
struct car* add_car(struct car* first,const char* target) {
return NULL;
}
void print_train(struct car* first) {
}
void cancel_train(struct car* first) {
}
struct car* clear_train(struct car* first, const char* target) {
return NULL;
}

50
a_train.h Normal file
View File

@ -0,0 +1,50 @@
#ifndef TRAIN_H
#define TRAIN_H
#define SIZE 100
/**
* Jeden vozen vlaku
*/
struct car {
/**
* Nazov cielovej stanice
*/
char value[SIZE];
/**
* Smenik na dalsi vozen
*/
struct car* next;
};
/**
* Prida vozen na koniec vlaku.
*
* @arg nazov cielovej stanice, ktory sa ma priradit novemu voznu.
* @arg kapacita vozna
* @return smernik na zaciatok vlaku.
*/
struct car* add_car(struct car* first,const char* target);
/**
* Vypise vsetky vozne vo vlaku
*
* @arg smernik na prvy vozen
*/
void print_train(struct car* first);
/**
* Zrusenie vsetkych voznov vo vlaku.
* @arg smernik na prvy vozen
*/
void cancel_train(struct car* first);
/**
* Vyradenie vsetkych voznov, ktorych cielova stanica je target
*
* @arg cielova stanica, ktora sa ma vyradit z vlaku.
*
*/
struct car* clear_train(struct car* first,const char* target);
#endif // TRAIN_H

17
main.c Normal file
View File

@ -0,0 +1,17 @@
#include "a_train.h"
#include <stdio.h>
// Testovaci subor pre vlak
int main(){
struct car* train = NULL;
train = add_car(train,"Presov");
train = add_car(train,"Bratislava");
train = add_car(train,"Levoca");
train = add_car(train,"Spiska Nova Ves");
print_train(train);
clear_train(train,"Levoca");
print_train(train);
cancel_train(train);
return 0;
}