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++. Using iostream and cstring library. Write a function that will...
Please, write this code in c++. Using iostream and cstring library. Write a function that will delete all words in the given text that meets more that one time. Also note than WORD is sequence of letters sepereated by whitespace. Note. The program have to use pointer. Input: First line contains one line that is not longer than 1000 symbols with whitespaces. Each word is not longer than 30 symbols. Output: Formatted text. example: input: Can you can the can...
Please, write code in c++. Using iostream and cstring library. You given a text.Your task is...
Please, write code in c++. Using iostream and cstring library. You given a text.Your task is to write a function that will find the longest sequence of digits inside. Note that the output have to be presened just like in sample. Note. The program have to use pointer. Input: First line contains one line that is not longer than 1000. Output: The longest sequence of numbers.All numbers are positive and integers. example: input: 101 fdvnjfkv njfkvn fjkvn jffdvfdvfd2010 output: 2010
Please, write code in c++. Using iostream and cstring library Write a function that will find...
Please, write code in c++. Using iostream and cstring library Write a function that will find and return most recent word in the given text. The prototype of the function have to be the following void mostRecent(char *text,char *word) In char *word your function have to return the most recent word that occurce in the text. Your program have to be not case-sensitive(ignore case - "Can" and "CAN" are the same words) Also note than WORD is sequence of letters...
Please answer QC,D,E,F using the code provided at the end please. A. Write C code to...
Please answer QC,D,E,F using the code provided at the end please. A. Write C code to define a structure called date that has three fields day, month, year, all of which are ints. B. Write C code to define a structure called person that has fields for name (50 char array), dateOfBirth (date struct from Q1), address (200 char array), phoneNum (20 char array), and ID (int). C. Write a C program that uses the person structure from Q2, and...
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...
Please, write code in c++. Using iostream and cstring library Use pointers! You given a text.Your...
Please, write code in c++. Using iostream and cstring library Use pointers! You given a text.Your task is to write a function that will find the longest sequence of digits inside. Note that the output have to be presened just like in sample. Note. The program have to use pointer. Input: First line contains one line that is not longer than 1000. Output: The longest sequence of numbers.All numbers are positive and integers. Samples: № INPUT OUTPUT 1 This is...
Fix the C++ code to count the number of inversions using the given array. The answer...
Fix the C++ code to count the number of inversions using the given array. The answer is 8 inversions, but I am only getting 6 inversions. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #include <iostream> using namespace std; int mergeInversion(int arr[], int l, int m, int r) {     // size of the two arrays     int n1 = m - l + 1;     int n2 = r - m;     // create temporary arrays     int L[n1];     int R[n2];     // Copy the...
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 code in c++. Using iostream library A chessboard pattern is a pattern that satisfies...
Please, write code in c++. Using iostream library A chessboard pattern is a pattern that satisfies the following conditions: • The pattern has a rectangular shape. • The pattern contains only the characters '.' (a dot) and 'X' (an uppercase letter X). • No two symbols that are horizontally or vertically adjacent are the same. • The symbol in the lower left corner of the pattern is '.' (a dot). You are given two numbers. N is a number of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT