QuestionQuestion

Transcribed TextTranscribed Text

Assignment #1 In this assignment, you will create some simple programs in C to get used to the language (i.e., control structs, variables, arrays), the Linux environment, and the compiling/running process. ALL of your code for both questions must be written neatly with proper indentation and have a reasonable amount of comments. If you do not, you will be losing multiple marks. (1) Window Tinting Assume that you have a company that tints building windows. You have found a good price on nice gold tinting film that comes in rolls that are 5 feet wide and 92 feet long. You want to write a program that determines the number of rolls that will be needed to be purchased to cover a building completely. Your program should assume that each window is the exact same size in the building and that the windows are always less than or equal to 5 feet wide. The program should ask the user for the number of floors in the building, the number of windows on each floor (includes all sides of the building) and the dimensions of the window (in inches). The program should then calculate the number of rolls needed. Note that when tinting a window, it must be done with one entire piece of film. That is, you CANNOT cut pieces of film to fit on the windows. You should determine whether the 5 foot width of tint roll is able to cover two or more windows. For example, if the windows are 12" x 24", then you can cover five windows with just two feet of roll … but if placed sideways, you can only cover 4 windows, with a little waste left over (see picture below). You should choose the best option in this case. However, you must not apply any other “packing/fitting” algorithm … for the purpose of marking consistency. Just choose which direction to put the tint on … up and down … or left to right. The program should output the correct number of tinting rolls that need to be purchased. Make sure to define appropriate constants in your code, as this represents proper coding style. Also, make sure to test adequately. (2) Scheduling Reservations Write a program called reservations.c that simulates some people trying to reserve seats at a restaurant for dinner. The program MUST work as follows: • The restaurant takes reservations anywhere from 4pm until 9pm. That means … someone can phone in and ask to reserve a table for a certain number of people starting at some specific time in the range of 4pm until 9pm. The people are allowed to stay past 9pm, but no more reservations can be made after 9pm. • The restaurant can seat at most 80 people at any time, on any day of the week. Reservations may be made at 15-minute intervals starting at 4pm. Hence, 4:00pm, 4:15pm, 4:30pm, 4:45pm, 5:00pm, 5:15pm, …., 8:45pm, 9:00pm. • The program MUST keep track of reservations by using a two dimensional array to indicate the number of patrons in the restaurant at any given timeslot. • The program must attempt to make 100 random (must be unique each time you run) reservations by choosing o A random day of the week o A random timeslot (i.e., there are 21 options from 4pm-9pm) o A random size (i.e., number of people) for that reservation which can be at most 40 • For each attempted reservation, you should show (nicely on he terminal window) the number of people for the reservation, the day of the week and the start time of the reservation. • If the reservation is able to be made, it should indicate that the reservation was accepted, otherwise it should indicate that it was denied. • In order to accept a reservation … we need to estimate the length of stay for each reservation. Assume the following: o If the reservation is for 2 people, the estimate length of stay is 60 minutes. o If the reservation is between 3-7 people, the estimate is for 75 minutes. o If the reservation is between 8-11 people, the estimate is for 105 minutes. o Otherwise the estimate should be for 120 minutes. • The program should accept the reservation if the restaurant can hold that many people for the duration of the estimated length of stay. For example, if a 5pm reservation for 4 people is made, you need to ensure that there are at most 76 people (i.e., restaurant capacity minus the reservation size) currently reserved for the following timeslots: 5:00pm, 5:15pm, 5:30pm, 5:45pm and 6:00pm. If any are over the value of 76, then the reservation should not be made, it should be denied. • After each random reservation is made (or denied), the program should display a nicelyformatted table showing the current reservation counts for each timeslot. This displaying must be done by means of a function that takes the 2D array as a parameter. The table should look as show below on the left. Note that it indicates the number of people currently reserved for that timeslot. You can see that on Tuesday, a reservation for 12 people has been reserved starting at 5:30pm and they are estimated to be gone by 7:30pm. The smaller group of 2 people on Sunday at 5:00pm are estimated to only be there for 1 hour. The image on the right shows the results after quite a few reservations have been made … many of them overlapping. ___________________________________________________________________________

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

/*
* File:   main.c
* Author:
*
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const int DAY_NUM = 7; // a week has 7days
const int SLOT_NUM = 21; // there are 21 15-minutes-intervals from 4 pm to 9 pm
const int MAX_SIZE = 40; // max random size per generation

/**
* convert integer to name of day in the week
* @param day from 0 to 6
* @param name from Sunday to Saturday
*/
void dayOfWeek(int day, char name[]);

/**
* convert slot number to time
* @param slot from 0 to 20
* @param name from 4pm to 9pm
*/
void startTime(int slot, char name[]);

/**
* estimate length of time which the patron
* will take
* @param size number of patron
* @return number of allocated slot
*/...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$86.00 $43.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats