Popular in Intro To Computer Science 1
verified elite notetaker
verified elite notetaker
verified elite notetaker
verified elite notetaker
verified elite notetaker
verified elite notetaker
Popular in ComputerScienence
This 46 page Class Notes was uploaded by Maya Notetaker on Monday November 23, 2015. The Class Notes belongs to 1500-03 at Tulane University taught by Kurdia, Anastasia in Summer 2015. Since its upload, it has received 45 views. For similar materials see Intro To Computer Science 1 in ComputerScienence at Tulane University.
Reviews for Lab
If you want to pass this class, use these notes. Period. I for sure will!
-Miss Perry Bartoletti
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 11/23/15
CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 0 Due Monday 83115 at 1159 pm on Blackboard Homework guidelines Complete the programs below and submit them on Blackboard before due date Each program should be placed in its own le named exactly as speci ed Your submission must be your work and only your work You are encouraged to work on all problems with a partner according to pair programming rules outlined in the syllabus both of you will submit the same program in the header docstring you should list your partner s name and both of you will receive the same grade You should work on one computer in the same physical location and collaborate on all problems in the homework splitting up work is not permitted All program les should contain header docstrings with name of program authors creation date and brief explanation of the program and in line comments explaining what your code does see Python code style requirements document on the course webpage for more info 0 Exam average lab0pr0py Write a program that asks the user for three exam scores and outputs their average You can assume that user provides valid input all numbers will be positive integers Here s how the output of a sample run of your program would look like Please enter the first exam score 90 Please enter the second exam score 97 Please enter the third exam score 92 Exam average is 930 1 Coffee cost lab0pr1py The CoffeToTheorems coffee shop sells coffee at 1150 a pound plus the cost of shipping Each order ships for 096 per pound plus 250 xed cost for handling overhead Write a program that given the weight of the order in pounds calculates and displays its total cost You can assume that user provides valid input a non negative number which can be a fraction and can also be 0 in the latter case the total cost is 0 Please enter the weight of your order 1 Your order costs 1496 dollars gtgtgt Please enter the weight of your order 15 Your order costs 2119 dollars 2 Seconds converter lab0pr2py Write a program that asks the user for a number of seconds and tells them how many hours minutes and seconds it is Make sure your program works correctly for values smaller than the whole hour or whole minute Here s what the sample output from several runs of your program would look like Please enter the number of seconds 2 2 seconds gtgtgt Please enter the number of seconds 8 minutes 20 seconds gtgtgt Please enter the number of seconds 5 hours 33 minutes 20 seconds 500 20000 Optional extra credit 5 pts make your program correctly process single and plural cases for words hours minutes seconds Please enter the number of seconds 75 1 minute 15 seconds Usernames lab0pr3 py You are creating a system that automatically assigns user names to students according to the following rule rst three letters of the rst name plus last three letters of the last name plus last two digits of class year If rst name last name has less than three characters then the entire rst name last name is used Write a program that asks the user for their rst name last name and class year and prints for them their username Sample output of your program Please enter your first name Darth Please enter your last name Vader Please enter your class year 2099 Your username is Darder99 gtgtgt Please enter your first name Jo Please enter your last name Manhattan Please enter your class year 2014 Your username is Jotan14 gtgtgt Please enter your first name Xe Please enter your last name Pu Please enter your class year 2017 Your username is XePu17 Last problem Algorithms around us lab0pr4txt Last problem in most labs will be a non coding assignment that will help you learn more about different branches of computer science the problems that CS solving and facing these days technol ogy of the future and so on Unlike other problems in the lab that you need to complete on your own to answer the questions of the last problem you re welcome to consult any source you nd credible including internet sites and forums family members friends outside of class your class colleagues etc of course it s optional and you may complete the answers on your own There is no one right answer to most of the questions This week we ll think about how the algorithm underlie many facets of everyday life in the US Watch TED talk by Kevin Slavin How algorithms shape our world 15 minutes httpwwwtedcomtalkskevinslavinhowalgorithmsshapeourworldlanguageen 0 Why do you think the algorithms can or cannot be viewed as part of nature as the speaker claims in his last sentence provide a 1 3 sentence response 0 We are not algorithmic stock market traders so how do algorithms shape our world in other words how is your day to day life governed or affected by the work of algorithms For example if you live in dorm your roommate was likely chosen by an matching algorithm that assigned roommates of the same sex to a room When you ride a bus or use a pedestrian crossing the traffic light schedule has a complicated algorithm behind it that aims to optimize safety minimize traffic jams in the city and so on Give at least three of your own examples more the better upper bound is 10 o For each of your examples would you know if the algorithm failed to work correctly and how would you be able to detect that For instance in room mate matching if ten people were assigned to the same 2 person room we would know there was a problem If green on the traffic light only lasted 01 seconds we d suspect a problem as well CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 1 Due Tuesday 9815 at 1159 pm on Blackboard Lab guidelines Complete the programs below and submit them on Blackboard before due date Each program should be placed in its own le named exactly as speci ed Your submission must be your work and only your work You are encouraged to work on all problems with a partner according to pair programming rules outlined in the syllabus both of you will submit the same program in the header docstring you should list your partner s name and both of you will receive the same grade You should work on one computer in the same physical location and collaborate on all problems in the homework splitting up work is not permitted All program les should contain header docstrings with name of program authors creation date and brief explanation of the program and in line comments explaining what your code does see Python code style requirements document on the course webpage for more info Note the additional requirements when working on problem 2 0 Pizza analysis lab1pr0py You noticed that the menu of your favorite pizza chain store is rather complicated They offer a range of pizza size and price op tions making it dif cult to see what option offers the most pizza for your dol lars So you decide to write program that calculates the cost per square inch of a circular pizza given its diameter and price similar to how grocery stores display cost per ounce prices The formula for area is A r2 gtllt 7r Use two func tions one called arearadius to compute the area of a pizza and one called costperinchdiameter price to compute cost per square inch Sample runs of your program should look like this Please enter the diameter of your pizza in inches 20 Please enter its cost in dollars 20 The cost is 006 dollars per square inch gtgtgtgt Please enter the diameter of your pizza in inches 85 Please enter its cost in dollars 1299 The cost is 023 dollars per square inch Use the built in Python function round value 2 to round the nal cost per inch value to two decimal points 1 Revenue lablpr1py Amount of money that a merchant receives for a credit card purchase equals the amount paid by a customer minus credit card fees and sales tax This exercise will give you an intuition why some merchants refuse to accept credit cards The credit card company charge for merchants is 3 of the transaction amount with a 250 minimum charge State sales tax rate is 4 for purchases below 20 dollars 3 for purchases between 20 and 100 dollars and 2 for purchases above 100 dollars Write a program that asks the user for the purchase price and displays actual amount received by merchant Use two auxiliary functions creditcharge value to compute the amount of credit card company charge and salestax value to compute the state sales tax Like before use the built in Python function roundvalue 2 to round the nal cost per inch value to two decimal points If necessary you can assume that the merchant refuses to accept cards for purchases less than 5 dollars Notice that the transaction fee is calculated using the original transaction amount before any taxes and fees and state sales tax is also computed using the original transaction amount before any taxes and fees in other words the amount received by a merchant is computed as transactionamount salestaxtransactionamount creditchargetransactionamount Sample runs of your program would look like this Please enter transaction amount in dollars 100 Amount received by the merchant is 940 dollars gtgtgtgt Please enter transaction amount in dollars 1999 Amount received by the merchant is 1669 dollars gtgtgtgt Please enter transaction amount in dollars 20 Amount received by the merchant is 169 dollars BMI lab1pr2py The body mass index BMI is calculated as a person s weight in pounds times 720 divided by the square of the person s height in inches A BMI in the range 19 25 inclusive is considered healthy Write a program that calculates a person s BMI and prints a message telling whether they are above within or below the healthy range You will build the program from independent functions similar to what we dis cussed in class Note that in this problem the sample input is not provided to you You should come up with your own messages for interaction with the user they should be polite and clear to let the user know exactly what they need to enter as input and what they are given as output like you did in other problems in this lab You should also come up with your own test values for all func tions at least two values of good input and corresponding return values and at least two inputs that will cause the function to fail For instance good input for computebmi would be 135 pounds and 66 inches and the expected return value is 2231 Write these test values in the docstring for each function a Start by writing a function inputimperial that will ask the user for their weight in pounds and height in inches and return a list of two numbers the rst number will be weight in pounds the second one will be height in inches b Write a function computebmi wh that takes in weight and height as input and returns a person s BMI c Write a function evaluatebmi bmi that takes in BMI value and displays to the user whether their BMI is below above or within healthy range d Independently test your functions call each function and try different inputs to ensure that the function works ne e If you did your functions right the main program for computing BMI will be lst inputimperial bmi computebmilst0 lst1 evaluatebmibmi Copy this code below your function de nitions and run it several times to make sure it works ne with your functions f Extend your program write a function inputmetric that will ask the user for their weight in kilograms and height in centimeters perform the conversion to pounds and inches and return a list of two numbers the rst number will be weight in pounds the second one will be height in inches The following program should still work correctly lst inputmetric bmi computebmilst0 lst1 evaluatebmibmi g Now extend your program even further it should handle users that are ac customed to different systems Before you do any weight height input and computation ask the user which system they prefer If they say metric use inputmetric to collect their weight and heigh information if they say imperial use inputimperial The rest of your program should stay unchanged ie you should only have one call to computebmi and evaluatebmi in the program 3 Last problem Unity in diversity labOpr3txt For your answer you re welcome to consult any source you nd credible including internet sites and forums family members friends outside of class your class colleagues etc of course it s optional and you may complete the answers on your own or with your partner There is no one right answer Watch the talk by Computerphile The Problem with Time and Timezones 10 minutes httpswwwyoutubecomwatchv5wpmgesOY As you could see in your BMI program and in the talk the diversity of users of your product will affect the way you will have to design the product Give example situations when differences in age sex gender identity disability status national origin geographical location cultural identity economic status language spoken and other differences among the users of software applications and hardware de vices affect the way we should design these software applications and hardware devices Give at least four example scenarios max is 10 and explain how the differences affect the design in 2 3 sentences for each case CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 2 Due Monday 91415 at 1159 pm on Blackboard Reminder If you do pair programming you should work with only one partner from your class pairs cannot consist of three or more people Both of you will submit the same program in the header docstring you should list your partner s name and both of you will receive the same grade You should work on one computer in the same physical location switching roles about every 20 minutes and collaborate on all problems in the homework splitting up work is not permitted Your submission must be your pair s honest work Check the syllabus for more info on pair programming rules Complete the programs below and submit them on Blackboard before due date Place each program in its own le named exactly as speci ed All program les should contain header docstrings with name of program authors creation date and brief explanation of the program The program should also contain in line comments explaining what your code does All functions should have header docstrings with description of the function function arguments and return value See Python code style requirements document on the course webpage for more info The individual problems in this homework will lead you to creation of your rst computer game in this class a guessing game 0 Integer lab2pr0 py a Write a function isnat s that determines whether a string contains a nat ural number nonnegative integer and nothing more If all characters of the string are digits the function should return True If not the function should return False Sample output of your function should look like this gtgtgt isnat 234 True gtgtgt isnat 124 False gtgtgt isnat 34s5a False Hint if you are having issues with writing your functions start with writ ing a program the one that asks the user for input and prints the output without def that would accomplish the same task and then convert it into function Another hint it won t be possible to say right away whether a string represents a nonnegative integer You will need to break this problem into pieces 0 a string represents an integer if all characters in the string are digits So you will need to look at each character individually and decide whether it is a digit 0 To decide whether an individual character is a digit you can test whether it s in the list of digits or in a string of digits suppose X holds your character if x in quot0123456789quot 0 You can count the number of digits seen so far as you move along the string After you have considered all string s characters you can compare the number of digits with total length of the string If they match this means that all characters are digits Before you start coding try to illustrate all these steps on a small example on paper You don t have to follow the hint there are several ways to solve this problem b Now write a function isints that determines whether a string contains any integer including negative numbers Sample output of your function should look like this gtgtgt isint 2843 True gtgtgt isint 348 True gtgtgt isint 453 False gtgtgt isint 345 False gtgtgt isint False In the original version of this lab here there was another task writing your own askforint function It is now a part of problem 2 to make the workflow easier If you have already completed and submitted lab2pr0 in its original form no need to resubmit it Optional extra credit 3 pts Write a function isfloat that determines whether a string contains a oating point number gtgtgt isfloat 314 True gtgtgt isfloat 3456 False In this and other problems in this homework you can test your functions by calling them from Python shell You rst hit Run for your hw2pr0py le and nothing visible happens Then you make a function call by typing function name on the keyboard and supplying the parameters manually like in the examples above Converting Strings to Integers lab2pr1py This problems involves writing your own version of the int s function that converts a string to an integer a First write a function chtoint ch that takes a single character as input and returns a corresponding integer You can assume that the input is a one character string only containing a digit Do not use the built in int function Using a bunch of ifs is perfectly ne here 1 bonus points for guring a loop based approach that does not use int or strO functions Sample output of your function would look like this gtgtgt chtoint 4 4 gtgtgt chtoint 0 0 Now use the above function to write a function stoint s that converts a string to an integer Again you can assume that the string can be converted to an integer Your function should work for positive integers negative integers and 0 You should use the above chtoint ch function Sample output of you function should look like this gtgtgt stoint 23425 23425 gtgtgt stoint 341 341 Hint use the fact that every integer can be composed from single digit inte gers multiplied by powers of 10 For example 234 2 gtllt 102 3 gtllt 101 4 gtllt 100 Use the same approach as Hints in problem0 suggest consider each digit individually at each step of computation maintain a partial result 2 Guessing Game lab2pr2py Make a new Python le called lab2pr2py and copy the code that you developed in lab2pr0py and lab2pr1py into this new le 81 Write a function askforint that asks the user to guess a number Use the isint function from above to test if the user entered an integer If so convert the string to an integer using your stoint function and return that integer If the user does not enter an integer your function should ask again and again until the user does correctly enter an integer In other words you should write an input validation loop similar to the Smiles To Mars program we discussed in class Example output is as follows gtgtgt askforint Please enter a number hello You did not enter an integer You did not enter an integer 123 Please try again two Please try again 123 Write a function guessinggame num that takes an integer and plays a guess ing game with the user Use the askforint to get the user to guess a number and your own string to integer conversion function stoint If the guess is too low or too high let the user know and ask for another guess Keep asking for guesses until the user enters a correct guess that equals num Keep track of number of guesses that the user took and output that number when the game ends Also make your guessinggame num function return that number An example run is as follows gtgtgt guessinggame13 Hello and welcome to the game You need to guess a number between 100 and 100 Please enter a number 50 Too high Please enter a number 25 Too high Please enter a number 10 Too low Please enter a number 15 Too high Please guess a number 13 Good job You took 5 guesses 5 To make your game more fun the number to guess should be different each time you run the game Put the following code at the end of your code le le import random guessinggamerandomrandint100100 Thoroughly test your program Play the game at least 5 times and keep track of the number of guesses it took you to complete the game using the smartest guessing strategy you can come up with Compute the average number of guesses with calculator or on paper you can even use the software that you have already written in this class Write that number in the docstring at the last line of your code le To make your game even more fun you will keep track of scores between different games in a text le historytxt For now we ll focus on keeping the only one score for the most recent game The le will store one number without spaces or extra symbols corresponding to the number of guesses in the previous game if there was a previous game or the le will be empty if no games have been played previously on this computer After the user has played your game your program will open the history txt le and read the number of guesses in previous game if it exists If there is no record of previous score the program will say Congratulations You are the first person to ever complete the game If previous score is higher meaning the user managed to guess the number faster this time the program will say Congratulations You did better than the previous player who took NUM guesses where NUM will be replaced by the actual number stored in the le If previous score is lower the program will say The previous player took NUM guesses Play again and improve your score Again NUM should be replaced by the actual number One possible technical problem is that when we play the game the rst time even we nnghtrnnhaye historytxt kaonthe sk Tb x n add the following code to the beginning of your program import ospath ifnot ospathisfilequothistorytxtquot fout openquothistorytxtquot quotwquot foutclose This code will check whether the le exists and if not will make a new empty kzhistorytxt Very rarely this code may not run It happens when your Python program has no permission to create or access les on your computer If you are experiencing this type of problem make sure you logged in to your computer as administrator and try running this code on your partner s computer Here s what the output might look like when you play the completed game Hello and welcome to the game You need to guess a number between 100 and 100 Please enter a number 50 Too high Please enter a number 30 Too high Please enter a number 10 Too low Please enter a number 11 Too low Please enter a number 14 Too high Please guess a number 13 Good job You took 6 guesses The previous player took 2 guesses Play again and improve your score 0139 Hello and welcome to the game You need to guess a number between 100 and 100 Please enter a number mmmmmm You did not enter an integer Please try again 2222 You did not enter an integer Please try again 11 Too low Please enter a number 13 Good job You took 2 guesses Congratulations You did better than the previous player who took 6 guesses OI39 Hello and welcome to the game You need to guess a number between 100 and 100 Please enter a number 99 Too high Please enter a number 50 Too low Please enter a number 10 Too low Please enter a number 10 Too low Please enter a number 30 Too high Please enter a number 13 Good job You took 6 guesses Congratulations You are the first person to ever complete the game 3 Games for good lab2pr3 txt Watch the talk by Justin Tan Using video games for better medical rehabilitation 14 minutes httptedxmontrealcomtalksjustintan As you can see from the talk gaming hardware can relatively easily be used for medical purpose Initially computer games were developed as entertainment but now have found practical uses in several unexpected areas Using Internet search and your imagination discover the cases in which computer game software and gaming hardware such as Wii remote Kinect are used to achieve a goal other than entertainment One notable example is FoldIt project but there are many more areas where computer games brought advances You can talk about existing cases or you can envision and predict potential application of gaming technology in other areas of life In your answer provide at least 3 examples max is 7 with 2 4 sentence description for each case For your answer you re welcome to consult any source you nd credible including internet sites and forums family members friends outside of class your class colleagues etc of course it s optional and you may complete the answers on your own or with your partner There is no one right answer to this problem CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 3 Due Monday 92115 at 1159 pm on Blackboard In this lab you will create a program that simulates work of an interactive data management system Gibson that s used to manage student info at Tulane likely grew from a system very similar to the one that you ll write in this lab The role of the database collection of records will be played by Python dictionary and you will write functions that will manipulate data in the dictionary In our example we ll keep a record of students and their associated majors however the same ideas will apply in any real life application where we need to keep and update records such as a database of stocks and their prices employees and their salaries at HR of ce accounts and their balances in a bank and so on Please follow the usual homework guidelines le naming rules honor code comment requirements Start early and give yourself enough time to work on this lab Note the new requirement docstring for every function you write in this lab should contain a brief explanation of the parameters and their type and return value type A conventional way to write such explanation has the format str gtint in this example the function has one input a string and returns an integer value This approach will be further explained in Wed Sep 17 class Before your start working note one interesting technical aspect dictionary is a muta ble data type When we talked about immutable data types such as integers or strings we said that when a function is called a function s own copy of parameter is created within a function and all changes made to this parameter will disappear after the func tion exits It is different with dictionaries and lists and other mutable data types If you pass a dictionary as a parameter to a function all changes made to this dictionary will stay after function has nished its execution Check for instance the following code def addnumbers assume numbers is a dictionary holding phone directory numbers800 quotToll freequot add a new number to the phone directory return d 911quotEmergencyquot addd call our function that adds an entry to dictionary printd you should see that after add function ends changes to the dictionary stay now the dictionary has two phone numbers Run this in Pythontutor too to get a better illustration 0 Look Up and Add lab3pr0py For this exercise start by having a prede ned dictionary storing a few student names and majors such as majors Harry Computer Science Hermione Mathematics Ron English Place the line with your dictionary initialization in the beginning of your le As you can see the name will serve as a key and major will be the value For simplicity we ll assume that each person will only have one major a Write a function lookupd where d is dictionary containing names and majors The function should ask the user to enter a name If the name is in the dictionary it should print out the major associated with the name If the name is not in the dictionary it should print Not found Sample output of your function should look like this gtgtgt lookupmajors Enter a name Harry Computer Science gtgtgt lookupmajors Enter a name Ron English gtgtgt lookupmajors Enter a name Voldemort Not found If you have problems writing code for lookupd function rst write a pro gram without writing a function ie without using defreturn just start with a given dictionary and proceed with asking the user for name and print ing the corresponding major for that name b Now write a function addd that asks the user to enter a name and a major It then adds this information as a new entry in the dictionary 1 If the name entered already exists in the dictionary do not alter the dictionary just print out A person with this name already exists in the system Sample output of your function should look like this gtgtgt addmajors Enter a name Hagrid Enter a major Physics gtgtgt majors Harry Computer Science Ron English Hagrid Physics Hermione Mathematics gtgtgt addmajors Enter a name Ron Enter a major Art A person with this name already eXists in the system 1 Change and Delete lab3pr1py For this problem use the same starting dictionary from above a First write a function change 1 that allows a user to change an entry of a dictionary The function should ask the user to enter a name If the name is not already in the dictionary it should print That name is not found If the name is in the dictionary the function the ask the user to enter a major Then the function should change the dictionary entry to include the new major Sample output of your function would look like this gtgtgt changemajors Enter a name Harry Enter the new major Biology gtgtgt majors Ron English Hermione Mathematics Harry Biology gtgtgt changemajors Enter a name Voldemort That name is not found b Now write a function delete d that allows a user a delete an entry from the dictionary d The function should ask the user for a name If the name is in the dictionary its entry should be removed If the name is not in the dictionary the function should print That name is not found Sample output of you function should look like this gtgtgt deletemajors Enter a name Harry gtgtgt majors Hermione Mathematics Ron English gtgtgt deletemajors Enter a name Voldemort That name is not found 2 Choice Menu and Dictionary display lab3pr2 py a Write a function getmenmchoice that displays to the user all of the pos sible choices look up add change delete and quit Each choice will have a number associated with it Then the function asks the user to make a choice If the user enters an invalid choice the function should ask again for a choice Once a valid choice is entered the choice should be returned Example output is as follows gtgtgt getmenuchoice Majors of College Students 1 Look up a student s major 2 Add a new student 3 Change a major 4 Delete a student 5 Display all students 6 Quit the program Enter your choice 7 Enter a valid choice hello Enter a valid choice 2 2 b Write a function displayd that displays all entries in a dictionary one name major pair per line as follows gtgtgt displaymajors Hermione is a wizard in Mathematics Harry is a wizard in Computer Science Ron is a wizard in English Remember our discussion dictionary does not preserve the order of entries Students that were added later may appear in the beginning of the list don t be puzzled by that 01 extra credit pts Format the output of displayd function so that it nicely aligns names like this gtgtgt displaymajors Harry is a wizard in Computer Science Ron is a wizard in English Hermione is a wizard in Mathematics If necessary you can assume that the longest name in the system will have at niost 10 characters 3 Main lab3pr3 py Now we write our main function We rst copy all functions that were developed in other homework les into lab3pr3 py Inside the main function start with an empty dictionary majors Now use the getmenuchoice function to ask the user for a choice When the user makes a choice the corresponding function should be called to alter or access the majors dictionary Then the user should be prompted to enter another choice This should continue until the user enters the choice of quitting the program An example run is as follows gtgtgt main Majors of College Students Look up a student s major Add a new student Change a major Delete a student Display all students Quit the program Enter your choice 2 Enter a name Hagrid Enter a major Computer Science Majors of College Students 1 Look up a student s major 2 Add a new student Change a major Delete a student Display all students Quit the program DWIgt00 Enter your choice 2 Enter a name Hedwig Enter a major Mathematics Majors of College Students 1 Look up a student s major 2 Add a new student 3 Change a major 4 Delete a student 5 Display all students 6 Quit the program Enter your choice 1 Enter a name Hedwig Mathematics Majors of College Students 1 Look up a student s major 2 Add a new student 3 Change a major 4 Delete a student 5 Display all students 6 Quit the program Enter your choice 3 Enter a name Hagrid Enter the new major Physics Majors of College Students 1 Look up a student s major 2 Add a new student 3 Change a major 4 Delete a student 5 Display all students 6 Quit the program Enter your choice 1 Enter a name Hagrid Physics Majors of College Students 1 Look up a student s major 2 Add a new student 3 Change a major 4 Delete a student 5 Display all students 6 Quit the program Enter your choice 4 Enter a name Hedwig Majors of College Students 1 Look up a student s major 2 Add a new student 3 Change a major 4 Delete a student 5 Display all students 6 Quit the program Enter your choice 1 Enter a name Hedwig Not found Majors of College Students 1 Look up a student s major 2 Add a new student 3 Change a major 4 Delete a student 5 Display all students 6 Quit the program Enter your choice 6 up to 1 extra credit points Modify your main function so that it stores the dictionary in le inputtxt between successive runs of your program That is in the very beginning of the program it should check whether le inputtxt exists and if yes it should read the data from the le into dictionary At the very end of the program it should write dictionary content into inputtxt How you store the data into le is really up to you Reading and writing parts should be handled by separate functions to avoid cluttering the code of main function Computer history exhibit lab3pr4 txt In this assignment you will take a role of a museum curator You will select a piece to represent a milestone in computer technology development Together with your class you will create a CMPS 1500 virtual exhibit of computer history To start watch a TED talk by John Graham Cumming The greatest machine that never was 12 minutes httpswwwtedcomtalksjohngrahamcummingthegreatestmachinethatneverwaslang about the machine that was the rst computer and about the rst programmer Then take some time to visit the exhibits Computer History Museum httpwwwcomputerhistoryorgexhibits Select one piece for our virtual exhibit It can be a computer program a hardware device eg the rst mouse or computing device can be an idea or its realization or phenomenon or event Essentially something that changed the path of computer technology development It doesn t have to be in use today For your answer submit a link to your piece an article or video about it the year when the piece rst appeared and a 3 5 line description of why you believe this is a crucial piece for the exhibit what was its role in computer history This is not a knowledge based assignment you re not expected to know much com puter history going into this class You should spend time reading and researching before your provide the answer Your link doesn t have to go to computerhis toryorg if you nd an interesting video on youtube or elsewhere or maybe you d like to make one you should include it instead Remember to provide the speci c detail that identify your piece don t just say a mouse mention maker model and year for the mouse and so on The examples used in the text of this assign ment Babbage engine and mouse are already taken and cannot be used as an answer CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 4 Due Monday 92815 at 1159 pm on Blackboard Please follow the usual homework guidelines le naming rules honor code comment requirements Read the entire assignment before you begin working on it 0 Encode and Decode lab4pr0 py In this exercise you will write a program that encodes and decodes text using a Caesar or shift cipher one of the oldest encryption algorithms The cipher works by replacing each letter of the original text with the letter some xed number of positions down the alphabet The xed shift number will be called the key You have seen that every character as an integer representation that can be found using the 0rd function in Python Given an integer you can switch back to the character representation by using the chr function Write a function encodecharch key that takes a lower case character and shifts it according to the key You may nd it easier to work on this function in steps a b Begin by specifying a function contract in the function docstring First work on encoding only lower case characters they have have integer rep resentations between and including 97 and 122 Begin writing your function by specifying tests in doctest format gtgtgt encodecharquotaquot 1 3b gtgtgt encodecharquotaquot 3h 7 Add at least two other test cases that test boundary input values refer to the slides on Blackboard for the guideline Once you are done with writing the function save and test it using doctest module Next modify the function make sure that when the code of the shifted character goes outside 97 122 range it wraps around to the beginning of lowercase alphabet z shifted by 1 position should yield a You also want to make sure that your function works for values greater than 26 Hint you will nd mod function handy Sample tests gtgtgt encodecharquotaquot 27 3b gtgtgt encodecharquotzquot 1 a Make sure you add at least two other tests of your own Now modify your function to also handle uppercase characters and then test both uppercase encoding and wraparound 6 Make sure that your function works for negative keys and allows the charac ters to be shifted to the right The function should work for uppercase and lowercase characters and they should also wrap around Finally make sure that if the input character is not a letter it is returned unmodi ed Make sure that each of the above 5 cases has at least 2 associated doctests Do not copy the sample tests from this assignment document Quote char acters don t copy well from the document and cause your seemingly correct tests to fail You can use the provided test but you have to type them from keyboard rather than copy and paste 1 Encoder and Decoder lab4pr1py a Write a function encode text key that encodes a string using the key and returns the encoded string Only letters should be changed every other character should remain the same in the encoded string Example test gtgtgt encodequotHello Worldquot 5 quqt Btwqi Begin by specifying a function contract in the function docstring and then providing several tests in doctest format Write a function decode text key that decodes a string using the key and returns the decoded string Note that key represents the key that was used to encode the text Example test gtgtgt decodequotquqt Btwqiquot 5 Hello World Begin by specifying a function contract in the function docstring and then providing several tests in doctest format Make sure that your function returns the string rather than just prints it decodeencodequotHello Worldquot 55 should return Hello World and encodedecodequotquqt Btwqiquot 55 should return quqt Btwqi Write a function encoder that asks the user for a text le to be encoded Then ask the user to enter a key integer positive number Using the user input read the le encode its contents and display the code to the user Then ask the user to enter a lename to save the code text to and saves the result into that le d Write a function decoder that asks the user for a text le to be decoded Then ask the user what key was used to encode that le Use this input to read the coded le decode the text and display the message to the user Then ask the user to enter a lename to save the decoded text to and saves the result into that le Finally write a main function that displays to the user three choices encode and decode along with the option to quit Read the user input and call the appropriate function 3Rn1canrwethef esrsacodetxtinuizimmermanntxttotestyourdecodnu rsacodetxt was encoded using 13 as the key and zimmermanntxt was encoded using 17 as the key If you decoding is correct you should get meaningful text There s also a test le secrettxt that was encoded with 42 as the key gtgtgt Encode 1 or decode2 or quit 9 1 Enter the file you would like to encode tulanetxt Enter the integer key you want to use for encoding 3 Here is your encoded text ondqh quyhuvlwb lv d sulydwh qrqvhfwduldq uhvhdufk quyhuvlwb orfdwhg lq th Ruohdqv Orxlvldqd quwhg dewhv Irxqghg dv d sxeolf phglfdo froohjh lq 1834 wkh vfkrro juhz lqwr d frpsuhkhqvlyh quyhuvlwb lq 1847 dqg zdv hthwxdoob sulydwlchg xqghu wkh hqgrzphqu ri deo ondqh dqg Mrvhsquh Orxlvh thfrpe lq 1884 ondqh lv d phpehu ri wkh varfldwqu ri Dphulqu quyhuvlwlhv Enter a filename to save the encoded text outputtxt Your encoded file is ready Have a nice day gtgtgt Encode 1 or decode2 or quit 9 2 Enter the filename that you wish to decode outputtxt Enter the key that decodes your cipher 3 Decoding the cipher using that key gives the following text Tulane University is a private nonsectarian research university located in New Orleans Louisiana United States Founded as a public medical college in 1834 the school grew into a comprehensive university in 1847 and was eventually privatized under the endowments of Paul Tulane and Josephine Louise Newcomb in 1884 Tulane is a member of the Association of American Universities Enter a filename to save the decoded text tulanetxt Your decoded file is ready Have a nice day encoderdecoderandnminfunc onsdonEtakeanyinputpamnneuus and return None Contracts and doctests are not required for these functions If you re getting File not found errors make sure that the code le that you re editing and your text input les are in the same folder Extra credit for geeks up to 1 points for English to Leet and up to 1 points Leet to English conversion Write a converter of a standard English text to Leet httpenwikipediaorgwikiLeet The text should be read from input le and written to output le just like in the main portion of the assignment As the rst step you ll replace suf xes in words as described in Wikipedia article As the second step some characters should be replaced with symbols The third step will process exceptions and speci c words There s no uniform 1337 standard and hence most choices about the converter are left to you In the top docstring of your program you should explain how your program works it would also be nice to print some explanation to the screen The converter does not have to be perfect and it s ok if it skips some words some times The output text should look suf ciently cryptic for a n00b but should be readable by an informed user This part of the program should be presented as a separate menu item in the main function Supply 3 4 sample input les with your program in one zip archive Codebreakers lab4pr2 txt The encoding decoding system that you implemented in this lab is one of the early encryption methods used by the humanity It would be easy to decrypt the text produced by Cesar cypher just try all possible 26 shift values on the input and view the resulting text Devising encryption methods that would be hard to decrypt as well as breaking those methods is a dif cult task Some people argue that understanding how to break codes is as important as understanding how to make them Watch the talk by security analyst cyber punk hacker pride geek girl Keren Elazari Hackers the Internet s immune system 16 minutes httpswwwtedcomtalkskerenelazarihackerstheinternetsimmunesystemt861538 a What s your opinion on the speaker s main argument Do you agree that hackers are the Internet s immune system Why or why not Explain your point in 3 6 sentences b There are several examples in the talk of the situations in which hackers may have done good but their actions where illegal according to the current law How do you think the law should treat hackers breakers cyberattackers Explain your point in 3 6 sentences c In 3 6 sentences summarize the possible positive and negative effects of hacker s actions Feel free to use recent events such as Target data break Sony Pictures data leak Ashley Madison hack search for these news on Google if necessary as examples CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 5 Due Monday 10515 at 1159 pm on Blackboard Please follow the usual lab guidelines le naming rules honor code comment requirements Read the entire assignment before you begin working on it Make sure you understand ppm format before you start coding 0 We are going places lab5pr0py In this exercise you will write a program that automatically generates image les for ags of different countries A computer image is a two dimensional grid of pixels Each pixel represents the smallest undivisible part of the computer screen An image le is an assignment of color to each pixel Pixels are referred to by their Cartesian coordinates The top left corner of an image has the coordinates 0 0 The bottom right corner has the coordinates 721 ml where n is the width of the image in pixels and m is the height of the image in pixels PPM format explanation Portable Pixel Map ppm le format is a simple format for storing graphical images Sample ppm le P3 44 255 000 10000 000 255 0255 000 0255175 000 0 00 000 000 015175 0 00 255 0 255 0 0 0 0 0 0 255 255 255 The rst few lines are de ned as the image header They provide an overview of the contents of the image PPM headers consist of four entries which will be de ned using the example P3 4 4 255 0 P3 de nes the image format that is what type of PPM full color ASCII encoding image this is For this assignment it will always be P3 0 Next comes the number of columns and the number of rows in the image The example is a 4 pixel by 4 pixel image 0 Finally we have the maximum color value This de nes the scale of values possible for the color intensities This can be any value but a common value is 255 meaning the red green and blue values for a pixel can range from a value of 0 upto 255 The way you see the header presented is how it should be appear in your image les too except you ll use your own dimensions The image body contains the actual picture information as a series of RGB values Each pixel of the image is a tiny colored square In the PPM le each pixel is de ned by a triplet of values representing how much red green and blue RGB are present So the rst pixel which has a value of O O O is black and the last pixel 255 255 255 is white By varying the levels of the RGB values you can come up with any color in between You can search the Internet to nd nice colors for your images in this assignment Note that color values must be separated by a space but after that any additional whitespace is ignored by the image viewer In the sample ppm above we used additional whitespace to format the pixel values so that it is easy for a human to understand but the computer doesn t care if everything is on one line if there is one line of RGB values per line of the image or some mix You should not assume one line in the le corresponds to one line in the image Viewing ppm les Your Python program will create ppm les and write to them just like you wrote to text les However to view the result as an image you ll likely need to install a viewer program standard picture viewers such as Picasa MS Paint etc do not recognize PPM format Freeware ie free software picture viewers exist One such viewer XnView can be downloaded from httpwwwxnviewcomenxnviewhtml a Write function getheader width height that takes in the desired image dimensions and returns a string with ppm le header as described above Remember to add function contract in the docstring For this function only you re required to provide 2 3 doctests b Your rst image is a ag of Netherlands The ag of Netherlands consists of three equal sized horizontal elds The colors top to bottom are red white and blue Write a function netherlands width height that takes in the dimensions of the ag and returns a string containing the all pixels of the ag If necessary for simplicity you can assume that the value of height is evenly divisible by 3 For example netherlands4 3 should return one long string containing the following values here you see this string broken into 3 to t the screen 25500255002550025500 255 255 255 255 255 255 255 255 255 255 255 255 00255002550025500255 This is a lab for nested loop practice You need to use nested loops to receive credit for this lab DO NOT USE STRING MULTIPLICATION or other ways to avoid using loops ag functions without nested loops will not receive credit c Now write a main function that you will use to test the above two functions It will be responsible for interacting with the user and calling getheader and netherlands 0 It should ask the user for ag dimensions and name of output le that is to contain the image Then it should generate a header and write it to the output le and then generate image body and write it to the output le Please enter width 400 Please enter height 300 Please enter output file name hollandppm The output has been written to hollandppm View the result in XnView View the resulting le in XnView and make sure that it looks like the ag of the Netherlands Note that the results of computation performed by this function are not di rectly displayed to the user It is a nice gesture on the program s part to inform the user that the computation is completed and how to see the re sults Please adapt this practice in your own programs that write the results to the le or otherwise don t display results directly d Next is the ag of Nigeria It s ag consists of three equal vertical sections green white green Write a function nigeriawidth height that gener ates the ag You can assume the value of width is evenly divisible by 3 Remember to specify function contract and use nested loops e Modify your main function to use nigeria instead of netherlands 0 You shouldn t need to modify anything else in your main function Use it to generate ppm le with Nigerian ag f Next image is the ag of the United Arab Emirates The ag consists of a vertical red eld at the hoist left side of the ag and three horizontal elds of equal height at the y right side of the ag The colors of the horizontal elds are from top to bottom green white black The width of the red eld is quarter of the ag s width Write a function uae width height that generates the ag You can assume the value of width is evenly divisible by 4 and height is evenly divisible by 3 Remember to specify function contract and use nested loops g Modify your main function to use uae Use it to generate ppm le with ag of the United Arab Emirates h Optional extra credit problems use nested loops to generate ags of Fin land Scotland or another country of your choice with a more sophisticated ag pattern than those described above consider Switzerland Bangladesh Republic of Congo Seychelles Greece or similarly complex ags up to 05 points per ag for the max of 2 points per 4 different ag patterns Each ag image should be generated in its own function 1 Elements of computer organization lab5pr1 pdf In the following exercise you will practice working with binary numbers and creating digital circuits The answer should be submitted electronically you have the choices how to produce the an swers draw by hand and take photo scan the drawing then insert the image into a Word le and save that le as a pdf but the most preferable way would be for you to use LogiSim software to generate your circuits then Export to png le and insert that le into Word le use google to nd Logisim a Hexadecimal numbers are numbers in base 16 They use the following sixteen digits 0 12 34 5 6 7 89ABCDE F They are widely used in com puting for example to represent colors or network addresses of computers i Convert A1F2316 to decimal Show your work ii Convert 547610 into hexadecimal Show your work iii Convert 00010101111000002 to hexadecimal Explain how can you use the fact that 16 24 iv If you convert a 64 bit binary number into hexadecimal how many hex adecimal digits does it have Explain b In this exercise you will design part of a circuit for adding three bits 10 y and cm resulting in two outputs Gout and 2 that represent the addition cc yl cm This is the same as the full adder that we covered in class You have already designed a circuit for computing Gout the odd parity function and now you ll make one for computing 2 the sum bit You can design your own truth table for the sum bit or nd it in slides Then you should write a corresponding minterm expansion logical formula and then draw a corresponding circuit 2 Visualization lab5pr2txt Representing the information visually has led to dra matic advancement of many elds Watch the TED talk by Hans Rosling The best stats you ve ever seen 17 min utes httpwwwtedcomtalkshansroslingshowsthebeststatsyouveeverseen a Look at the list of undergraduate major programs at Tulane http admission tulane edu acade Select 4 professions majors in which the people are highly engaged in data analysis and are likely to bene t from data visualization tools such as gapminder org presented by Prof Rosling For each of the 4 examples name the area and explain how the data visualization tools can be bene cial b Find your own example story of how computer graphics or visualization help in everyday work of a non CS professional Submit a link to this story can be video podcast or online article and a 2 3 sentence summary CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 6 Due FRIDAY 10915 at 1159 pm on Blackboard Please follow the usual lab guidelines le naming rules honor code comment re quirements doctest requirements Read the entire assignment before you begin working on it Instagram Facebook and automatic image analysis 1ab6 py A computer image is a two dimensional grid of pixels Each pixel represents the smallest undivisible part of the computer screen An image le is an assignment of color to each pixel Pixels are referred to by their Cartesian coordinates The top left corner of an image has the coordinates 00 The bottom right corner has the coordinates 721 ml where n is the width of the image in pixels and m is the height of the image in pixels In this lab you will be working with another image format png very popular on the internet format Portable Network Graphics File reading and writing in png format are handled for you by a provided csSpng module This module will hand you a function that reads in the le image and stores it in a 2D list of lists Each element of this grid represents a pixel and each pixel is in turn a list of 3 numbers one number for red green and blue component respectively so in essense you are dealing with 3D list Some example applications for functions written in this lab are Instagram lters Facebook avatar lters eg a rainbow lter or recent India lter and automatic image analysis eg knowing how much white is on the image is the rst step in deciding whether that image is likely to be of northern winter or of white dress style wedding Download and unzip the assignment les in the same folder 0 Run the example lab6 le and take time to understand the details of its work 1 Using invert pixel function as example write a function light enpixel image n that takes in the 2D list of pixels and a positive number n and adds a number n to color value of each pixel Note the resulting value should not exceed 255 If you get a greater value replace it with 255 2 Using invert image function as example write a function lightenimage image n that takes in the 2D list of pixels and a positive number n and returns a new 2D list of pixels with all pixels lightened Test this function on kitten and some of your own images Eg if you test kitten with n 50 you should get a visibly lighter image as a result 3 Write a function for automatic image analysis colorcount array color that takes in a 2d array of pixels and color as a 3 number list and returns how many pixels of that color the image has To test this function make your main to also output the ratio of pixels of the given color to the total number of pixels 4 Write a function for automatic image analysis colorreplacearray colorin colorout that takes in a 2d array of pixels and returns a new array of pixels where pixels of colorin are replaced with pixels of colorout 5 Write a function that produces the mirror image of the original image The mirror image contains all pixels of the original image but their coordinates need to be changed 6 Rewrite your main function to contain an in nite input accepting loop that pro Vides the user With a menu of possible image transformations reads in names of input and output les from the keyboard and calls the appropriate functions This lab is purposefully short in the speci cation to encourage you revisit What we have done in class so far and apply that knowledge but if you get really puzzled about some of its parts feel free to bring up your questions in class or to the TAs CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 7 Due Monday 102615 at 1159 pm on Blackboard Please follow the usual homework guidelines le naming rules honor code comment requirements A gentle reminder to add function contracts docstrings and comments to your code add doctests for speci ed functions and give meaningful names to your variables and functions Very sad to see people lose points in perfectly running programs for lack of comments presence of legacy code etc See Python code style requirements document on our course webpage Read the entire assignment before starting your work in order to plan your time 0 Recursive functions lab7pr0py a Write a recursive function 3 aces s that counts a number of space charac P ters in the input string Do not use loops or built in Python string functions the only string functions you can use are slicing and indexing gtgtgtgt n spacesquotHello worldquot printn 1 Add comments to your code to point out the base case and the recursive case Below the function add a comment describing 2 real life scenarios when this function or its variation can be useful b From the standpoint of Python words like world and world as dif ferent words So if we wrote an automatic English to Spanish translator that replaced world with mundo world would have been replaced and world wouln t Ie we notice that before we can write a program for au tomatic translation we need to nd a way to ignore punctuation in a string Write a recursive function cleanstrings that would remove all symbols that are not uppercase or lowercase letters or space from s and return the clean string Do not use loops gtgtgtgt GS cleanstringquotHello worldquot printCS Hello world Add comments to your code to point out the base case and the recursive case c Using a similar idea to the one you employed in cleanstrings func tion write a recursive function cleanlist11 12 that takes two lists as input and returns a list of elements from 11 that are not present in 12 Do not use loops gtgtgtgt unique cleanlist1234567 246l printunique 1357 Add comments to your code to point out the base case and the recursive case 1 Sort veri cation lab7pr1py a Write a function issortedlst that takes as input a list of numbers and returns True if the list is sorted in increasing order and False otherwise Provide doctests that test your function for several inputs It s fantastic if you can make your function recursive but in this case it s ok to use loops as well Write a function isfilesortedfilename This function takes as input a name of the input le containing a list of integer numbers one number per line and returns True if the list is sorted in increasing order and False otherwise Test your function with several inputs Now add main part of the program that prompts user for input and outputs a user friendly message with the result as follows gtgtgt Please enter file name inputtxt Looks like inputtxt needs to be sorted 0139 gtgtgt Please enter file name inputsortedtxt Congratulations The file inputsortedtxt is nicely sorted For each code line of your le add a comment describing the asymptotic running time of that line of code in terms of n the number of entries in the input le On the last line in your le add a comment with the total big Oh running time of this program and a brief justi cation 2 Sort usage lab7pr2py a Carefully study the implementations of sorting algorithms provided with this homework Write a function usemergesortinputfile outputfile This function takes as input a name of the input le containing a list of integer numbers one number per line and the output le name This function should read in numbers from the le sort them using the provided mergesort function and output the sorted numbers to the output le one number per line Important Remember to convert string values to integers before sorting Otherwise your numbers will be sorted alphabetically for example numbers 121112 will be sorted 111122j which is not the right order for integers Write a function useselectioninputfile outputfile This function takes as input a name of the input le containing a list of integer numbers one number per line and the output le name This function should read in numbers from the le sort them using the provided selection sort function and output the sorted numbers to the output le one number per line c Write a function generatenumsfilename n that makes a le named filename and writes to it n random numbers from 0 to 99 inclusive Refer to the random number example provided in the hw Use generatenums function to generate les of different size that you would then use for testing your usemergesort and useselection 3 Practical performance of sorting lab7pr3py In class we spoke about the oretical analysis of merge sort and selection sort algorithms In this exercise you evaluate the performance of these two algorithms in practice Start by carefully studying the le with the examples of time functions a Modify your usemergesort function into analyzemergesort inputf ile outputfile function so that it calculates and displays to the user the time in seconds it took to read in the values from the input le the time it took to sort the values the time it took to output the values to le the total time it took to run the program and the total number of values that were processed Round the seconds value to 6 decimal digits For example gtgtgt analyzemergesortquotinput10txtquot quotsorted10txtquot It took 0008058 seconds to input 10 values from file input10txt It took 1112337 seconds to sort 10 values using merge sort It took 0121144 seconds to output 10 sorted values to file sorted10txt Total time the program took is 1241539 seconds Your numbers will be different from mine b Similarly modify your useselect ion function into analyzeselect ion inputf ile outputfile function gtgtgt analyzeselectionquotinput10txtquot quotsorted10txtquot It took 0008058 seconds to input 10 values from file input10txt It took 1112337 seconds to sort 10 values using selection sort It took 0121144 seconds to output 10 sorted values to file sorted10txt Total time the program took is 1241539 seconds 4 Sort analysis lab7pr4pdf Now you are ready to compare merge sort and selection sort side by side First use your generatenums function to generate les with 10 100 1000 10000 100000 and 1000000 numbers Then run your analyze functions from the previous exercise on these les Your goal is to see how much time selection sort and merge sort take on the same list of numbers Note last year selection sort on a million numbers took 29 hours on a standard laptop You can use this value in your analysis if you don t have patience to wait until your simulation completes Include in your submission the explanation with approximate time that you waited before you stopped the program and also your prediction on how long the program would actually take based on its performance for a smaller set of numbers It would be interesting to see the numbers for this year let me know if you gure it out a d First for each of the input sizes copy the info about time taken by both functions into a Word le Clearly separate the outputs produced by running different les Highlight the time taken by the sorting portion of the program You only need to copy the time measurements Do not copy the numbers that were actually sorted In each case state what percentage of total running time is taken by input and output Look at these percentages and answer what are these numbers telling us Make four graphs On the rst one plot the time taken to merge sort the le vs the number of values in the input On the second one plot the time taken to selection sort the le vs the number of values in the input Make sure you only use the actual sorting time not the total time of the program Now repeat these steps but plot the actual time taken by entire program vs number of values processed one graph for merge sort and one graph for selection sort Add clear captions to your graphs You may want to Excel to produce graphs and copy them into your Word le You are free to use any other word processing plotting software that you re familiar with In a few sentences interpret your graphs What are the plots telling us Save your le as pdf and submit it to blackboard Algorithm competition lab7pr5txt Asymptotic analysis is one good way to compare algorithms but as you could see in the previous exercise running the algorithms side by side on the same input adds to the understanding of relative algorithm performance Using Internet search nd two concrete examples when performance of software programs or technical devices is being compared side by side with other programsdevices or with performance of humans such as the annual robotic soccer competition httpwwwrobocup2015org where different classes of robots are compared based on their ability to play soccer Your response can refer to a story or news item or video or established competition a b C d Submit links to both of your examples Provide a 2 3 sentence description of the essence of the competition Explain how the winner is decided what is the success criterion speed accuracy For your two examples can you imagine a way to combine technology from these two examples to make an even more powerful technology For instance if one competition is between soccer playing robots and one between voice recognition software then installing voice recognition software on those robots could help robots from the same team communicate during the game with sound commands thus improving their play If yes describe this imaginary combination If not explain how either of these technologies can help humans achieve their routine tasks more ef ciently CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 8 Due Monday 110215 at 1159 pm on Blackboard Please follow the usual homework guidelines le naming rules7 honor code7 comment requirements Read the entire assignment before starting your work in order to plan your time Some important points 0 When you re asked to measure time of program execution refer to the past lab where you were evaluating performance of sorting and use those commands o Turtle programs should end with done statement If you miss done function call7 then IDLE may freeze This is extremely inconvenient both for you and graders Remember to add done 0 Recursion vs iteration lab8pr0pdf As we discussed recursion is a very powerful problem solving technique any com putation can be expressed recursively However recursion doesn t always lead to ef cient solution as you will now see A classic example of recursion is the de nition of Fibonacci number Wikipedia has a good article about it httpenwikipediaorgwikiFibonaccinumber Remem ber to check the part that talks about Fibonacci numbers in nature A Fibonacci number is de ned as follows F0 2 0 F1 2 1 E Fn1 Fn2 for n gt 1 a Write a recursive function Fn that returns n th Fibonacci number In comments mark the base case and recursive step b Write an iterative function using iteration ie loopsf n that returns n th Fibonacci number 0 For the recursive version F n illustrate recursion trace for the function calls that take place when F6 is computed You ll need to scan your trace and add it to the report document or you can draw one electronically The trace should illustrate what function calls what other functions and with what parameters as discussed in the lab session d Just like you did in the previous lab measure the time it takes to compute 10th 20th 30th and 40th Fibonacci numbers using your iterative and recur sive functions Copy the values into the report document where you make a table illustrating n and the time it took to reach the solutions in a couple of sentences compare the ef ciency of recursive and iterative solutions and explain why it takes long to compute larger Fibonacci numbers Copy the code of Fn and f n in the bottom of the report document 1 Turtle race turtlerace py Complete the provided starter le replacing com ments with appropriate Turtle graphic commands Run your program after each step and don t move to next step before you get the preceding step to work When this exercise is complete you will see three turtles running off the screen and the counter changing values with each step Up to 1 point extra credit is available for submissions that improve the turtle race beyond the basic one You may display starting and nishing line you can add detection for crossing of nish line and display a victory message you may make each turtle have a speed function or add other functionality that makes the race more fun Clearly explain your additions in the header comment of turtleracepy le 2 Time milclockpy Suppose we are writing an application for the military pur pose and nd that we need to keep and use time in 24 hour format also known as military time Write a class MilClock Its attributes will be hours and minutes for the methods it should at minimum have a constructor overloading of str function that should return time in hhmm format and a method addOne that would add one minute to the current value of the clock Place your MilClock class in a sepa rate le milclockpy From the course website download the test le and place it in the same folder with your milclockpy When your MilClock is correct you should be able to run that test le and get the following output We wake up at 0500 We get up at 0530 We are sleepy again by 0610 Last tram leaves at 2300 Today ends at 2359 Tomorrow starts at 0000 Rationality rationalpy In class Rational copy the code from your notes or slides on Bb overload the following three operators division power raising a Rational to exponent exponent can be assumed to be non negative integer conversion to oat This exercise is essentially an opportunity for you to test the code that you developed in class or something very similar to it NOTE one important correction for division in our version of Python we should be overloading truediv method The test le is provided When your Rational class in rationalpy is correct you should be able to run the test le and get the following result My first rational is 27 Its cube is 8343 Its approximate floating point value is 02857142857142857 My second rational is 13 My first rational is 67 times larger than the second one Cybersecurity lab8pr4txt In the past weeks you explored applications of com puting in different elds of study In the next few weeks you ll be looking at the impact computing technology is making on societies and humanity in general In the spirit of upcoming Halloween we ll start with the scary topic Watch the TED talk by James Lyne Everyday cybercrime and what you can do about it 17 minutes httpwwwtedcomtalksjameslyneeverydaycybercrimeandwhatyoucandoaboutit a One of the types of crime that computing technology made extremely easy to achieve is identity and personal data theft In your opinion why identity theft is a problem How can identifying information be misused What about other types of personal data Think about 2 3 different areas of one s life eg what if your grade information is stolen What about your health records Or purchase history Explain your point in 3 6 sentences b In the talk the speaker mentions several ways of making oneself vulnerable by exposing too much data For instance posting photos taken at home publicly allows the entire world to see your home address gps coordinates if geotagging is not turned off Which of these steps are true about you and which are not After watching this talk do you believe it is possible to completely avoid exposing personal data Why or why not Provide a 3 6 sentence answer CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 9 Due Monday 11915 at 1159 pm on Blackboard Please follow the usual homework guidelines le naming rules honor code comment requirements Read the entire assignment before starting your work in order to plan your time Note you can use Node class developed in lectures in all your assignments and refer to modify the code provided on Blackboard 0 Linking two linked lists linkedpy linkedpdf a Write a function joinhead1 head2 that takes as input the front nodes of two linked lists and links those two linked lists together The second list should be linked to the end of the rst list Note that you re not given the tail of the rst list you need to nd it and then connect head2 to it There should not be any new nodes created The function should return the front node of the result list Test your function with several inputs b What is the asymptotic running time of your function in terms of n where n denotes the total length of both input lists Please write your answer as a comment in your code together with a very brief justi cation c Consider running your code on the following two lists L1 a gt b gt c gt and L2 d gt e gt f gt Trace your code by showing on paper the changes in the variables and in memory during the execution of your function Scan or photograph your work and submit with your homework as pdf 1 Length of list lengthpy lengthpdf a Write a recursive function that takes as input the head node of a linked list and returns the number of nodes in the list Test your code b What is the asymptotic running time of your function in terms of n where n denotes the total number of nodes in the list Add a comment on top of your code with big Oh value and brief justi cation c Consider running your code on the following list L a gt b gt c Trace your code by showing on paper the function calls that take place their input parameters and return values in other words provide recursion trace like we did in class Scan or photograph your work and submit as a pdf le 2 FIFO Queue fifoqueuepy A rst in rst out queue FIFO Queue is a data structure that conceptually stores a linear list of items by providing the following functionality o enqueueitem appends the new item at the end of the queue o dequeue removes the front item from the queue and returns it It returns None if the queue is empty 0 isEmpty returns True if the queue is empty and False otherwise Write a class Queue that uses a linked list to store a FIFO queue and that im plements the three methods enqueue dequeue isEmpty in constant time For this you have to store a reference to the front as well as to the rear of the queue and you have to store the size of the queue the number of elements it con tains The three attributesvariables front rear size have to be initialized in the constructor init Make sure that you implement enqueue dequeue isEmpty as methods ie as part of the class and not as functions ie outside of the class For testing remember to also add str method that should return a string with all elements of the queue separated by spaces Add a comment in the code where you justify why the runtime of enqueue dequeue isEmpty is constant Place the code for Node and Queue classes into fifoqueue py Down load testqueue py and place it in the same directory with your queuepy When your program is complete you should be able to run testqueuepy and get the following result Queue now isEmpty True Queue now a isEmpty False Queue now a b Queue now a b c Dequeued a Queue now b c Dequeued b Queue now c Dequeued c Queue now isEmpty True Internet for greater good reflectiontxt This week we continue exploration of the impact computing technology is making on societies and humanity in general and turn our attention to positive sides of this impact Watch the TED talk by Luis von Ahn Massive scale online collaboration 17 minutes httpswwwtedcomtalksluisvonahnmassivescaleonlinecollaboration Then answer these questions a How does Duolingo deal with the fact that people who translate the texts are not professional translators and are beginning learners How can this approach be applied in other areas of life provide an example b What other good products or ideas came out of online collaboration of vol unteers over the Internet Search the web and talk to your circle of friends to generate at least two example products websites or technologies Have you taken part in any such initiative If yes please share your experience In your opinion what are other advantages and advances that personal com puters and connecting them via the Internet has brought to the humanity Give at least three 1 2 sentence examples Try to focus on implications It s clear that computers help us crunch the numbers faster than we would have done manually but what implication this ability has on our everyday life of a person society or humanity in general CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 10 penultimate Due Monday 111615 at 1159 pm on Blackboard Please follow the usual homework guidelines le naming rules honor code comment requirements Read the entire assignment before starting your work in order to plan your time 0 Counting nodes countingpy So far we have been analysing running time estimates for the binary search tree operations by taking into account 72 the number of nodes in a tree We can know 72 for sure if we performed all insertiondeletion operations ourselves What if somebody else hands us a tree and claims it s a binary search tree with n nodes Well depending on who that is we may want to verify their claim before we start using that tree So now you will write a function that veri es that the number of nodes in the tree is indeed n by counting them The task is to write a recursive function count root that takes as input a root node of a binary search tree and returns a number of nodes in the three Up to 1 points extra credit is available if you create a printtree T function that can print a tree in the typical CS way not sideways as we saw in class Make sure your code works for trees with missing nodes on some levels and with up to 8 levels Alternatively you can work on displaying the tree using turtle graphics 1 BST performance bstpluspy We said in class that adding removing and nding elements in a binary search tree can be done in logarithmic time in the best case and linear time in the worst case Now you will measure the practical performance of a binary search tree on a list of words wordlist txt provided with the homework Note that the starter le for this problem already contains Python code to load the le into a list and builds a binary search tree a Time the amount of time needed to insert items in the list Use different size lists by changing how n is computed in the code and characterize the running time to construct the binary search tree Characterize essentially means describing in a few sentences the pattern that you observe and the reason for it b Determine the time to perform 500 nd operations for each size of binary search tree you study above What is the trend that you observe c Given your answers to the previous two questions are the operations as ef cient as they can be In other words are they closer to the best case or the worst case Can you think of a way to improve their ef ciency a descrip tion with explanation will suf ce 05 points extra credit if you implement your algorithm and 05 more points if it has best performance of all of the attempts in class you need to describe your improvements in comments to qualify for extra credit Put your answers to all three questions as comments to the bottom of the code le Linked list from BST linkedpy Write a function bstlist root that takes as input a root node of a binary search tree and returns a head of linked list that stores the result of post order traversal of the tree HINT use recursion to construct a list if you are at a certain node N then the linked list associated with the tree rooted at N is the list representation of left subtree of N joined with list representation of right subtree of N joined with node with the data of N You can use your joinhead1 head2 function of the previous lab to join the lists Doubly linked list doublypy Write Python code that implements a doubly linked list Your code should contain the following a A class ListNodeDouble that stores data a reference next to the next node in the list and a reference prev to the previous node in the list Make sure to add an appropriate constructor and string conversion method b A class DoublyLinkedList Naturally class de nition should have a con structor it s up to you what you place there The methods that are discussed in the rest of the exercise pertain to this class c A function addelement that adds a new element to the front of the list as well as a method addelement that adds a new element to the front of the list Make sure to properly update next and prev references The code for the function and the method will look similar the point is to practice the difference between functions and methods Test both the function and the method You are welcome to use the test le provided with the assignment and you also should do a few similar tests on your own d A function printlist and a method printlist that each print the doubly linked list In addition implement the str method that returns a string representation of the list The code for the function and the two meth ods will look similar the point is to practice the difference between functions and methods and between printing and returning a string Make sure to test the function and the two methods e As comments in the code provide the runtimes for all your functions and methods f At the end of your program give test code that creates and prints a doubly linked list lt 1 2 4 8 Y Then on paper trace your code providing detailed pictures of all the variables and the linked list in memory If you run the test le provided with this assignment you should see Testing node class Created one ListNodeDouble object with data 11 Now testing doubly linked list class Printing the list using printlist method lt1gt lt2gt lt4 gt lt8gt Printing the list using printlist function lt1gt lt2gt lt4gt lt8gt Printing the list using standard print function It implicitly calls str method of the list lt1gtlt2gtlt4 gtlt8gt 3D printing reflectiontxt This week we continue exploration of the impact computing is making on societies and humanity in general Many of advances are brought by technological inventions One of such inventions that today is believed to bring dramatic changes in our day to day life of people very soon is the 3D printing technology Lisa Harouni A primer on 3D printing 14 minutes httpswwwtedcomtalkslisaharouniaprimeron3dprinting Then answer these questions a d How would your day to day life change if you had access to a affordable 3D printer and raw materials What would you print Provide 2 3 sample objects or scenarios and explain the advantages of using 3D printing vs the ways you obtain these products now If when 3D printing becomes as common as high speed internet or washing machines how would the world be different For instance if you can print a plastic cup it won t be necessary to export it from abroad and the world trade and manufacture will be affected Think of speci c examples of people s ability to print things on demand will alter the way we approach things today What computer science problems appear in 3D printing Formulate at least 2 example problems ideally a few more If necessary refer to Wikipedia article on Computer Science to see the list of CS areas and think which of them may be involved in 3D printing What problems topics that we encountered and studied in this class could po tentially appear in 3D printing context Formulate at least 2 speci c example problems ideally a few more PS This is an optional part If you ve been impressed with what 3D printing can do here s another facinating talk about its abilities httpswwwtedcomtalksanthonyatalaprintingahumankidney CMPS 1500 Introduction to Computer Science I Fall 2015 Lab 11 last one this semester Due Monday 112315 at 1159 pm on Blackboard Please follow the usual homework guidelines le naming rules honor code comment requirements Read the entire assignment before starting your work in order to plan your time Notice that test les or sample output are not provided this time for some problems You will need to generate your own test input and provide it as a part of submission When working on graph problems you may nd it helpful to draw graphs on paper and trace the steps of algorithm on paper before you start implementing them 0 Degree of Separation friendshippdf friendshippy Consider the following scenario where friendship is mutual ie if A is friends with B then B is also friends with A Chao is friends with Anna Bob and Deepak Anna and Bob are also friends Deepak is friends with Emma Aisha Chao and Greg Emma Aisha and Isaac are friends Hannah Juan and Greg are friends a Model this scenario as a graph and draw the graph How many vertices and edges does it have How many connected components does it have b What is the largest degree of friendship separation between any two people in this scenario How could you compute this describe your strategy c Input this graph using a dictionary of adjacency lists in a Python le call this dictionary G Answer the rst two questions on paper and submit a scanned version of the document or the image taken with a camera Alternatively you can use your favorite diagram editor and compose your document electronically then convert it into pdf The last question only asks to create a dictionary corresponding to the graph you will use it as a test case for other problems for now just submit the le 1 Diameter diameterpy As we discussed in lecture graphs are the basic abstraction used to model computer and social networks One interesting graph property is the diameter of a graph which is de ned as the longest shortest path between any pair of vertices in the graph If a graph is not connected then the diameter is assumed to be in nite in the code we will denote this case by 1 rather than in nity a Describe what graph diameter means intuitively when we are using a graph to model a computer network and when we are using a graph to model a social network Place the answer in the comments on top of your code le b Describe in English a step by step algorithm for computing the diameter of a graph with n vertices and m edges What is the worst case running time of your algorithm Place the answer in the comments on top of your code le below the rst answer c Implement your algorithm as the diameter function Test it on several inputs including your test graph from the previous problem The starter code for BFS is provided along with several test inputs For the graphs in the input le the output will be Diameter of G is 1 Diameter of G1 is 1 Diameter of G2 is 4 Diameter of H is 3 2 Clique iscliquepy a Given a graph G V E and a number k 1 g k g n the CLIQUE problem asks us whether there is a set of k vertices in G that are all connected to one another That is each vertex in the clique is connected to the other I 1 vertices in the clique this set of vertices is referred to as a 7 kt clique Show that this problem is in class NP veri able in polynomial time by providing a function isClique GXk that given a graph G in a form of adjacency list stored in dictionary and list of vertices X checks whether a given set of vertices X in fact a lit clique b In the comments provide an answer what is the running time of your algo rithm in terms of n and lt7 and why does it imply that CLIQUE is in NP c Thoroughly test your code i In your le below the code for isClique provide at least two test graphs Try to make one graph to be typical and two to be in some way special awed or degenerate a graph without edges at all or with several connected components or only with V 1 edges or with edges between all vertices etc Each of the graphs should have at minimum seven vertices ii For each of the graphs provide a function call to isClique with that graph and the list of all vertices as input as well as a couple of subsets of the vertices iii Test your program on the friendship graph you created earlier 3 Takehome ideas summarytxt 2 points As we are nearing the end of Intro to Computer Science course it is the time to pause and ask yourself what have you learned What concepts that you encoun tered are applicable beyond this course How has your idea about computing and computer science changed Are you approaching or solving problems in a different way In short how did this journey changed the way you think and what are you bringing home from it For this exercise you re asked to re ect back on the entire course use all course materials your notes course schedule and formulate ten most important ideas or concepts or approaches that you learned in the course It s inevitable that some of content part of our coursework is forgotten If you could only pick 10 things to remember from the course what would those be For instance for me a big idea was abstraction and its application in separating of conceptual data structures such as Queue that you implemented in one of the labs and their different implementations such as more e icient linkedlist imple mentation of last hw or less e lcient Pythonlist implementation that we use in BPS Now when I approach a new problem I rst think about the operations that the solution program will have to perform then I can pick the most e icient way of implementing them not the other way around For your answer submit a numbered list of 10 items Each item should come as a formulation of an idea or concept or approach or a change in the way you solve problems Each item should have an example of how it could be helpful either in programming in languages other than Python or in solving problems in other subject areas or in one s everyday life Place each new item on a new line I plan to make the answers available for everyone to see after the deadline so please do a good job on this exercise Congratulations on completion of lab portion of CMPS 1500 Great job this semester
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'