This assignment has two goals:
The due date is: Friday, October 18th, 1996 at 2.30pm (before class). You should expect to spend between six to eight hours of computer time over the next two weeks. You should also expect to spend one to two hours of thinking time, depending on how much prior programming experience you have. As usual, we will not accept late assignments (no matter how entertaining the excuse).
A) Create a file named time1.c. This program will read in a flight's starting and ending times (provided in military or twenty-four hour time) and print the length of the trip. Here is the sample input and output for our solution. The italics are our input, the monospace font is computer output.
10:15 11:30
Trip #0 was 1 hours, 15 minutes (75 minutes).
3:45 14:20
Trip #1 was 10 hours, 35 minutes (635 minutes).
18:30 23:15
Trip #2 was 4 hours, 45 minutes (285 minutes).
control-d
You can assume that the user will be well-behaved, that the times will always be valid, and that the second time will always be after the first. P> You should build this program based on the functions in the file timeutils.c. The idea is that you will compile this source file, then compile your program, and finally link the resulting object modules together to form an executable (as we will be discussing how to do in class). As a result, you get to pretend the functions in this file are part of the language, like printf and scanf.
In particular, you will find the following functions to be very useful in accomplishing this part.
int timeDifference(int start_hour_of_day, int start_minute_of_hour, int end_hour_of_day, int end_minute_of_hour);timeDifference takes two times (each in the form of an hour and a minute) and returns the number of minutes between them. For example,
puts 255 into n. If the second time precedes the first, you'll get a negative number.n = timeDifference(10,15,14,30);int timeIntoMinutes(int hour_of_day, int minute_of_hour);timeIntoMinutes takes an hour and a minute and returns how many minutes total are in that number of hours and minutes. For example,
puts 210 into n.n = timeIntoMinutes(3,30);int timeHour(int minute_of_day); int timeMinute(int minute_of_day);timeHour takes a number of minutes since midnight and returns the actual hour of the day. timeMinute takes a number of minutes since midnight and returns the actual minute within that hour. For example,
places a 3 into x and a 30 into y.x = timeHour(210); y = timeMinute(210);
Once you are confident your program processes the reasonable input correctly, you can modify it to handle the case where the flight's ending time precedes it's starting time. We will interpret this case to mean that the flight ended the next day (e.g., a 11:00pm flight from Honolulu to LA arrives at 5:15am the next day). So your program should produce the following output:
22:00 23:30
Trip #0 was 1 hours, 30 minutes (90 minutes).
22:00 3:45
Trip #1 was 5 hours, 45 minutes (345 minutes).
The last aspect of this part is making sure your program behaves sensibly if the user provides invalid input. The cases you need to check for are any garbage when you try to read a time, and for a starting or ending time that's invalid (an hour greater than 23 or less than 0, and a minute greater than 59 or less than 0). Here's an example that illustrates what your program is to do.
25:15 12:45Notice that if your program encounters garbage, it stops, but if it has a bad time (a time with illegal hours or minutes), it prints an error message but keeps going to process the next value. You will find the following functions from timeutils.c. helpful here:
ERROR: Invalid starting time for trip #0
12:45 25:15
ERROR: Invalid ending time for trip #1
21:98 11:78
ERROR: Invalid starting time for trip #2
some garbage
ERROR: Could not read times for trip #3.
int timeIsBefore(int first_hour, int first_minute, int second_hour, int second_minute)timeIsBefore takes two times (each in the form of an hour and a minute) and returns a 1 if the first time is before the second and a 0 otherwise. For example,
puts a 1 into n, butn = timeIsBefore(10,15,14,30);puts a 0 into n.n = timeIsBefore(14,30,10,15);int timeIsValid(int hour_of_day, int minute_of_hour)timeIsValid takes an hour and a minute and returns a 1 if they are both legal (the hour is between 0 and 23 and the minute is between 0 and 59). For example,
puts a 1 into n, butn = timeIsValid(12,59);puts a 0 into n.n = timeIsValid(25,16);
B) : Now copy your solution to the first part into a file time2.c. In this stage, you will modify this program to produce information about the average trip length, the length of the longest and shortest trips, and the total time spent travelling. This information is printed after all input has been read and processed and is only printed if there were no input errors. Here's an example:
10:15 16:30
Trip #0 was 6 hours, 15 minutes (375 minutes).
21:30 22:45
Trip #1 was 1 hours, 15 minutes (75 minutes).
22:15 5:30
Trip #2 was 7 hours, 15 minutes (435 minutes).
8:00 14:00
Trip #3 was 6 hours, 0 minutes (360 minutes).
control-d
Average trip was 5 hours, 11 minutes (311 minutes).
Longest trip was 7 hours, 15 minutes (435 minutes).
Shortest trip was 1 hours, 15 minutes (75 minutes).
Total time was 20 hours, 45 minutes (1245 minutes).
A) For this first part you will familiarize yourself with the given "helper functions" by utilizing them to print out a series of figures exactly as they are given to you. These functions will then be used to do the second part, where you will design a program that will read a pair of values and then print "EE150" in big block numbers and letters with that height and width (the first value is the height, the second value is the width). Here's a sample run of the program (the first line is input, everything else is output).
5 5
xxxxx
x
xxx
x
xxxxx
xxxxx
x
xxx
x
xxxxx
x
x
x
x
x
xxxxx
x
xxxxx
x
xxxxx
xxxxx
x x
x x
x x
xxxxx
7 7
xxxxxxx
x
x
xxxxx
x
x
xxxxxxx
xxxxxxx
x
x
xxxxx
x
x
xxxxxxx
x
x
x
x
x
x
x
xxxxxxx
x
x
xxxxxxx
x
x
xxxxxxx
xxxxxxx
x x
x x
x x
x x
x x
xxxxxxx
This may seem like quite a job, but if you build this as a series of functions, you'll find it's straightforward. We will start by giving you the following five "Helper functions":
void drawLine(int length)
{
int i;
for (i = 0; i < length; i++)
printf("x");
printf("\n");
}
void drawBlanks(int n)
{
int i;
for (i = 0; i < n; i++)
printf(" ");
}
void drawBothEndPointsNtimes(int lines, int length)
{ void drawBlanks(int n);
int i;
for (i=0; i < lines; i++)
{ printf("x");
drawBlanks(length-2);
printf("x\n");
}
}
void drawRightEndPointNtimes(int lines, int length)
{ void drawBlanks(int n);
int i;
for (i=0; i < lines; i++)
{ drawBlanks(length-1);
printf("x\n");
}
}
void drawLeftEndPointNtimes(int lines, int length)
{ int i;
for (i=0; i < lines; i++)
printf("x\n");
}
drawLine takes a number of x's to write and writes them, followed by a newline. drawBlanks is similar, except its parameter is a number of spaces to write and it doesn't write a newline. With drawLine we can write pieces of most of the numbers, like the top and bottom of the 0, the top, middle, and bottom of the 5 and also the top, middle and bottom of the letter E. drawLeftEndPointNtimes takes a length and number of lines and writes out one left x, followed by a newline. drawRightEndPointNtimes also takes a length and number of lines and writes out one right x, followed by a newline. drawBothEndPointsNtimes also takes a length and number of lines and writes out one left and one right x, followed by a newline.
So consider writing the 0. You need to familiarize yourself with the five functions that will help you to write out the number or letter. So for the first part, you are required to use these functions to write a program that will print out the following series of figures (exactly as shown):
xxxxx x x x x x x x x x x x x x x x x x x x x
Given these functions, you can now easily write the source file draw.c that will utilize the 5 "Helper functions" given to you.
B) : Copy the program from the previous part of the assignment into a file named numbers2.c. Now you'll begin to write functions that will produce the big block letters and numbers. Using the provided "helper functions" write the functions drawE, drawOne, drawFive and drawZero to write E, 1, 5 and 0 respectively. (The trick here is figuring how to calculate the correct value to pass to the drawEndPoints and drawRightEndPoints functions.)
Now you have one final task. Write the final version for all the numbers and letter and then call the number/letter drawing functions in order. To make things simple, you can assume that the user will always enter an odd number for the height.
BONUS*** If you can think of a "better way" to achieve the desired results or produce a clever method (code) for error checking you will be given a bonus!
To get credit for this assignment, you must electronically turn in the four files you created in Parts 1 (A&B) and 2 (A&B): time1.c, time2.c, numbers1.c and numbers2.c.