Fake Final Due: Before Finals Week 75 Points(theoretically) **** INSTRUCTIONS **** This "fake final" will be very similar to the real final you'll soon be taking. The in-person section will be taking the final in-class on December 9 at 3PM EST. The online section will be taking the final on Blackboard. It will be made available at 12:01AM EST on December 6, and will be due at 11:59PM EST on December 10. You will have two hours to complete the exam and it must be done in one sitting. **** SECTION 1 - UNIX COMMANDS **** (12 pts) Give me a command that does the following: 1. creates a directory: 2. removes a file: 3. moves or renames a file: 4. prints how long since last system reboot: 5. changes your password: 6. clears the terminal screen Write the command that does the specified task: 1. prints the contents of /u1/h1/jcompton5: 2. makes a copy of file a1 and names it a2: 3. change to the root directory: 4. outputs the contents of README to the screen: 5. prints out information about the rmdir command: 6. renames a file b1 to b2 **** SECTION 2 - EXPRESSIONS **** (9 pts) Suppose the computer is tasked with calculating the following expressions, what would the result be? 1. 5 + 7 * 3 % 2 = 2. 9 * 8 - 8 + 2 = 3. 7 * (11 / 7) + 11 % 7 = 4. 5.0 / 10 + 2 = 5. 5 / 10 + 2 = 6. 2 + 3 - 10 * 0 = 7. 10 % 2 + 5 = 8. 2 * 2 % 2 = 9. 5 + 5 / 10 = **** SECTION 3 - C CODE **** (14 pts) Answer the following questions about C Functions 1. Give me a line of code that sets up "temp" as a floating point variable with the initial value of 98.6. 2. Given the two lines of code below, write the next line of code that gets the user's age and stores it in the variable "age" int age; printf("Please enter the user's age"); 3. Give me a line of code that opens a file in your current directory named stuff.txt for reading and stores it in a file pointer named f 4. What function will output the length of a string? 5. Consider the following while loop: int i = 0; while(i < 10){ printf("%d\n", i); i++; } Rewrite this while loop as a for loop that does the same thing. 6. Give me a printf statement that does the same thing as the following C statement putchar(c); Fill in the missing C Code that accomplishes the specified task: (10 pts) 1. Consider the following code #include int main(int argc, char *argv[]){ int c; FILE *f = fopen(argv[1], "r"); int count = 0; //need a while loop here printf("number of characters: %d\n", count); return 0; } We want this program to count the number of period ('.') characters in the file. Write the while loop that will count the number of period characters. 2. Consider the following code #include int main(int argc, char *argv[]){ int num; int sum = 0; int countEven = 0; FILE *f = fopen(argv[1], "r"); //need a while loop here printf("sum = %d, number of even numbers = %d\n", sum, countEven); return 0; } We want this program to calculate the sum of all of the numbers, and additionally keep a count of the number of even numbers read. Write the while loop that accomplishes this task. **** SECTION 4 - WRITING A PROGRAM **** (15 pts) Write a complete C Program that opens a file in your current directory named "shortStory" for reading. uses fgetc to read all the characters in the file, counts how many times either 'E' or 'e' appear in the file and prints the total number of times the letter e, regardless of case appears. **** SECTION 5 - PLAY COMPUTER **** (15 pts) Consider the program below. Below the program, you can see the program's variables. Each variable has a box next to it. Values for a variable are to be written in the box for the variable. Work from left to right: When the program stores a value in a variable, write the value in the box for the variable to the right of the old values. When the computer prints a value, write it in the screen (in the next problem) in the appropriate place. --PROGRAM-- #include int main(){ int sum = 0; for(int i = 0; i < 3; i++){ int k = 2 * i + 2; sum = sum + k; printf("%d %d\n", k, sum); } printf("Done\n"); return 0; } --VARIABLES-- sum: i: k: --SCREEN--