2671 Shares

Tough C programming problem. Can anyone help or give advice?

Tough C programming problem. Can anyone help or give advice? Topic: Example of writing a process description
July 19, 2019 / By Kerenza
Question: There is one program I'm having a lot of trouble figuring out. We just started going over using input files in my c programming class.. This is the description for the program: Problem C: American Idol (idol.c) American Idol is a hit and theme park visitors love interactive shows and exhibits. Your boss has taken this into account and has come up with a brilliant idea for the park,... Idol. The idea is a simple one: at the beginning of the show, several volunteers sign up to sing well-known songs for the audience. For each volunteer, the audience will score their performance on a scale from 1 to 100. A score will be assigned to each volunteer in one of two ways: 1) Averaging all scores the volunteer receives. 2) Averaging all BUT the lowest and highest scores the volunteer receives. The volunteer with the highest score (according to these criteria) will be the winner for the show. Your boss has hired you to write the software to automate the scoring process. In order to speed up the process, since there are so many audience members, your program will read in input from a file, idol.txt. The input file will contain the following information: 1) The number of volunteers (contestants singing) 2) The number of audience members judging 3) The method of scoring (keep all scores, or drop the lowest and highest) 4) The scores for each volunteer Input File Format(idol.txt) The first line of the file will contain three integers separated by spaces: C (1 < C < 10), representing the number of contestants, A (2 < A < 101), representing the number of audience members judging the contestants, and J (J = 0 or J = 1), representing whether or not to include all scores (J = 0), or drop the minimum and maximum scores (J = 1). The next C lines will contain A positive integers separated by spaces in between 1 and 100, inclusive, representing all of the scores of that particular contestant. (The first line has the scores for contestant number 1, the second line for contestant number 2, etc.) Note: PLEASE DO NOT CALL YOUR VARIABLE NAMES C, A AND J. I HAVE USED THESE VARIABLE DESIGNATIONS TO MAKE THE DESCRIPTION ABOVE CLEAR AND SUCCINCT. Output Specification (to the screen) Output the winning contestant number as well as their average score using the following format: Contestant #k, you win with an average score of X. Note: k will be a positive integer in between 1 and the number of volunteers. X will be a real number in between 1 and 100 printed to 2 decimal places. Note: You are guaranteed that only one contestant will have the highest average under the given judging rules. I just really don't know where to start on this one, if anyone could show me how to solve it or at the least give me some great pointers I'd be SO appreciative! Thanks!!
Best Answer

Best Answers: Tough C programming problem. Can anyone help or give advice?

Jaclyn Jaclyn | 6 days ago
First, a simple file example. This is your idol.txt file. Use notepad or similar to create it: As it is a simple test, only 2 contestants, and 11 judges with a score method flag. 2 11 0 95 80 54 76 23 97 67 88 62 49 83 54 67 22 87 35 47 15 61 49 71 33 Now then, the problem gives you some specific limits. You can safely limit your arrays to the specified sizes but error check and terminate the program if any limits are exceeded. So, write a program to read the file and load it into the arrays. You'll need to write a line parser that understands what are numbers spaces and line terminators. Make sure than none of the internal program limits are exceeded. Do not depend on the file to properly limit things. Do the math to decide the winner. Display the answer. Now, if you think you are good, you only need 1 array to read in the scores and a few variables to keep track of who the winner might be. You can do everything while you read the file in real time. Shadow Wolf
👍 240 | 👎 6
Did you like the answer? Tough C programming problem. Can anyone help or give advice? Share with your friends

We found more questions related to the topic: Example of writing a process description


Jaclyn Originally Answered: Tough problem. Help me out?
You're missing an important piece of information here. We know the can was either 4 inches high with a circumference of 6 inches, or it was 6 inches high with a 4 inch circumference. I'll show you how to solve it assuming the first case: If the can was 4 inches high with a 6 inch circumference, use those numbers to find the volume. The volume of a cylinder is the area of one end times the height of the cylinder. In this case, the area of the base is: ((6/π)/2)^2*π = 2.86 in^2 Multiply by the height of 4" and you get: 11.44 in^2. The answer will be different if the can was actually 6 inches high with a 4 inch circumference, but there is the process so you can figure it out if that's the case.
Jaclyn Originally Answered: Tough problem. Help me out?
First, picture what happened so you understand what you're after. If you take off the ends of the can and squash if flat, it has two sides. The top is half the surface area of the round part, the bottom is the other half. Since the squashed can is 4 x 6, it's area A = l x w = 4 x 6, so the surface area of the roundy part must be twice that, or 48 square inches. Now what's the volume of a cylinder? It's the area of the circle at the bottom (or top) times the height of the can, or V = (pi)r^2h Can you finish from here? (Don't assume anything about height; the can might be short and fat like a can of tuna, or it might be tall and skinny like a can of tomato paste, so you can't necessarily say whether the height ends up being the width or the length!).

Emelia Emelia
Good it seems foolish that your sister and her husband would choose to decide upon a fight about some thing as ridiculous as a workforce dropping a game. That's existence. A person wins and somebody loses. We can not all be winners. Did they ever stop to feel that it might have been their workforce that misplaced? On the flip aspect, if he did not wish to stay and listen to all of the flack, and i can't say I blame him, then he might have stated to them, "I've had ample. I go house." as a minimum that way they might have identified the place he was once going. So there used to be wrong on either side. If you happen to say something in any respect you might factor that out to each your sister and your dad
👍 100 | 👎 5

Christin Christin
Start with either a flowchart or pseudo-code. Then work out what data structures you're going to use. Then plan out your functions. Then code them.
👍 95 | 👎 4

Christin Originally Answered: Probability: Can you answer this tough three dice problem?
Whew! Okay -- first of all . . . I'm assuming that you mean that you throw a switch whenever your first roll a sum of 3, of 5, of 8, _OR_ of 11. (When you wrote, "When the dice sum to 3, 5, 8 & 11 you throw one of the switches," I first thought that you meant that the first switch didn't get thrown until _all four_ sums had appeared. But the rest of your initial calculations didn't seem to support that interpretation...) Okay -- talking about expected value. On average, it should take . . . 216 rolls before you get a sum of 3 36 rolls before you get a sum of 5 10 2/7 rolls before you get a sum of 8 8 rolls before you get a sum of 11 (If you don't understand why, at first, try thinking of a simpler case: On average, how many times do you have to roll a die before you get a "4"?) You have a (1/6) chance of getting it on the first roll. You have a (5/6) * (1/6) chance of getting it on two rolls. You have a (5/6)^2 * (1/6) chance of getting it on three rolls. You have a (5/6)^3 * (1/6) chance of getting it on four rolls. (et cetera) Calculating the expected value . . . [(1/6) * 1] + [(5/6) * (1/6) * 2] + [(5/6)^2 * (1/6) * 3] + . . . = 6 (Doing this same type of calculation using the probabilities of getting a sum of 3, 5, 8, or 11, you can find the results I gave above.) Now -- most of the time, by the time you've rolled a sum of 3, you already "knocked off" the other three sums. But what if you haven't? There's a (210/216)^216 chance that you're still missing a sum of 5. There's a (195/216)^216 chance that you're still missing a sum of 8. There's a (189/216)^216 chance that you're still missing a sum of 11. Included within those three probabilities, there's also . . . ...a (189/216)^216 chance that you're still missing a 5 _and_ an 8. ...a (183/216)^216 chance that you're still missing a 5 and an 11. ...a (168/216)^216 chance that you're still missing an 8 and an 11. AND -- within all _six_ of those probabilities, there's also . . . ... a (162/216)^216 chance that you're still missing everything but a 3! So -- to get the expected value, you'd sum the following calculations... (Prob. of "3" being last) * (216 rolls) (Prob. of needing just a "5" after the 3) * (252 rolls) (Prob. of needing just an "8" after the 3) * (226 2/7 rolls) (Prob. of needing just an "11" after the 3) * (224 rolls) (Prob. of needing a 3, then a 5, then an 8) * (262 2/7 rolls) (Prob. of needing a 3, then a 5, then an 11) * (260 rolls) (Prob. of needing a 3, then an 8, then an 11) * (234 2/7 rolls) (Prob. of needing a 3, a 5, an 8, then an 11) * (270 2/7 rolls) NOTE!!! Some of these probabilities in the early going need to be "doubled" or "tripled" up. For example -- when I say, "Prob. of needing just a '5' after the 3," that probability has to include a case where (after the 3) you needed a 5 _and and 8 and/or 11_, but where you got the "8 and/or 11" before that 5 came up! Similarly, when I say, "(Prob. of needing a 3, then an 8, then an 11)," that has to include the case where you _also_ needed a 5, but it came up before the 11 did. (Like I said. Whew!) I'm going to post this now. If you give me a little time, I'll do the calculations and edit them in . . . :-) Edited to add: Yeah -- I'm getting lost in the math. I'm only getting an expected value of 216.08197094 -- so I know I'm missing something, or have an error floating around in my work. For those of you who care, though -- here's a Basic program that will run a simulation . . . 1 home 2 let f = 0 3 let mx = 220 4 let mn = 220 5 for j = 1 to 25000 6 let w = 0 7 let x = 0 8 let y = 0 9 let z = 0 10 for n = 1 to 5000 20 let a = int(6*rnd 1)+1 30 let b = int(6*rnd 1)+1 40 let c = int(6*rnd 1)+1 50 let d = a+b+c 60 if d = 3 then let w = 1 70 if d = 5 then let x = 1 80 if d = 8 then let y = 1 90 if d = 11 then let z = 1 100 goto 200 110 next n 200 if w = 0 then goto 110 210 if x = 0 then goto 110 220 if y = 0 then goto 110 230 if z = 0 then goto 110 300 if n > mx then let mx = n 310 if n < mn then let mn = n 500 let f = f+n 510 let q = f/j 520 print n,q 530 next j 534 print 535 print mn 536 print mx 540 end Changing the value of "j" in line 5 will let you run more trials or fewer trials. "n" is the number of rolls before you trip all the switches; "q" is the running average number of rolls over many trials. (In line 10, if you set the value too small, you'll get a "next without for" error -- as you've exhausted all your rolls and you still haven't tripped all the switches...) At the end, it will print the minimum number of rolls it took and the maximum number of rolls it took to trip all the switches. :-)

If you have your own answer to the question example of writing a process description, then you can write your own version, using the form below for an extended answer.