Sunday, 24 April 2022

5. Define a structure that can describe a Hotel. It should have members that include name, address, grade, room charges, grade and no of rooms. Write a function to print out all hotel details with room charges less than a given value.

 


#include<stdio.h>
#include<conio.h>

struct hotel
{
    char name[20],add[50],grade[3];
    int rch,rno;
}s[20];

void lesscharges(int);

void main()
{
    int no,i;
    clrscr();

    printf("how many hotel details you want to enter: ");
    scanf("%d",&no);

    for(i=0; i<no; i++)
    {
        printf("\nenter hotel name: ");
        scanf("%s",s[i].name);
        printf("enter hotel address: ");
        scanf("%s",s[i].add);
        printf("enter hotel grade: ");
        scanf("%s",s[i].grade);
        printf("enter hotel charges: ");
        scanf("%d",&s[i].rch);
        printf("enter no of rooms: ");
        scanf("%d",&s[i].rno);

    }
    lesscharges(no);
    getch();
}

void lesscharges(int num)
{
    int i,min,k;

    min = s[0].rch;

        for(i=0; i<num; i++)
        {
            if(s[i].rch < min)
            {
                min = s[i].rch;
                k = i;
            }
            else if(min == s[0].rch)
            {
                k = 0;
            }
        }

    printf("\n\n!! room charges lessthan given value !!");
    printf("\n\nhotel name: %s",s[k].name);
    printf("\nhotel address: %s",s[k].add);
    printf("\nhotel grade: %s",s[k].grade);
    printf("\nhotel charges: %d",s[k].rch);
}

/*      output:

how many hotel details you want to enter: 3

enter hotel name: taj
enter hotel address: ahmedabad
enter hotel grade: A
enter hotel charges: 1500
enter no of rooms: 1

enter hotel name: shyam
enter hotel address: goa
enter hotel grade: B
enter hotel charges: 1300
enter no of rooms: 1

enter hotel name: vihar
enter hotel address: div
enter hotel grade: A
enter hotel charges: 1400
enter no of rooms: 1


!! room charges lessthan given value !!

hotel name: shyam
hotel address: goa
hotel grade: B
hotel charges: 1300

*/

No comments:

Post a Comment

python programs

1. sum of two number