Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MY CODE SO FAR: #include // Defined Constants #define FIRST_CAR_LENGTH 10 #define NORMAL_CAR_LENGTH 8 #define CAR_CAPACITY 4 int main(void) { // declared variables int track_length,maximum;

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

MY CODE SO FAR:

#include // Defined Constants #define FIRST_CAR_LENGTH 10 #define NORMAL_CAR_LENGTH 8 #define CAR_CAPACITY 4 int main(void) { // declared variables int track_length,maximum; int safe_train_length; int passengers; int total_length; int trains,cars; int surplus; int car_length; int i,N; // value for N printf("What is the value for N? "); scanf("%d", &N); // loop for taking user input to N time(s) for(i=0;i=NORMAL_CAR_LENGTH){ total_length+=NORMAL_CAR_LENGTH; surplus=maximum-total_length; cars++; } // safe train length (25% of total track) safe_train_length=track_length*0.25; car_length=maximum; // calculating number of trains while(car_length0){ printf("Maximum train length has a surplus of %d feet. ",surplus); printf(" "); } } return 0; }<>

Problem B: Roller Coaster Redesign (coaster2.c)(50 points Your boss has noticed that maximizing the length of the train does not always maximize the number of passengers. She's come up with a great idea for you to improve your program, so that you can calculate the actual maximum number of passengers the roller coaster can support. Her idea is as follows Let's say the maximum length of a train is 55. Then, we can simply start by trying out a train of length 10 (one car), and seeing how many passengers such a train would support. Then, we can try a train of length 18 (two cars) and recalculate the number of passengers this design would support. If this is better than the best design we've seen so far, simply save this new value. Continue in this fashion, until we've tried all possible trains. In this situation, we would try trains of lengths 10, 18, 26, 34, 42, and 50. (We stop here because the next train, of length 58, would be too long.) In each of these candidate lengths, compute the following quantity: total rollercoaster passengers divided by the total length of all the trains. Store each value in an array, so you will be storing as many values as there are lengths. Finally, compute the average of those values, and print it out as a final answer The user will input the same information as was inputted in assignment #1 part C Note that this time you will not be inputting the number N, and you will not print the message about the surplus. This time, however, your program should output the actual number of maximum people the ride can support, the number of cars per train that achieves this maximum, and the final average of the passengers/length ratio Do the problem in small stages. First, ensure that you are getting the correct enumeration of the various train-lengths, then (for each train length) compute how many trains can fit on the track; that gives the number of people on the track simultaneously, check if this beats the max-so-far, if so, replace max. For each train length choice, you need to compute the ratio of people to cumulative car length, and (it is a good idea to) store this in a one-dimensional array that can store decimal values. Finally, compute the average of the ratios, and print that out. Input Specification 1. The total length of the track will be a positive integer (in feet) less than 10000. 2. The maximum length of a train will be a positive integer in between 10 and 100, inclusive Output Specification The output should consist of three lines. The first line outputs the maximum number of passengers on the roller coaster at any one time with a single statement of the following format Your ride can have at most X people on it at one time. with a single statement of the following format: This can be achieved with trains of Y cars. Note: If there are multiple ways in which the maximum number of people can be supported, output the smallest number of cars that achieves this maximum. (Thus, if both 2 cars and 4 cars lead to 100 people on the ride and this is the maximum, then your program should output 2 cars.) The third line should simply output the average value of people to length, as: AVG Ratio: XxXX. XXX Output Samples Two sample outputs of running the program are included below. Note that these samples are NOT a comprehensive test. You should test your program with different data than is shown here based on the specifications given above. Sample Run #1 What is the total length of the track, in feet? 1000 What is the maximum length of a train, in feet? 42 Your ride can have at most 112 people on it at one time. This can be achieved with trains of 4 cars AVG Ratio: 0.451 (Note: The maximum is achieved when each train has 4 cars on it, and each car has 4 people, at most. Thus, 16 people can sit in one train. This train has a length of 34 feet, and since 34 feet x 7-238 feet, which is less than 25% of the total track length, this means that exactly 7 trains can be placed on the track at the same time. Thus, 16 people/train x 7 trains-112 people total.) Sample Run #2 What is the total length of the track, in feet? 4025 What is the maximum length of a train, in feet? 89 Your ride can have at most 480 people on it at one time This can be achieved with trains of 6 cars AVG Ratio: 0.467

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data 29th British National Conference On Databases Bncod 2013 Oxford Uk July 2013 Proceedings Lncs 7968

Authors: Dan Olteanu ,Georg Gottlob ,Christian Schallhart

2013th Edition

3642394663, 978-3642394669

More Books

Students also viewed these Databases questions

Question

Why does sin 2x + cos2x =1 ?

Answered: 1 week ago

Question

What are DNA and RNA and what is the difference between them?

Answered: 1 week ago

Question

Why do living creatures die? Can it be proved that they are reborn?

Answered: 1 week ago

Question

Is it clear what happens if an employee violates the policy?

Answered: 1 week ago