Final Exam - Computer assigment Instructions: Make a directory for your Final exam called final. Use the names listed below for each program. If you used multiple files for an problem, these should be combined into one file. There should be exactly one file for each problem. To submit your Final, type 211submit-final in the correct directory. The command for submitting final is different!!! You may resubmit your final at anytime before the deadline. The old one will be erased. The Computer part of the final is due on 23:59 Wednesday, May 7. the final folder will be locked after the deadline and you will not be able to submit your final after the deadline. DUE: Wednesday, May 7, 1997 The Computer part of the final exam is different from your homeworks. You should not discuss any problem with anyone other than your instructor. You may, however, use text books, or any reference books if you wish. It is a violation of the honor code to copy, discuss, or seek help from anyone other than your instructor. Your instructor will answer your question if you are not clear about the problem, however, no help will be given from the instructor. There is a total of 5 problems. Each worth 10 points. 2 points will be given if you tried hard enough (if your program includes some expected calls). You will not get more than 2 points if your program does not compile. If your program is basically right in structure, and gives partially correct answers, you get 6 points. Of course, you get 10 points if everything is correct. A problem submitted will receive the scores of 0, 2, 6, or 10. These problems should be named in the following way before submission: FILES: ex1.c ex2.c ex3.c ex4.c ex5.c ********************************************************************* The key for Problems 1 to 4 have less than 25 lines. The key for Problem 5 have 52 lines, but 22 of them are just the country_codes. ********************************************************************* Problem 1. Write a program computing the SUM of the following series a[0] = 3.5, a[k] = 1.5*a[k-1] - 1.5, k = 1, 2, ... , 29. The summation goes from a[0] through a[29], with both a[0] and a[29] included. For your output. You should display (1) the sum with format 1 digit after dicimal point; (2) If the sum is over 100000, display a message "too big". ********************************************************************* Problem 2. Write a program asking user to enter an integer numberical score, then print a Letter grade according the following scale: Between 0 and 280: F Between 281 and 320: D Between 321 and 370: C Between 371 and 410: B Between 411 and 450: A If a negative number or a number bigger than 450 is entered, display a message: "Ridiculous score". ********************************************************************* Problem 3. Write a program solving the equation sin(x) + x = 1 for an solution x between 0 and 2. The error should be within 0.0001. Display your answer with 4 digits after dicimal point. Hint: #define f(x) (sin(x)+(x)) More hint: It is clear that f(0.0)<1 and f(2.0)>1. (1) Start with left=0.0, right=2.0, and start a loop. (2) In next step, middle=(left+right)/2. Assign right to be middle if f(middle)>1, assign left to be middle if f(middle)<=1. (3) In each step, you should have f(left)<=1 and f(right)>1 after assignment. (4) Stop the loop when (right-left) is within the error. Compile header with cc file.c -lm ********************************************************************* Problem 4. Suppose we declare char *color[9] = {"Red", "Blue", "Black", "White", "Yellow", "Pink", "Green", "Grey", "Mixed"}; Write a program randomly display 10 times these 9 words in one line, seperating the words with a space. Hint: (1) still remember time() in time.h ? (2) remember how to initialize a random generator ? ********************************************************************* Problem 5. Using the table on page 339 for country_codes, write a program asking user to enter an integer dialing code, then compare with the table and prints the name of the country in CAPITAL letters. If the country is not found, prints an error message: "Error, the country is not found" You should not change the table to capital letters. You may paste the following into your program. (22 lines) struct dialing_code{ char *country; int code; }; const struct dialing_code country_codes[] = { {"Argentina", 54}, {"Bangladesh", 880}, {"Brazil", 55}, {"China", 86}, {"Colombia", 57}, {"Egypt", 20}, {"Ethiopia", 251}, {"France", 33}, {"Germany", 49}, {"India", 91}, {"Indonesia", 62}, {"Iran", 98}, {"Italy", 39}, {"Japan", 81}, {"Korea, Republic of", 82}, {"Mexico", 52}, {"Nigeria", 234}, {"Pakistan", 92}, {"Philippines", 63}, {"Poland", 48}, {"Russia", 7}, {"South Africa", 27}, {"Spain", 34}, {"Thailand", 66}, {"Turkey", 90}, {"Ukraine", 7}, {"United Kingdom", 44}, {"Vietnam", 84}, {"Zaire", 243}};