diff --git a/APL1.2/TP02/alterations.c b/APL1.2/TP02/alterations.c new file mode 100644 index 0000000..d4ae09e --- /dev/null +++ b/APL1.2/TP02/alterations.c @@ -0,0 +1,73 @@ +#include +#include +#include + +struct rectangle { + int x; + int y; + int xx; + int yy; +}; + +typedef struct rectangle rect; + +void drawRect(rect Rekt) { + DessinerRectangle(Rekt.x, Rekt.y, Rekt.xx-Rekt.x, Rekt.yy-Rekt.y); +} + +rect moveRect(rect Rekt, int x, int y) { + Rekt.x += x; + Rekt.y += y + Rekt.xx += x; + Rekt.yy += y; + return Rekt; +} + +rect rotRectLeft(rect Rekt) { + +} + +rect rotRectRight(rect Rekt) { + +} + +int main(int argc, char * argv[]) { + InitialiserGraphique(); + CreerFenetre(100,100,1200,700); + + rect Rekt = {100,100,200,200}; + int state = 0; + + couleur white = CouleurParNom("white"); + + drawRect(Rekt); + + while (1) { + if (ToucheEnAttente()) { + int key = Touche(); + if (key == XK_Escape) return EXIT_SUCCESS; + } + + if (SourisCliquee()) { + if (state == 0) { + Rekt.x = _X; + Rekt.y = _Y; + state = 1; + } else { + if (_X < Rekt.x ) { + Rekt.xx = Rekt.x; + Rekt.x = _X; + } else Rekt.xx = _X; + if (_Y < Rekt.y ) { + Rekt.yy = Rekt.y; + Rekt.y = _Y; + } else Rekt.yy = _Y; + state = 0; + drawRect(Rekt); + } + } + } + FermerGraphique(); + return EXIT_SUCCESS; +} + diff --git a/APL1.2/TP02/complexes.c b/APL1.2/TP02/complexes.c new file mode 100644 index 0000000..09b2531 --- /dev/null +++ b/APL1.2/TP02/complexes.c @@ -0,0 +1,35 @@ +#include +#include +#include + +struct nb_complex { + float real; + float imaginary; +}; + +typedef struct nb_complex complex; + +float module(complex z) { + return sqrt(pow(z.real, 2) + pow(z.imaginary, 2)); +} + +complex conjugate(complex z) { + z.imaginary = -z.imaginary; + return z; +} + +complex inverse(complex z) { + float a = z.real; + float b = z.imaginary; + z.real = a/(pow(a, 2) + pow(b, 2)); + z.imaginary = -b/(pow(a, 2) + pow(b, 2)); + + return z; +} + +int main(int argc, char * argv[]) { + complex a = {1.0f, 1.0f}; + printf("%f\n", module(inverse(a))); + return EXIT_SUCCESS; +} + diff --git a/APL1.2/TP02/date.c b/APL1.2/TP02/date.c new file mode 100644 index 0000000..ac2064f --- /dev/null +++ b/APL1.2/TP02/date.c @@ -0,0 +1,12 @@ +#include +#include +#include + +int main(int argc, char * argv[]) { + time_t temps = time(NULL); + struct tm * timeInfos = localtime(&temps); + + printf("Nous sommes le %4d-%2d-%2d\n", timeInfos->tm_year+1900, timeInfos->tm_mon, timeInfos->tm_mday); + return EXIT_SUCCESS; +} + diff --git a/APL1.2/TP02/groupe.c b/APL1.2/TP02/groupe.c new file mode 100644 index 0000000..8f94085 --- /dev/null +++ b/APL1.2/TP02/groupe.c @@ -0,0 +1,14 @@ +#include +#include +#include +#include +#include + +int main(int argc, char * argv[]) { + struct group * students21 = getgrnam("students21"); + char ** names = students21->gr_mem; + + printf("%c", names[1]); + return EXIT_SUCCESS; +} + diff --git a/APL1.2/TP02/rectangles.c b/APL1.2/TP02/rectangles.c new file mode 100644 index 0000000..a7158a4 --- /dev/null +++ b/APL1.2/TP02/rectangles.c @@ -0,0 +1,57 @@ +#include +#include +#include + +struct rectangle { + int x; + int y; + int xx; + int yy; +}; + +typedef struct rectangle rect; + +void drawRect(rect Rekt) { + DessinerRectangle(Rekt.x, Rekt.y, Rekt.xx-Rekt.x, Rekt.yy-Rekt.y); +} + +int main(int argc, char * argv[]) { + InitialiserGraphique(); + CreerFenetre(100,100,1200,700); + + rect Rekt = {100,100,200,200}; + int state = 0; + + couleur white = CouleurParNom("white"); + + drawRect(Rekt); + + while (1) { + if (ToucheEnAttente()) { + int key = Touche(); + if (key == XK_Escape) return EXIT_SUCCESS; + } + + if (SourisCliquee()) { + if (state == 0) { + Rekt.x = _X; + Rekt.y = _Y; + state = 1; + } else { + if (_X < Rekt.x ) { + Rekt.xx = Rekt.x; + Rekt.x = _X; + } else Rekt.xx = _X; + if (_Y < Rekt.y ) { + Rekt.yy = Rekt.y; + Rekt.y = _Y; + } else Rekt.yy = _Y; + state = 0; + drawRect(Rekt); + } + } + } + FermerGraphique(); + return EXIT_SUCCESS; +} + diff --git a/APL1.2/TP02/tailles.c b/APL1.2/TP02/tailles.c new file mode 100644 index 0000000..f205b20 --- /dev/null +++ b/APL1.2/TP02/tailles.c @@ -0,0 +1,15 @@ +#include +#include + +struct enregistrement { + int champ1; + char champ2; + char champ3; +}; + +int main(int argc, char * argv[]) { + struct enregistrement toto = {}; + printf("%d\n", sizeof(toto)); + return EXIT_SUCCESS; +} + diff --git a/APL1.2/TP03/challenger.c b/APL1.2/TP03/challenger.c new file mode 100644 index 0000000..0424478 --- /dev/null +++ b/APL1.2/TP03/challenger.c @@ -0,0 +1,54 @@ +#include +#include +#include + +int main(int argc, char * argv[]) { + FILE* flux; + flux = fopen("top10", "r"); + + int NewRank = atoi(argv[1]); + int added = 0; + + char* ChallengerNames[11] = {}; + int ChallengerRanks[11] = {}; + + int count = 0; + + if (flux) { + do { + int rank; + char * name = calloc(4, sizeof(char)); + + fread(&rank, 4, 1, flux); + fread(name, 1, 3, flux); + + if (rank < NewRank && !added) { + ChallengerNames[count] = calloc(4, sizeof(char)); + strcpy(ChallengerNames[count], argv[2]); + ChallengerRanks[count] = NewRank; + added = 1; + count++; + } + + ChallengerNames[count] = calloc(4, sizeof(char)); + strcpy(ChallengerNames[count], name); + ChallengerRanks[count] = rank; + count++; + + } while (!feof(flux)); + fclose(flux); + + flux = fopen("top10", "w"); + if (flux) { + //printf("%d\n", count); + /*for (int i = 0; i < count-2; i++) { + printf("%s\n", ChallengerNames[i]); + fwrite(&ChallengerRanks[i], 4, 1, flux); + fwrite(&ChallengerNames[i], 1, 3, flux); + }*/ + fclose(flux); + } + } + return EXIT_SUCCESS; +} + diff --git a/APL1.2/TP03/records.c b/APL1.2/TP03/records.c new file mode 100644 index 0000000..ae07159 --- /dev/null +++ b/APL1.2/TP03/records.c @@ -0,0 +1,35 @@ +#include +#include +#include + +int main(int argc, char * argv[]) { + FILE* flux; + flux = fopen("top10", "r"); + + char name1[4] = "aaa"; + char name2[4] = "bbb"; + char name3[4] = "ccc"; + + if (flux) { + do { + int score; + char* name = calloc(3, sizeof(char)); + fread(&score, 4, 1, flux); + fread(name, 1, 3, flux); + + if (feof(flux)) break; + + strcpy(name3, name2); + strcpy(name2, name1); + strcpy(name1, name); + } while (!feof(flux)); + + printf("1ere place : %s\n", name1); + printf("2eme place : %s\n", name2); + printf("3eme place : %s\n", name3); + + fclose(flux); + } + return EXIT_SUCCESS; +} + diff --git a/APL1.2/TP03/top10 b/APL1.2/TP03/top10 new file mode 100644 index 0000000..f6c571a Binary files /dev/null and b/APL1.2/TP03/top10 differ