Difference between revisions of "CSC111 Final Exam 2018"
(→Information Released After the Deadline) |
(→Information Released After the Deadline) |
||
Line 385: | Line 385: | ||
<br /> | <br /> | ||
* The grade was automatically set to 65/100 if the program crashed on any of the input files. | * The grade was automatically set to 65/100 if the program crashed on any of the input files. | ||
− | * Points were removed for lack of documentation, or for | + | * Points were removed for lack of documentation, or for solutions that used iteration (for-loop) in the function. |
<br /> | <br /> |
Revision as of 10:40, 14 May 2018
D. Thiebaut (talk) 11:39, 26 April 2018 (EDT)
- This is the final exam for CSC111, Spring 2018.
- The deadline to submit your programs is May 11, 4 p.m. Please make note of the different submission time of day.
- This exam has to be done individually, and is given under the rules of the Smith Honor Code. You are not allowed to work in pairs on any part of this exam.
- You are not allowed to discuss any of the details of this exam, except with your instructor, D. Thiebaut
- You can ask questions on Piazza only. Do not post code on Piazza. If you think you may be giving away part of the solution when expressing your question on Piazza, make it private.
- Do not answer questions posted by others on Piazza; only your instructor is allowed to answer questions.
- The TAs and lab instructor will not be available to help out on this exam.
- You have to do the debugging of your code on your own.
- Two problems will be auto-graded on Moodle. The autograder is setup to only run your program on a small subset of cases, without generating a grade. You must test your program thoroughly to make sure it will pass all the tests that will be used to fully evaluate your program.
- A whole letter-grade will be removed for poorly documented code.
- Make sure you list the resources you used to generate your code in your program header, if these resources are other than our textbook, or the notes and/or programs generated in class.
- Submit your code as soon as you have something running, in case you run into problems with your laptop, with the network, or with other unforeseen technical failures.
- All four problems are worth the same weight: 25% of the final grade.
Contents
Problem 1
- Write a program that prompts the user for the name of a CSV file that contains the email addresses of 5-college students along with their major or double-major, and, possibly, their minor.
- Below is a typical file. Note that the first line will always contain the headers.
email, major1, major2, minor Florance872@hampshire.edu,RUL,, Nguyet929@umass.edu,REES,CSC,THE Sol937@hampshire.edu,CSC,, Loreen219@smith.edu,ITL,ENV, Marquerite747@amherst.edu,DAN,,BUX Alishia128@hampshire.edu,AMS,, Nolan149@smith.edu,SAX,, Xiao517@umass.edu,CSF,, Lawerence246@smith.edu,JUD,, Dominique1@smith.edu,ESS,,LALS
- Write a python program called final1.py (final-one dot py) that reads this type of CSV file, and outputs this information:
- The most popular major. In this case both the first major and second major count. For example, in the 3 lines shown below, CSC is the most frequent major.
Flo72@hampshire.edu,RUL,CSC, Anna10@hampshire.edu,CSC,ECO, Monty77@smith.edu,CSC,RUL,
- The most popular minor
- The most popular double major or double majors. In the 3 lines above, CSC-RUL is the most common double-major, and should be listed as CSC-RUL, and not RUL-CSC, since CSC is before RUL, alphabetically.
- Which email domain is most frequent in the file.
- Example of output:
GEO ITL CSC-ECO smith.edu
- Your program should be able to handle a file where nobody has a second major or minor. In this case the output for the double-major and minor should be "---".
- Example:
GEO --- --- smith.edu
- In case two or more majors (or minors, or double-majors, or emails) have the same largest count, then your program should output all of them on the same line, separated by spaces, and listed alphabetically:
- Example
GEO ITL CSC EAL PHY CSC-ECO ECO-MTH hampshire.edu smith.edu umass.edu
- Here is an example of the interaction with a user who mistypes the name of the file:
> hello > blabla.txt > test2.csv RUL --- CSC-RUL ECO-RUL amherst.edu hampshire.edu mtholyoke.edu smith.edu umass.edu
- Note that the program prints a blank line after getting a valid file name and before outputting the result.
- Submit your program in the Final Exam PB 1 section on Moodle.
Additional Information
- Lines that do not contain a '@' character should be considered invalid.
Problem 2: An Orange Tree
- Modify the fractal tree program shown below so that it will generate an exact replica of the tree shown above. You should not reproduce the large grey text in the image; just the tree, its colors, its fruit, and the yellow box with your name in it.
- Call your program final2.py and the image final2.jpg or final2.png. Submit both to the Final Examp PB 2 section on Moodle.
- Note: To change the color of a line with the graphics library, you should use the setOutline() method rather than the setFill() method. To change the width of a line, you can use the setWidth() method.
- I used only 3 colors to generate the tree above: "green", "blue", and "brown".
- The oranges have radius 10.
# fractalTree.py # D. Thiebaut # # Draws a fractal tree on the graphic window. # from graphics import * import math import time import random # dimensions of the window MAXWIDTH = 800 MAXHEIGHT = 700 # recursive tree-drawing function # def draw_tree(win , # the canvas order, # the level of recursion. Starts positive. theta, # angle of new branch leaving this trunk sz, # size of this branch x, y, # coordinates of base of this branch heading, # angle of direction of this branch color # color ): trunk_ratio = 0.29 # How big is the trunk relative to whole tree? trunk = sz * trunk_ratio # length of trunk # compute x, y of end of the current branch delta_x = trunk * math.cos(heading) delta_y = trunk * math.sin(heading) x2, y2 = x + delta_x, y + delta_y # draw current branch branch = Line( Point( x, y), Point( x2, y2 ) ) branch.setWidth( 2 ) branch.setOutline( color ) branch.draw( win ) # if this branch has sub-branches, then recurse if order > 0: # make the recursive calls to draw the two subtrees newsz = sz*(1 - trunk_ratio) draw_tree(win, order-1, theta, newsz, x2, y2, heading-theta, color ) draw_tree(win, order-1, theta, newsz, x2, y2, heading+theta, color ) def drawName( win, name ): ''' draws the programmer's name in a box, at the bottom of the window''' r = Rectangle( Point( 300, win.getHeight()-35 ), Point( win.getWidth()-300, win.getHeight()-5 ) ) r.setFill( "yellow" ) r.setOutline( "black" ) r.draw( win ) l = Text( Point( win.getWidth()//2, win.getHeight()-20 ), name ) l.setFill( "black" ) l.draw( win ) # draw 1 tree in the middle of the screen, shooting straight up. def main(): win = GraphWin("CSC111 Final Exam", MAXWIDTH, MAXHEIGHT ) # draw the fractal tree theta = 0.55 # use 0.02 for tall skinny trees, 0.7 for fat trees order = 9 draw_tree(win, order, theta, MAXWIDTH*0.9, MAXWIDTH//2, MAXHEIGHT-50, -math.pi/2, "magenta" ) # draw programmer's name in a box drawName( win, "Mickey Mouse" ) # wait for user to click window win.getMouse() win.close() main()
Problem 3
Write a graphic program that takes an image and generates a circular soft mask around the center of the image, as illustrated below. On the left is the original image, and on the right the image generated by the program you have to write.
Testing
Run your program on the following image, and submit a copy of the processed image under the name finalb.jpg or finalb.png. Add a rectangle with your name inside it, so that the image can be easily identified. Failure to add the name will result in losing some valuable points.
(click on the image twice to get to the real full size image)
Implementation Details
- The circular part of the mask should be as large as the width or the height of the image, whichever is smaller
- The mask color must be white.
- The resulting image should be fully white outside the circular mask.
- The amount of softness inside the circle is up to you. But there should be some softening of the colors! The pixel at the very center of the foggy image should retain its original color.
- Your graphic program should only ask the user for a file name, nothing else.
- If you need help capturing the final image, please visit this page.
- You may find these functions useful...
# distanceDemo.py # D. Thiebaut from math import * from graphics import * def distance( x1, y1, x2, y2 ): return sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) def distanceP( p1, p2 ): x1, y1 = p1.getX(), p1.getY() x2, y2 = p2.getX(), p2.getY() return distance( x1, y1, x2, y2 ) def main(): point1 = Point( 3, 5 ) point2 = Point( 7, 8 ) d = distanceP( point1, point2 ) print( "distance =", d ) main()
Submission
- Your program should be called final3.py and the image final3.png or final3.jpg, and both should be submitted in the Final Exam, PB3 section on Moodle.
Problem 4
Dave, here's a bunch of banana. Can you tell me if there are two bananas next to each other that have the same weight?
Write a program called final4.py containing a recursive function similar to the functions we created in class, using Dave and Gru as example. Your program will prompt the user for a list of integers, and will print "True" if there are two numbers in the list that are consecutive and have the same value, and it prints "False" otherwise.
Your program must use a recursive function to determine if the there exist two consecutive numbers that have the same value. Programs that solve the problem using an iterative loop, and not using recursion will automatically get 0/100.
Examples of interactions with the program:
==== RESTART: final4.py ==== > [ ] False >>>
==== RESTART: final4.py ==== > [ 100 ] False >>>
==== RESTART: final4.py ==== > [ 100, 2 ] False >>>
==== RESTART: final4.py ==== > [ 34, 34 ] True >>>
==== RESTART: final4.py ==== > [ 1, 2, 3, 4, 1, 2, 3, 4 ] False >>>
==== RESTART: final4.py ==== > [ 1, 2, 3, 4, 5, 5 ] True >>>
==== RESTART: final4.py ==== > [ 1, 2, 3, 4, 4, 5, 6, 7 ] True >>>
Main program
Below is what your main program should look like. You simply need to add a recursive lookFor2() function and document the code. The lookFor2() function must be recursive.
def main(): bananas = eval( input( "> " ) ) print() success = lookFor2( bananas ) print( success )
Additional Information
- You cannot use the "in" operator in your recursive function to test if an item is inside the list.
Submission
- Submit your program to the Final PB 4 section on Moodle.
Information Released After the Deadline
Problem 1
The first program was tested with several files:
- test0.csv
email, major1, major2, minor
- test1.csv
email, major1, major2, minor Flo872@hampshire.edu,RUL,, Joe999@smith.edu,ECO,, Anna33@amherst.edu,CSC,, Mana00@mtholyoke,EAS,,
- test2.csv
email, major1, major2, minor Flo872@hampshire.edu,RUL,ECO, Joe999@smith.edu,ECO,RUL, Anna33@amherst.edu,CSC,RUL, Mana00@mtholyoke.edu,EAS,, Annya@umass.edu,RUL,CSC,
- test3.csv
email, major1, major2, minor Flo872@smith.edu,RUL,, Joe999@smith.edu,RUL,, Anna33@smith,RUL,, Mana00@smith.edu,RUL,, Annya@smith.edu,RUL,,
- There was also a test where an invalid file name was provided to the program.
- The grade was automatically set to 65/100 if the program crashed on any of the input files.
- Points were removed for lack of documentation, or for not using several functions.
Problem 4
Problem 4 was tested with several lists:
[ ] [ 1 ] [ 1, 2 ] [ 3, 3 ] [ 2, 3, 4, 5, 6, 7, 8, 9 ] [ 2, 3, 2, 3, 2, 3, 2, 3 ] [ 2, 3, 4, 5, 6, 7, 8, 8 ] [ 2, 3, 4, 5, 2, 3, 4, 5 ]
- The grade was automatically set to 65/100 if the program crashed on any of the input files.
- Points were removed for lack of documentation, or for solutions that used iteration (for-loop) in the function.