Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cstructHotel
//gcc 7.4.0 //define a structure that can describe a hotel and has following members: name,address, grade,number of rooms and average room charge; //write a function to print out hotels of a given grade in order of charges and another function to print out hotels with room charges less than a given value //this code is created by Rezaul Hoque on August 17,2021;contact: jewelmrh@yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <stdio.h> #include <stdlib.h> #include <string.h> const int n=5; struct hotels{ char name[30]; char add[50]; int grade; int room; int charge; }; void gradeSort(struct hotels []); void chargeQ(struct hotels []); void display(struct hotels []); void gradeSort(struct hotels hotel[5]){ int gr; char temp4[30]; char temp5[50]; printf("Enter the grade(1/2/3):\n"); scanf("%d",&gr); for(int i=0;i<5;i++) if(hotel[i].grade==gr) { for(int l=1;l<n;l++) { for(int j=1;j<n-l;j++) { if(hotel[j-1].charge>hotel[j].charge){ int temp=hotel[j-1].charge; hotel[j-1].charge= hotel[j].charge; hotel[j].charge= temp; int temp2=hotel[j-1].grade; hotel[j-1].grade= hotel[j].grade; hotel[j].grade= temp2; int temp3=hotel[j-1].room; hotel[j-1].room= hotel[j].room; hotel[j].room= temp3; strcpy(temp4,hotel[j-1].name); strcpy(hotel[j-1].name,hotel[j].name); strcpy(hotel[j].name,temp4); strcpy(temp5,hotel[j-1].add); strcpy(hotel[j-1].add,hotel[j].add); strcpy(hotel[j].add,temp5); } } } } printf("Hotel\tAddress\tGrade\tRooms\tCharge\n"); for(int i=0;i<5;i++) if(hotel[i].grade==gr) printf("%5s\t%5s\t%2d\t%3d\t%4d\n",hotel[i].name,hotel[i].add,hotel[i].grade,hotel[i].room,hotel[i].charge); } void chargeQ(struct hotels hotel[5]){ int cq; printf("Enter desired room charge to get the list of hotels:\n"); scanf("%4d\n",&cq); printf("For room charge $%3d per night or below,the hotels are:\n",cq); printf("Hotel\tAddress\tGrade\tRooms\tCharge\n"); for(int i=0;i<5;i++) if(hotel[i].charge<=cq){ printf("%5s\t%5s\t%2d\t%3d\t%4d\n",hotel[i].name,hotel[i].add,hotel[i].grade,hotel[i].room,hotel[i].charge); } } void display (struct hotels hotel [5]){ printf("Hotel\tAddress\tGrade\tRooms\tCharge\n"); for(int i=0;i<5;i++) printf("%5s\t%5s\t%2d\t%3d\t%4d\n",hotel[i].name,hotel[i].add,hotel[i].grade,hotel[i].room,hotel[i].charge); } int main() { struct hotels hotel[5]; for(int i=0;i<5;i++) scanf("%5s\t%5s\t%2d\t%3d\t%4d\n",hotel[i].name,hotel[i].add,&hotel[i].grade,&hotel[i].room,&hotel[i].charge); display(hotel); gradeSort(hotel); chargeQ(hotel); return 0; }
run
|
edit
|
history
|
help
0
AC_setting_example
strcat
20171103_factorial
primeno
PointTeleBook
Project 3 part 2 Book v0.6
guia 4 terminada
ARREGLO DE VARIABLES DE TIPO STRUCT
C Pointers Experiment (So bad don't use)
First program.c