Question

In: Computer Science

please write the code in C format avoid using (<<count>>) Assume that you work for a...

please write the code in C format avoid using (<<count>>)

Assume that you work for a travel agency. Write a C program that performs 7 different tasks described below
for this company. The flights have the following
daily departure and arrival times:

hotel name cost ride cost
Rose 248$ 0$
Poprock 90$ 25$
flower 128$ 20$
departure time arrival time cost
7:15 am 8:25am 231$
8:15 am 9:25am 226$
9:15am 10:25am 226$
10:15am 11:25am 283$
11:15am 12:25pm 283$
3:15pm 4:25pm 226$
4:15pm 5:25pm 226$
5:15pm 6:25pm 401$

a) Based on the time entered by the customer, the closest departure time is displayed using 12- hour format.

b)the customer is asked if they would like a hotel and for how many days. hotel cost is mentioned above. Calculate the total cost (before taxes) and display it (flight + hotel for n number of days +ride).

c) now there is 2 types of discount:
Discount1: If the total fee is a multiple of 11, then the
customer gets a 6% discount.
Discount2: An additional discount of 7% is given to those customers whose subtotal
after discount1 is a multiple of the sum of digits of the customer’s day of birth.
Three examples are given below for your convenience. See Sample Input / output
for more clarification.
• Ex1: If the day of birth entered is 3, the customer will get an additional 7%
discount if the sub-total of their purchase after discount1 is a multiple of 3.
• Ex 2: If the day of birth entered is 12, the customer will get an additional 7%
discount if their purchase after discount1 is a multiple of 3 (since sum of digits of
day of birth (12) is 3).

c)13% tax is applied to the total cost and the final bill is?

Solutions

Expert Solution

Solution:

The below is the required Code in C.

#include<stdio.h>
#include<math.h>

int main ()
{
    int dept1,dept2,dept3,dept4,dept5,dept6,dept7,dept8,hh,mm,usertime;
//Declare an array of integer of size
    int departure[8];
    int noOfDays,index;

    char m1[80]="Closet Departure time is 07:15 A.M,arriving at 08:25 A.M";
    char m2[80]="Closet Departure time is 08:15 A.M,arriving at 09:25 A.M";
    char m3[80]="Closet Departure time is 09:15 A.M,arriving at 10:25 P.M";
    char m4[80]="Closet Departure time is 10:15 A.M,arriving at 11:25 P.M";
    char m5[80]="Closet Departure time is 11:15 A.M,arriving at 12:25 P.M";
    char m6[80]="Closet Departure time is 03:15 P.M,arriving at 04:25 P.M";
    char m7[80]="Closet Departure time is 04:15 P.M,arriving at 05:25 P.M";
    char m8[80]="Closet Departure time is 05:15 P.M,arriving at 06:25 P.M";


//Calculate time in minutes and set to array positions
//indexes
    dept1=7*60+15;
    departure[0]=dept1;

    dept2=8*60+415;
    departure[1]=dept2;

    dept3=9*60+15;
    departure[2]=dept3;

    dept4=10*60+15;
    departure[3]=dept4;

    dept5=11*60+15;
    departure[4]=dept5;

    dept6=15*60+15;
    departure[5]=dept6;

    dept7=16*60+15;
    departure[6]=dept7;

    dept8=17*60+15;
    departure[7]=dept8;

        printf("Enter a time in any format:");
//prompt for time in hh and mm
        scanf("%d:%d",&hh,&mm);

//calculate time in minutes
        usertime=hh*60+mm;

        int closeDepartureIndex=0;
        int closeDeparture=usertime-departure[0];

//find the closest time
        for(index=1; index<8; index++)
        {
            if(abs((usertime-departure[index]))<closeDeparture)
            {
                closeDeparture= usertime-departure[index];
                closeDepartureIndex=index;
            }
        }


//pring message of corresponding index
        if(closeDepartureIndex==0)
            printf("%s",m1);
        else if(closeDepartureIndex==1)
            printf("%s",m2);
        else if(closeDepartureIndex==2)
            printf("%s",m3);
        else if(closeDepartureIndex==3)
            printf("%s",m4);
        else if(closeDepartureIndex==4)
            printf("%s",m5);
        else if(closeDepartureIndex==5)
            printf("%s",m6);
        else if(closeDepartureIndex==6)
            printf("%s",m7);
        else if(closeDepartureIndex==7)
            printf("%s",m8);

        printf("\nFor How many Days you would like to stay in hotel: ");
        scanf ("%d",&noOfDays);
        printf ("Enter the hotel name Rose/Poprock/Flower: \n");
        char hotelname[10];
        int cost;
        scanf("%s",&hotelname);
        char hotel1[10]="Rose";
        char hotel2[10]="Poprock";
        char hotel3[10]="Flower";
        if(hotelname==hotel1)
        {
            cost=noOfDays*248;
            printf("The cost is %d",cost);
        }
        else if(hotelname==hotel2)
        {
            cost=noOfDays*90;

            printf("The cost is %d",cost);
        }
        else
        {
            cost=noOfDays*128;

            printf("The cost is %d",cost);
        }
        int dayofbirth;
        printf("\nEnter the day of birth\n");
        scanf("%d",&dayofbirth);
        if(dayofbirth==3&&cost%3==0)
        {
            cost-=cost*0.07;
        }
        else if(dayofbirth==12&&cost%7==0)
        {
            cost-=cost*0.12;
        }

//13% tax is applied to the total cost and the final bill i

    printf("The final bill is %d\n",cost+cost*0.13);

    return 0;
}

The following is the Ouput snapshot:

Enter a time in any format:15:25

Closet Departure time is 03:15 P.M,arriving at 04:25 P.M

For How many Days you would like to stay in hotel: 10

Enter the hotel name Rose/Poprock/Flower:

Rose

The cost is 1280

Enter the day of birth

3

The final bill is 73896.


Related Solutions

Please write this code in C++, also if you could please bold the names of the...
Please write this code in C++, also if you could please bold the names of the input files and provide comments for each choice. For this part, the program gives the user 4 choices for encrypting (or decrypting) the first character of a file. Non-lowercase characters are simply echoed. The encryption is only performed on lowercase characters. If c is char variable, then islower(c) will return true if c contains an lowercase character, false otherwise To read a single character...
Using newer versions of MATLAB, please write the complete code for: 1. Assume Y is an...
Using newer versions of MATLAB, please write the complete code for: 1. Assume Y is an exponential random variable with rate parameter λ=2. (1) Generate 1000 samples from this exponential distribution using inverse transform method (2) Compare the histogram of your samples with the true density of Y.
Please write code in C, thank you. Write a program that reads a list of integers,...
Please write code in C, thank you. Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither. The input begins with an integer indicating the number of integers that follow. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: all even Ex: If the input is: 5 1 3 5 7 9...
please write the code in C not c++, and not to use Atoi or parseint to...
please write the code in C not c++, and not to use Atoi or parseint to parse the string, Thank you. #include <stdio.h> #include <stdbool.h> /* * The isinteger() function examines the string given as its first * argument, and returns true if and only if the string represents a * well-formed integer. A well-formed integer consists only of an * optional leading - followed by one or more decimal digits. * Returns true if the given string represents an...
infographic project write Routine Internal Proposal in memo format. your supervisor assume you work in the...
infographic project write Routine Internal Proposal in memo format. your supervisor assume you work in the university recruitment offive or in charge of communication within academic department. you want to propose that the department increase its recruitment efforts in response to a 5 years decline. of Human Resources Management. your proposal is to create infographic that can be handed out to prospective students, sent to regional high school, and distributed electric ally via email and in department wedsite 1. identify...
Please code C# Convert the following for loop into a while loop: for(int count = 8;...
Please code C# Convert the following for loop into a while loop: for(int count = 8; count > 0; count--) { Console.WriteLine(count); }
I am running this code using C to count the words in char array, but somehow...
I am running this code using C to count the words in char array, but somehow it keeps counting the total characters + 1. Any solution to fix this problem? #include <stdio.h> int main() {    char input[1001];    int count =0;    fgets(input, 1001, stdin);    char *array = input;    while(*array != '\0')       {        if(*array == ' '){            array++;        }        else{        count++;        array++;...
C++ Code! This code was written/implemented using the "class format." How would I go about in...
C++ Code! This code was written/implemented using the "class format." How would I go about in converting it to the "struct format?" #include <iostream> #include <iomanip> using namespace std; class ListNode{ public: string course_name; string course_number; string course_room; ListNode* next; ListNode(){ this->next = NULL; } ListNode(string name, string number, string room){ this->course_name = name; this->course_number = number; this->course_room = room; this->next = NULL; } }; class List{ public: ListNode* head; List(){ this->head = NULL; } void insert(ListNode* Node){ if(head==NULL){ head...
Code in C++ please You are going to write a program for Computer test which will...
Code in C++ please You are going to write a program for Computer test which will read 10 multiple choice questions from a file, order them randomly and provide the test to the user. When the user done the program must give the user his final score
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT