This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: University of California San Diego ECE15: Engineering Computation Final Exam: Problem # 3 The city of Denver, Colorado, known as “gateway to the Rocky Mountains,” hired the Dot-C advertising agency to promote the city to potential visitors. One of the slogans suggested by Dot-C Advertising stated that the mountain ranges around Denver create the most beautiful skyline in the US. However, the City Hall objected, saying that “the most beautiful skyline” is a subjective and unverifiable claim, and could therefore be considered misleading. After much deliberation, Dot-C Advertising came up with the alternative slogan “Denver — the longest skyline in the US!” Although not as catchy, it is hopefully verifiable. This is where you come in. As the Programmer-in-Chief at Dot-C Advertising , your task is to write a C program, called skyline.c , that computes the length of a skyline. Consider each mountain as a two-dimensional isosceles triangle (the right and left slopes of the moun- tain correspond to sides of the same length ). A skyline is the outline of one or more mountains. The skyline’s length is the total length of this outline. For example, with reference to the four figures below, the figures on the left represent mountain ranges, while the figures on the right illustrate the resulting skylines (bold lines) as well as those mountain slopes that do not contribute to the skyline (dashed lines). The horizon is indicated by the brown horizontal line in all the figures. Note that parts of the horizon line that lie between mountains are not considered skyline, and so do not contribute to its total length. Also note that a given mountain can be completely obscured by another mountain, or several mountains. Input The program should read its input from the file skyline.dat . The input file consists of one or more test cases, which are descriptions of mountain ranges. Each test case starts with a line containing a sin- gle positive integer N , which specifies the number of mountains in the range. Each of the next N lines contains three positive integers X , H , and B , which specify the horizontal position of the mountain’s peak, the height of the mountain, and the width of its base, respectively. You can assume that the base of each mountain coincides with the horizon line. You can also assume that N 100 . The last test case is followed by a line containing the number , which is the last line in the file. Here is a sample input: 1 100 50 100 3 20 30 35 37 24 29 60 20 13 2 1 40 60 1 20 30 You do not need to check the validity of data given in the input file: you can assume that it conforms to the specifications detailed above. You can also assume that the input file contains at most 1024 lines....
View Full Document
This note was uploaded on 04/15/2010 for the course ECE ECE15 taught by Professor Vardy during the Fall '08 term at UCSD.
- Fall '08