Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CMPE 150 – Spring 2007 – Midterm2 - Group B 08/05/2007 Name : ………………………………… Lab No : ………………………… Student No : …………………………... Computer No : …………………. IMPORTANT: This is a lab exam. You will use the online C compiler to write and compile your C programs. To enter the system; open the web page in the Internet Explorer which will be announced by your exam supervisor. For login into the system: Student no : your student no Password : the password that you use for login the system for regular working or during labs. If it is not working, try deneme. If still not working, tell this to your exam supervisor. Exam Password : will be given to you by your exam supervisor Example: Student no: 2005111111 Password : ilovecoding Exam password : f78erw6i Click 'login' You will see 4 files, one file for each question. Open the corresponding file for the question and start working. You must write your answers in these C files. Save your code in intermediate steps, in case your computer or compiler fails. We may test your answers with different input or may change the code segments above and below your functions. You cannot use extra paper for your calculations. You can use this sheet if required. You will return this sheet at the end of the exam. If your submitted code can not be compiled, you will get 0 points from that question. No partial credit will be given to non-working programs. A program that just compiles need not get more than 0 points. Be careful that you must take the input in the order as indicated in the question and examples, and you must give the output as shown in the examples (DO NOT write anything on the screen other than the output. DO NOT write any string like “The output is…”. Also DO NOT take any extra input (e.g. DO NOT put a scanf function at the end of your program). For input and output, always use scanf and printf functions, DO NOT use getchar and putchar or getch, putch. Also DO NOT use fflush() function. By signing below, I admit that I have read and understood the explanations above. Signature : ……………………. Question 1 (25 points): A program is given that gets a number of temperature values and outputs the total of these temperatures. Some of the functions are omitted, complete these functions so that the program works as it should be. There are several rules in the system; 1) Each temperature input is given with a number code, the codes have different meanings: Code 1 : Use the temperature as it is Code 2 : The temperature is given in Celcius, so convert it to Fahrenheit before calculation Code 3 : Use the temperature as it is, but do not read any more values from the user 2) Only accept the temperature value if it is between (and including) -10 and 50 degrees (after conversion to Celcius if the code is 2). HINT: Relation between Fahrenheit to Celcius degree values is as follows F 32 C 180 100 Input: 1-10 2-20 3-5 Input: 2-90 1-40 1-55 1-0 3-13 Input: 1-43 2-0 2—5 1-30 3-5 Output: 15 Output: 53 Output: 133 Question 2 (25 pts.) Write a function that finds the average, minimum and maximum values; and the integer which has the farthest value to the midrange, given a sequence of positive integers as input. Notes: Midrange is the average of the minimum and maximum values in the input sequence. For instance, for the sequence “8 5 6 2 8 5 2 2 7 2 9”, midrange is (2 + 9) / 2 = 5.5 (where 2 and 9 are the minimum and maximum integers in the sequence respectively). In this case, the integer which has the farthest value to the midrange is 5. If there is more than one integer with the farthest value to the midrange, the output will contain only the integer appearing in the sequence before all the other integers which also have the farthest value to the midrange. As input to the program, total number of integers in the sequence and the sequence itself are entered respectively obeying the format for input as shown below. input 3: 18 25 1 6: 1 5 2 1 7 3 8: 32 64 4 13 5 2 4 8 output 14.7:1:25:25 3.2:1:7:1 16.5:2:64:64 Question 3 (25 Points) Write a program which calculates the average points per match for teams given below. Program gets 2 weeks number and does the calculations for matches between these weeks and the result with three digit precision. For example if the user enters 3 and 7 then program will calculate the matches of the weeks 3,4,5,6,7. Week numbers will be different from each other and between 1 and 10 no more control is necessary. The following table shows the match results. 1 means win, 0 means draw and -1 means beating. In the Turkish Super League every win is 3, every draw is 1 and lastly every beating is 0 pts. Average points = Total Points / weeks Week GS BJK FB Number 1 0 -1 1 2 1 1 1 3 0 1 1 4 0 1 -1 5 0 -1 1 6 1 -1 0 7 -1 1 1 8 0 0 -1 9 0 1 0 10 1 1 1 (The match statistics are the values of the first 10 weeks of Turkish Super League 2006-2007) Be very careful about the input and output format. Input and outputs must be in the given format. First enterance will be initial and second enterance will be last week number. ( Teams are alphabetically sorted in the output. ) HINT: For printing a float value with four digits of precision, you have to use %.3f . Ex: float a=3.12345; printf(“%.3f”,a); output is: 3.123 Input: 1:5 Output: BJK:1.80 FB:2.40 GS:1.40 Input: 3:7 Output: BJK:1.80 FB:2.00 GS:1.20 Question 4 (25 points): Write a program that gets several characters that are composed of numbers and letters, then writes down the sum of the numbers and the letters in the array. The number of the characters are given prior to the array. If there are n consecutive numbers between two letters then the number is assumed to be a n-digit number (ex: T800A, number is 800). Also, the letters will be written down in the order as they appear in the input array. Lastly, any non-capital letters will be converted into capital letters. (NOTE: The numbers will ALWAYS be given as either positive integer values or zero. Use dynamic allocation for the input array) Input: 6 T011Lo Input: 20 S40pA12R48t80A120aAa Input: 16 4D8h15ar16m23a42 Output: 11 TLO Output: 300 SPARTAAAA Output: 108 DHARMA