Difference between revisions of "CSC231 Final Exam 2017"
Line 61: | Line 61: | ||
<br /> | <br /> | ||
Take the quiz on Moodle regarding '''Fixed''' and '''Floating-Point''' numbers. | Take the quiz on Moodle regarding '''Fixed''' and '''Floating-Point''' numbers. | ||
+ | <br /> | ||
+ | =Problem 3: Assembly Programming= | ||
+ | <br /> | ||
+ | Write a program that contains a recursive function called '''binSearch''', that searches a sorted array of integers (4 bytes) for an integery ''key''. | ||
+ | <br /> | ||
+ | Your program will be linked with a separate main program that will call your function and will provide it with | ||
+ | :# the address of the array, i.e. the address of the first byte of the first integer in the array, | ||
+ | :# an integer ''key'', which is the integer we are searching in the array, | ||
+ | :# a low index, identifying the lowest bound of the interval being searched, and | ||
+ | :# a high index, idnetifying the upper bound of the interval being searched. | ||
+ | Your function will return the index of the key, if it is found, or it will return -1 if the key is not found. | ||
+ | <br /> | ||
+ | The Python function '''search()''' given [[CSC231_binarySearch.py| on this page]] is exactly what you need to translate to assembly. | ||
+ | <br /> | ||
+ | ==Example Main Program== | ||
+ | <br /> | ||
+ | |||
<onlydft> | <onlydft> |
Revision as of 11:18, 30 April 2017
--D. Thiebaut (talk) 16:23, 29 April 2017 (EDT)
<onlydft>
This exam is due on May 12, at 4:00 p.m..
This exam is given under the rules of the honor code. You have access to all your notes, to books, and to the Web. You cannot, however, discuss the details of the exam with anybody other than your instructor. Questions regarding the exam can only be asked in class, or using Piazza. Do not post code on Piazza. Do not suggest or imply possible solutions in your posts on Piazza.
All three problems are worth the same number of points.
Contents
Problem 1: C Programming
Write a C program called 231grep.c that works similarly to the Linux grep command. Your program should get its input from the command line, just like grep, and support the "-i" switch. When the user uses this switch, the search is not case sensitive. When the user omits the switch the search is case-sensitive.
Here is an example illustrating how your program should work.
- Create a text file called quote.txt containing the following 3 lines:
Believe in yourself! Have faith in your abilities! Without a humble but reasonable confidence in your own powers you cannot be successful or happy. --Norman Vincent Peale
- Run grep and search for various words in the file:
231b@aurora ~/handout $ ./231grep in quote.txt Believe in yourself! Have faith in your abilities! Without a humble but reasonable confidence in your own powers you cannot be successful or happy. --Norman Vincent Peale 231b@aurora ~/handout $ ./231grep faith quote.txt Believe in yourself! Have faith in your abilities! 231b@aurora ~/handout $ ./231grep Faith quote.txt 231b@aurora ~/handout $ ./231grep but quote.txt Without a humble but reasonable confidence in your own powers 231b@aurora ~/handout $ ./231grep -i believe quote.txt Believe in yourself! Have faith in your abilities! 231b@aurora ~/handout $ ./231grep confidence doesnotexist.txt grep: doesnotexist.txt: No such file or directory
- Your program should behave exactly the same way.
Implementation Details
- Your program needs to support only the "-i" switch
- The order of the command-line parameters will always be
- switch (if present)
- word
- file name
Testing
- Your program will be tested by comparing its output to the output of grep, using diff.
- You know enough to be able to create your own test script that should be able to inform you of whether your program's output is correct or not.
Submission
- Submit your code on Moodle, in the grep section of the final exam.
Problem 2: Fixed and Floating Point Numbers
Take the quiz on Moodle regarding Fixed and Floating-Point numbers.
Problem 3: Assembly Programming
Write a program that contains a recursive function called binSearch, that searches a sorted array of integers (4 bytes) for an integery key.
Your program will be linked with a separate main program that will call your function and will provide it with
- the address of the array, i.e. the address of the first byte of the first integer in the array,
- an integer key, which is the integer we are searching in the array,
- a low index, identifying the lowest bound of the interval being searched, and
- a high index, idnetifying the upper bound of the interval being searched.
Your function will return the index of the key, if it is found, or it will return -1 if the key is not found.
The Python function search() given on this page is exactly what you need to translate to assembly.
Example Main Program
<onlydft>