Added td7

This commit is contained in:
Yohan Boujon 2020-09-12 18:34:37 +02:00
parent fd91be9bdd
commit 94de39f68c
7 changed files with 271 additions and 0 deletions

60
td7/exo1&2.c Executable file
View file

@ -0,0 +1,60 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_NOM 64
#define MAX_PRENOM 64
typedef struct
{
char nom[MAX_NOM+1];
char prenom[MAX_PRENOM+1];
unsigned int age;
} INDIV;
void saisie(INDIV* individu2);
void petit(INDIV individu1, INDIV individu2, INDIV* le_plus_jeune);
void affichage(INDIV le_plus_jeune);
int main()
{
INDIV individu1, individu2, le_plus_jeune;
strcpy(individu1.nom,"BOND");
strcpy(individu1.prenom,"James");
individu1.age=7;
saisie(&individu2);
petit(individu1,individu2,&le_plus_jeune);
affichage(le_plus_jeune);
return 0;
}
void saisie(INDIV* individu2)
{
printf("Nom : ");
gets((*individu2).nom);
printf("Prenom : ");
gets((*individu2).prenom);
printf("Age : ");
scanf("%u",&((*individu2).age));
while(getchar()!='\n') {;}
}
void petit(INDIV individu1, INDIV individu2, INDIV* le_plus_jeune)
{
if(individu1.age<individu2.age)
{
*le_plus_jeune=individu1;
}
else
{
*le_plus_jeune=individu2;
}
}
void affichage(INDIV le_plus_jeune)
{
printf("\n Le plus jeune est :");
printf("\n\nNOM : %s", le_plus_jeune.nom);
printf("\n\nPrenom : %s", le_plus_jeune.prenom);
printf("\n\nAge : %u", le_plus_jeune.age);
printf("\nTaper ENTRER pour sortir");
getchar();
}

61
td7/exo4.c Executable file
View file

@ -0,0 +1,61 @@
#include<stdio.h>
#include<string.h>
# define MAX_NOM 64
# define MAX_PRENOM 64
typedef struct
{
char nom[MAX_NOM+1];
char prenom[MAX_PRENOM+1];
int numero_compte;
float solde;
} CLIENT;
void afficher_client(CLIENT c);
void crediter_client(CLIENT* c, float montant);
int main(void)
{
//déclaration d'un client avec initialisation
CLIENT c1= {"LAMY","Alexandra",59605,5000};
//déclaration d'un client sans initialisation
CLIENT c2,c3,c4;
//enregistrement de clients sans initialisation
float solde = 4500;
c2=(CLIENT){.nom="LEGAULOIS",.prenom="Asterix",.numero_compte=59606,.solde=solde};
c3=(CLIENT){"DUPOND","Robert",c2.numero_compte+1,2000};
//changement de nom suite à un mariage
strcpy(c1.nom,"DUJARDIN");
//copie d'un client
c4=c2;
//RAZ d'un client
c2=(CLIENT){"","",0,0};
//retirer
c3.solde=c3.solde-2500;
//créditer
float somme = 90000;
crediter_client(&c4, somme);
afficher_client(c1);
afficher_client(c2);
afficher_client(c3);
afficher_client(c4);
return 0;
}
void afficher_client(CLIENT c)
{
printf("\n\t%10s\t%10s\t%10d\t%10.2fEuros", c.nom, c.prenom, c.numero_compte, c.solde);
}
void crediter_client(CLIENT *c, float montant)
{
(*c).solde=(*c).solde+montant;
}

47
td7/exo5.c Executable file
View file

@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX_NOM 64
typedef struct
{
char nom[MAX_NOM+1];
float bac;
} BAKA;
void saisie(BAKA* etudiant);
void petit(BAKA x1, BAKA x2);
int main()
{
BAKA etudiant1, etudiant2;
saisie(&etudiant1);
printf("\n");
saisie(&etudiant2);
petit(etudiant1,etudiant2);
return 0;
}
void saisie(BAKA* etudiant)
{
printf("NOM : ");
gets((*etudiant).nom);
do{
printf("MOYENNE BAC : ");
scanf("%f",&((*etudiant).bac));
while(getchar()!='\n') {;}
}while((*etudiant).bac>20 || (*etudiant).bac<0);
}
void petit(BAKA x1, BAKA x2)
{
if(x1.bac<x2.bac)
{
printf("%s %.2f\n",x2.nom,x2.bac);
printf("%s %.2f",x1.nom,x1.bac);
}
else
{
printf("%s %.2f\n",x1.nom,x1.bac);
printf("%s %.2f",x2.nom,x2.bac);
}
}

47
td7/main.c Executable file
View file

@ -0,0 +1,47 @@
#include <stdio.h>
#include <stdlib.h>
#define MAX_NOM 64
typedef struct
{
char nom[MAX_NOM+1];
float bac;
} BAKA;
void saisie(BAKA* etudiant);
void petit(BAKA x1, BAKA x2);
int main()
{
BAKA etudiant1, etudiant2;
saisie(&etudiant1);
printf("\n");
saisie(&etudiant2);
petit(etudiant1,etudiant2);
return 0;
}
void saisie(BAKA* etudiant)
{
printf("NOM : ");
gets((*etudiant).nom);
do{
printf("MOYENNE BAC : ");
scanf("%f",&((*etudiant).bac));
while(getchar()!='\n') {;}
}while((*etudiant).bac>20 || (*etudiant).bac<0);
}
void petit(BAKA x1, BAKA x2)
{
if(x1.bac<x2.bac)
{
printf("%s %.2f\n",x2.nom,x2.bac);
printf("%s %.2f",x1.nom,x1.bac);
}
else
{
printf("%s %.2f\n",x1.nom,x1.bac);
printf("%s %.2f",x2.nom,x2.bac);
}
}

41
td7/td7info.cbp Executable file
View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="td7info" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/td7info" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/td7info" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="main.c">
<Option compilerVar="CC" />
</Unit>
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

5
td7/td7info.depend Executable file
View file

@ -0,0 +1,5 @@
# depslib dependency file v1.0
1607699339 source:d:\data\alzyohan\geii\info\td7info\td7info\main.c
<stdio.h>
<stdlib.h>

10
td7/td7info.layout Executable file
View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="4" zoom_2="0">
<Cursor>
<Cursor1 position="723" topLine="0" />
</Cursor>
</File>
</CodeBlocks_layout_file>