APL 1.2
This commit is contained in:
parent
cc9a68d4a1
commit
98e66379f9
73
APL1.2/TP02/alterations.c
Normal file
73
APL1.2/TP02/alterations.c
Normal file
@ -0,0 +1,73 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<graph.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
35
APL1.2/TP02/complexes.c
Normal file
35
APL1.2/TP02/complexes.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<math.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
12
APL1.2/TP02/date.c
Normal file
12
APL1.2/TP02/date.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<time.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
14
APL1.2/TP02/groupe.c
Normal file
14
APL1.2/TP02/groupe.c
Normal file
@ -0,0 +1,14 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<sys/types.h>
|
||||
#include<grp.h>
|
||||
#include<string.h>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
struct group * students21 = getgrnam("students21");
|
||||
char ** names = students21->gr_mem;
|
||||
|
||||
printf("%c", names[1]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
57
APL1.2/TP02/rectangles.c
Normal file
57
APL1.2/TP02/rectangles.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<graph.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
15
APL1.2/TP02/tailles.c
Normal file
15
APL1.2/TP02/tailles.c
Normal file
@ -0,0 +1,15 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
54
APL1.2/TP03/challenger.c
Normal file
54
APL1.2/TP03/challenger.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
35
APL1.2/TP03/records.c
Normal file
35
APL1.2/TP03/records.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
BIN
APL1.2/TP03/top10
Normal file
BIN
APL1.2/TP03/top10
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user