0% found this document useful (0 votes)
15 views13 pages

Erreur C++

Uploaded by

mbouhlais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

Erreur C++

Uploaded by

mbouhlais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

#include <stdio.

h>

#include <stdlib.h>

#include <stdbool.h>

#include <string.h>

typedef struct user {

char firstname[50];

char lastname[50];

int id;

struct user *next;

} user;

typedef struct room {

char name[50];

int capacity;

int id;

struct room *next;

} room;

typedef struct date {

int day;

int month;

int year;

} date;

typedef struct resrv {


int id;

int roomid; // Added room ID to link reservation with room

char name[50];

int indusr; // User ID who made the reservation

date date;

struct resrv *next;

} resrv;

void ajout(user **head) {

user *r = malloc(sizeof(user));

printf("Please give your id \n");

scanf("%d", &r->id);

printf("Give me your first name \n");

scanf("%s", r->firstname);

printf("Please give me your last name \n");

scanf("%s", r->lastname);

r->next = *head;

*head = r;

void afficher(user *head) {

user *p = head;

while (p != NULL) {

printf("%d\n", p->id);

printf("%s\n", p->firstname);

printf("%s\n", p->lastname);
p = p->next;

user *find(user *head, int id, char *name) {

user *p = head;

while (p != NULL) {

if (p->id == id || strcmp(p->firstname, name) == 0) {

return p;

p = p->next;

return NULL;

void ajoutroom(room **head) {

room *l = malloc(sizeof(room));

printf("Please give the name of your room: ");

scanf("%s", l->name);

printf("Please give me the id: ");

scanf("%d", &l->id);

printf("Please give me the capacity: \n");

scanf("%d", &l->capacity);

l->next = *head;

*head = l;

}
void affichroom(room *head) {

room *p = head;

while (p != NULL) {

printf("%d\n", p->id);

printf("%s\n", p->name);

printf("%d\n", p->capacity);

p = p->next;

room *finderrom(room *head, int id) {

room *p = head;

while (p != NULL) {

if (p->id == id) {

return p;

p = p->next;

return NULL;

void ajoutrsrv(resrv **head) {

resrv *l = malloc(sizeof(resrv));

printf("Please give your reservation id: ");

scanf("%d", &l->id);
printf("Please give the room id for the reservation: ");

scanf("%d", &l->roomid);

printf("Please give the user id making the reservation: ");

scanf("%d", &l->indusr);

printf("Please give the name of your reservation: ");

scanf("%s", l->name);

printf("Give the date (day month year): ");

scanf("%d %d %d", &l->date.day, &l->date.month, &l->date.year);

l->next = *head;

*head = l;

void affichresrv(resrv *head) {

resrv *p = head;

while (p != NULL) {

printf("%d\n", p->id);

printf("%s\n", p->name);

printf("Room ID: %d, User ID: %d\n", p->roomid, p->indusr);

printf("%d-%d-%d\n", p->date.day, p->date.month, p->date.year);

p = p->next;

bool isRoomAvailable(resrv *reservations, int roomId, date desiredDate) {

resrv *current = reservations;

while (current != NULL) {


if (current->roomid == roomId &&

current->date.day == desiredDate.day &&

current->date.month == desiredDate.month &&

current->date.year == desiredDate.year) {

return false;

current = current->next;

return true;

user *delete(user *head, int id) {

user *current = head, *prev = NULL;

while (current != NULL && current->id != id) {

prev = current;

current = current->next;

if (current == NULL) {

printf("User with id %d not found.\n", id);

return head;

if (prev == NULL) {

head = current->next;

} else {
prev->next = current->next;

free(current);

return head;

room *deleteroom(room *head, int id) {

room *current = head, *prev = NULL;

while (current != NULL && current->id != id) {

prev = current;

current = current->next;

if (current == NULL) {

printf("Room with id %d not found.\n", id);

return head;

if (prev == NULL) {

head = current->next;

} else {

prev->next = current->next;

free(current);
return head;

resrv *deleter(resrv *head, int id) {

resrv *current = head, *prev = NULL;

while (current != NULL && current->id != id) {

prev = current;

current = current->next;

if (current == NULL) {

printf("Reservation with id %d not found.\n", id);

return head;

if (prev == NULL) {

head = current->next;

} else {

prev->next = current->next;

free(current);

return head;

void demin() {
printf("si vous avez ajouter un user entre 1 \n");

printf("si vous avez ajouter un room clikier sur 2 \n");

printf("si vous avez ajouer un reserv cliker sur 3 \n");

printf("si vous avez deleter un user cliker sur 4 \n ");

printf("si vous avez deleter un romm cliker sur 5 \n");

printf("si vous avez deleter un resrv cliker sur 6 \n");

printf("si vous avez afficher un user cliker sur 7 \n");

printf("si vous avez afficher un room cliker sur8 \n");

printf("si vous avez afficer un resrv cliker sur 9 \n");

printf("si vous voulez chercher sur utilister cliker sur 10 \n");

printf("si vous voulez chrcher sur room entre 11\n");

printf("si vous voulez cherher sur resrv entre 12\n");

printf("si vous voulez verfier si le room est disponible entre 13\n");

int main() {

demin();

int id, roomId;

date checkDate;

int choix;

bool exit = false;

user *l = NULL;

room *p = NULL;

resrv *q = NULL;
do {

printf("Please give your choice: \n");

scanf("%d", &choix);

switch (choix) {

case 1:

ajout(&l);

break;

case 2:

ajoutroom(&p);

break;

case 3:

ajoutrsrv(&q);

break;

case 4:

printf("Please give your id: \n");

scanf("%d", &id);

l = delete(l, id);

break;

case 5:

printf("Please give your id: \n");

scanf("%d", &id);

p = deleteroom(p, id);

break;

case 6:

printf("Please give your id: \n");


scanf("%d", &id);

q = deleter(q, id);

break;

case 7:

afficher(l);

break;

case 8:

affichroom(p);

break;

case 9:

affichresrv(q);

break;

case 10:

printf("Please give your id: \n");

scanf("%d", &id);

user *foundUser = find(l, id, "");

if (foundUser == NULL) {

printf("User with id %d not found.\n", id);

} else {

printf("User found: %s %s\n", foundUser->firstname, foundUser->lastname);

break;

case 11:

printf("Please give your id: \n");

scanf("%d", &id);

room *foundRoom = finderrom(p, id);


if (foundRoom == NULL) {

printf("Room with id %d not found.\n", id);

} else {

printf("Room found: %s\n", foundRoom->name);

break;

case 12:

printf("Please give your reservation id: \n");

scanf("%d", &id);

resrv *foundResrv = deleter(q, id);

if (foundResrv == NULL) {

printf("Reservation with id %d not found.\n", id);

} else {

printf("Reservation found: %s\n", foundResrv->name);

break;

case 13:

printf("Please enter the room ID: \n");

scanf("%d", &roomId);

printf("Enter the date to check (day month year): \n");

scanf("%d %d %d", &checkDate.day, &checkDate.month, &checkDate.year);

if (isRoomAvailable(q, roomId, checkDate)) {

printf("The room %d is available on %d-%d-%d.\n", roomId, checkDate.day,


checkDate.month, checkDate.year);

} else {
printf("The room %d is not available on %d-%d-%d.\n", roomId,
checkDate.day, checkDate.month, checkDate.year);

printf("Invalid choice.\n");

printf("Do you want to continue? 1 for yes, 0 for no: ");

scanf("%d", &exit);

exit = !exit;

} while (!exit);

return 0;

break;

default:

You might also like