problem3

# problem3 - University of California San Diego ECE15...

This preview shows pages 1–3. Sign up to view the full content.

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

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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 0 , 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 0 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. Output The program should write its output to the file skyline.out . For each test case in the input file, the program should print the case number (beginning with 1 ) followed by the length of the resulting skyline. Print this length rounded to the nearest integer (with 0.5 rounded up). Here is a sample output file skyline.out
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern