sync
This commit is contained in:
22
C/C2/shared/administration.c
Normal file
22
C/C2/shared/administration.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "administration.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "animal.h"
|
||||
|
||||
|
||||
int removeAnimal(
|
||||
int animalId, Animal* animalArray,
|
||||
size_t numberOfAnimalsPresent,
|
||||
size_t* newNumberOfAnimalsPresent)
|
||||
{
|
||||
//add implementation
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// To do : add the missing functions
|
||||
|
||||
|
||||
56
C/C2/shared/administration.h
Normal file
56
C/C2/shared/administration.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef ADMINISTRATION_H
|
||||
#define ADMINISTRATION_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "animal.h"
|
||||
|
||||
|
||||
/* pre : animalArrayLength must be greater than numberOfAnimalsPresent
|
||||
* post : animalArray is updated with the information from animalPtr, the
|
||||
* updated number of animals is passed in newNumberOfAnimalsPresent returns: 0
|
||||
* on success or -1 if an error occurs
|
||||
*/
|
||||
int addAnimal(
|
||||
const Animal* animalPtr, Animal* animalArray,
|
||||
size_t animalArrayLength, size_t numberOfAnimalsPresent,
|
||||
size_t* newNumberOfAnimalsPresent);
|
||||
|
||||
/* pre :
|
||||
* post : All animals with id 'animalId' are removed from AnimalArray, the
|
||||
* updated number of animals is passed in newNumberOfAnimalsPresent returns: The
|
||||
* number of removed animals, 0 if no animals removed or -1 if an error occurs
|
||||
*/
|
||||
int removeAnimal(
|
||||
int animalId, Animal* animalArray,
|
||||
size_t numberOfAnimalsPresent,
|
||||
size_t* newNumberOfAnimalsPresent);
|
||||
|
||||
/* pre :
|
||||
* post : The first animal from animalArray with id 'animalId' is copied into
|
||||
* animalPtr returns: 1 on success, 0 if not found or -1 if an error occurs
|
||||
*/
|
||||
int findAnimalById(
|
||||
int animalId, const Animal* animalArray,
|
||||
size_t numberOfAnimalsPresent, Animal* animalPtr);
|
||||
|
||||
/* pre :
|
||||
* post : All animals in animalArray are sorted by age
|
||||
* returns: 0 on success or -1 if an error occurs
|
||||
*/
|
||||
int sortAnimalsByAge(Animal* animalArray, size_t numberOfAnimalsPresent);
|
||||
|
||||
/* pre :
|
||||
* post : All animals in animalArray are sorted by the year in which they were
|
||||
* found returns: 0 on success or -1 if an error occurs
|
||||
*/
|
||||
int sortAnimalsByYearFound(
|
||||
Animal* animalArray, size_t numberOfAnimalsPresent);
|
||||
|
||||
/* pre :
|
||||
* post : All animals in animalArray are sorted: first female animals and then
|
||||
* male animals returns: 0 on success or -1 if an error occurs
|
||||
*/
|
||||
int sortAnimalsBySex(Animal* animalArray, size_t numberOfAnimalsPresent);
|
||||
|
||||
#endif
|
||||
33
C/C2/shared/animal.h
Normal file
33
C/C2/shared/animal.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef ANIMAL_H
|
||||
#define ANIMAL_H
|
||||
|
||||
typedef enum {
|
||||
Cat,
|
||||
Dog,
|
||||
GuineaPig,
|
||||
Parrot
|
||||
} Species;
|
||||
|
||||
typedef enum {
|
||||
Male,
|
||||
Female
|
||||
} Sex;
|
||||
|
||||
typedef struct {
|
||||
int Day;
|
||||
int Month;
|
||||
int Year;
|
||||
} Date;
|
||||
|
||||
#define MaxNameLength 25
|
||||
#define MaxLocationLength 100
|
||||
|
||||
typedef struct {
|
||||
int Id;
|
||||
Species Species;
|
||||
Sex Sex;
|
||||
int Age;
|
||||
Date DateFound;
|
||||
} Animal;
|
||||
|
||||
#endif
|
||||
35
C/C2/shared/file_element.c
Normal file
35
C/C2/shared/file_element.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include "file_element.h"
|
||||
|
||||
|
||||
int readAnimals(const char* filename, Animal* animalPtr, size_t nrAnimals)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int writeAnimals(const char* filename, const Animal* animalPtr, size_t nrAnimals)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int getNrAnimalsInFile(const char* filename, size_t* nrAnimals)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int readAnimalFromFile(
|
||||
const char* filename, size_t filePosition, Animal* animalPtr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int writeAnimalToFile(
|
||||
const char* filename, size_t filePosition, const Animal* animalPtr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int renameAnimalInFile(
|
||||
const char* filename, size_t filePosition, const char* animalSurname)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
66
C/C2/shared/file_element.h
Normal file
66
C/C2/shared/file_element.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef FILE_ELEMENT_H
|
||||
#define FILE_ELEMENT_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "animal.h"
|
||||
|
||||
int readAnimals(const char* filename, Animal* animalPtr, size_t nrAnimals);
|
||||
/* pre : n.a.
|
||||
* post : If file contains enough Animals, nrAnimals Animals are read into
|
||||
* animalPtr. If less animals than nrAnimals exist, all animals from
|
||||
* the file are read into animalPtr.
|
||||
* returns: Nr of animals written into animalPtr or -1 if an error occurs
|
||||
*/
|
||||
|
||||
int writeAnimals(const char* filename, const Animal* animalPtr, size_t nrAnimals);
|
||||
/* pre : n.a.
|
||||
* post : nrAnimals animals are written into a new file with data from
|
||||
* animalPtr
|
||||
* returns: On succes: 0, on error (file could not be written, input pointers
|
||||
* are NULL): -1
|
||||
*/
|
||||
|
||||
int getNrAnimalsInFile(const char* filename, size_t* nrAnimals);
|
||||
/* pre : n.a.
|
||||
* post : get number of animals (Animal structures) in the file
|
||||
* returns: on succes: 0, on error: -1
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
int readAnimalFromFile(
|
||||
const char* filename, size_t filePosition, Animal* animalPtr);
|
||||
/* pre : n.a.
|
||||
* post : read the animal on filePosition (first animal is filePosition 0,
|
||||
* second animal is filePosition 1, ...) into animalPtr
|
||||
* returns: On success: 0, on error: -1 (no data available on filePosition,
|
||||
* file could not be read, ...)
|
||||
*/
|
||||
|
||||
int writeAnimalToFile(
|
||||
const char* filename, size_t filePosition, const Animal* animalPtr);
|
||||
/* pre :
|
||||
* post : write the animal in animalPtr to the file at position 'filePosition'
|
||||
* returns: On success: 0, on error: -1
|
||||
*
|
||||
**** note: do not open the file in append mode (a or a+): in append mode you
|
||||
**** ALWAYS write to the end of the file. You cannot open the file in
|
||||
**** write mode either (w or w+), as this will truncate an existing file
|
||||
**** to 0 bytes. You MUST open the file in "r+" mode (means: r+w) and if
|
||||
**** that fails (could mean: file does not exist) retry in "w" mode.
|
||||
*/
|
||||
|
||||
int renameAnimalInFile(
|
||||
const char* filename, size_t filePosition, const char* animalSurname);
|
||||
/* pre :
|
||||
* post : change the animal name on the filePosition in this way:
|
||||
* The new animal name will start with animalSurname, followed
|
||||
* by a space and followed by the original animal name
|
||||
* Example : We have animal called "Max" on filePosition and animalSurname
|
||||
* "Verstappen". The new animal name will be "Verstappen Max".
|
||||
* The renamed animal will be written back to the file.
|
||||
* returns : On success: 0, on error: -1
|
||||
*/
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user