1CSE4IP&CSE5CES(BU-1)INTRODUCTION TO PROGRAMMINGPROGRAMMING FOR ENGINEERS AND SCIENTISTSSemester 1, 2021Assignment 2Delays caused by computer downtime cannot be accepted as a valid reason for alate submission without penalty. Students must plan their work to allow for bothscheduled and unscheduled downtime.Penalties are applied to late assignments (accepted up to 5 working days after thedue date only). See the university policy for details.Individual Assignment: This is an individual assignment. You are not permitted towork as a group when writing this assignment.Copying, Plagiarism: Plagiarism is the submission of somebody else’s work in amanner that gives the impression that the work is your own. The Department ofComputer Science and Information Technology treats academic misconductseriously. When it is detected, penalties are strictly imposed. Refer to the unit guidefor further information and strategies you can use to avoid a charge of academicmisconduct. All submissions will be electronically checked for plagiarism.Objectives: The general aims of this assignment are:• To practise using concepts and techniques covered in the lectures and relatedlabs.• To apply those concepts and techniques for practical problem solving,i.e. to design and implement programming solutionsHow to submit your assignment1. The answer for Question 1 must be put in text file A2Q1.py. In this file, youwrite at the top of the answer: (i) Your student ID, (ii) Your first name, and(iii) Your last name, in that order. Do this for all other questions.2. Put all your answers in a zip file, with the .zip extension. The name of the zipfile should be CSE4IP-20001111 if your student Id is 20001111, for example.3. Upload the zip file using Assignment 2 Submission set up on the subject’sLMS.2Question 1– Translating Text Messages [10 marks]Instant messaging (IM) and texting on portable devices has resulted in a set ofcommon abbreviations useful for brief messages. However, some individuals maynot understand these abbreviations.Write a program that reads a one-line text message containing commonabbreviations and translates the message into English using a set of translationsstored in a file. For example, if the user enters the text message:y r u l8the program should print whyare you lateAs a simplification, you can assume that are no punctuation marks.Proceed as follows:a. Build a dictionary with abbreviations as keys and associated texts as values.Read the provided text file abbreviations.txt, each line of which contains anabbreviation and the associated text it.(You should display the list lines to see what a string of this list looks like.)Complete the code to build a dictionary with abbreviations as keys and theassociated texts as value.b. Translate a message.Split the message into “words”. If a “word” is in the dictionary, replace it by theassociated text. Otherwise simply copy the “word” to the translation.Question 2– Merge Big Files [10 marks]Suppose we have two very big text files, so big that we cannot read them into thecomputer’s memory. The files are already sorted.Now, we want to merge them. How can we do this?We can use the following approach. Imagine that the names are on two piles ofcards.• We look at the cards on top of the two piles.• We then pick out the smaller one to add to the merged pile. If the two topcards have the same name, we add one card to the merged pile and discardthe other one.3• We repeat this until one pile is exhausted. We simply add all the cards of theother pile, if any, to the merged pile.Write a program to implement the above approach. For demonstration purpose,you can take names set1.txt and names set2.txt as the two input files.Call the output file names merged big.txt.Note: The merge problem we consider here is part of the algorithmknown as external merge sort, which is used to sort very big files,without reading the whole files into computer memory.Question 3 – Pattern [10 marks]Write a program in python to print the following pattern. You need to enterthe number of rows from a user using input() function.Question 4– Date and Calendar [30 marks]a. Define a function called isLeapYear that takes a year as an integerand returns True if it is a leap year and False otherwise. A year,between 1800 and 20000, is a leap year if• It is divisible by 4 but not by 100 or• It is divisible by 400For this function, you can assume that the year is between 1800 and20000. You do not need to check it.b. Define a function called daysInMonth that takes a month of a yearand returns the number of days for that month. The function takes an4integer for the month (1 for January, 2 for February, etc.) and a year(an integer between 1800 and 20000).For this function, you can assume that the month is between 1 and 12and the year is between 1800 and 20000. You do not need to checkthem.c. Define a function called isValidDate that takes three integers for aday, a month and a year (in that order) and returns True if the theeintegers represent a valid date and False otherwise.Among other things, this function must check that the day is between1 and 31, the month is between 1 and 12, and the year is between 1800and 20000. The function must return False if any of these conditionsis not satisfied.d. Let day, month and year be the day, the month and the year of a date.The day of the week this date falls in can be determined by thefollowing method of calculation (given by the famous mathematicianCarl Friedrich Gauss):x = year – (14 – month)/12y = x + x/4 – x/100 + x/400z = month + 12 * ((14 – month) /12) -2dow = (day + y + (31 * z)/12) % 7where the division is integer division (in which the fractional part isdiscarded), and dow represents the day of the week, with Sundaybeing 0, Monday being 1, etc. Write a function called dayOfWeekthat takes the day, month and year of a date and returns a number torepresent the day of the week for that date, with 0 for Monday, 1 forTuesday and so on (Note the slight difference from the outcome ofGauss’s algorithm). If the numbers do not represent a valid date thefunction should return None.5e. Write a function called printCalendar that takes two integers torepresent a particular month in a particular year and prints out thecalendar for that month. For this function, you can assume that themonth is between 1 and 12 and the year is between 1800 and 20000.f. Add statements to your program to ask the user for a birth date of aperson (day, month and year). If the birth date is not valid, print themessageThe given date is invalid.Otherwise, display• On which day of the week the person was born, e.g.The person was born on a MondayAnd• The calendar of the month of the birthday in 2020. Make surethat the columns (of the days of the week and the days) line upnicely.Q: Should I submit more than one program for this question?A: No, please put all the functions and the statements required for the last taskin a program.Q: What about test cases?A: You are not required to do this. But it may be a good idea to include thetesting code. But make sure you comment the code for testing out.Question 5 – Reading Bus Route Data [40 marks]In this question, you will work with a text file that contains information about thebus route that goes from the Bundoora campus of La Trobe University to the Cityof Melbourne.6The data (which is route 250) is stored in the text file BusRoute250.txt. It lists allthe bus stops on the route, 67 of them actually. Details about a stop is stored onone line. The first 5 lines and the last 5 lines are shown below:1/La Trobe Uni Terminus/Science Dr/Bundoora2/La Trobe Uni Thomas Cherry Building/Science Dr/Bundoora3/Kingsbury Dr/Waterdale Rd/Bundoora4/Crissane Rd/Waterdale Rd/Heidelberg West5/Percy St/Waterdale Rd/Heidelberg West …63/Exhibition St/Lonsdale St/Melbourne City64/Melbourne Central/Lonsdale St/Melbourne City65/Elizabeth St/Lonsdale St/Melbourne City66/Little Bourke St/Queen St/Melbourne City67/Little Collins St/Queen St/Melbourne CityEach line has four fields, separated by slash characters:• The first is the stop number (an integer), counting from the La Trobe Universityend.• The second is the stop’s name. You may be interested in how bus stops arenamed. In general, the name of a bus stop can be– Either the name of a nearby street that cuts across the route (which will bereferred to as the “cross-street”), e.g. Kingsbury Dr– Or the name of a place of interest near the stop (which will be referred toas the “cross-site”), e.g. La Trobe Uni Thomas Cherry Building• The third is the street along the route on which the stop lies, e.g. Science Dr forstop number 1.• The fourth field is the name of the suburb of the stop. It is enclosed between apair of brackets, e.g. Bundoora.A- Write a program to read the file and display the details about the bus stops. Thedetails of a bus stop are displayed on four lines, showing the bus stop number, thename, the street, and the suburb. [10 marks]For example:1La Trobe Uni TerminusScience DrBundoora …7B- In this question, you write a number of functions to load the data into a list ofbus stops and make various queries about the bus stops on the route. [30marks]Complete the program shown below:loadData()Please see descriptions of the functions on the next page.This function reads the data file BusRoute250.txt, creates the BusStop instancesand put them in busStopList.listAllBusStopNames()This function lists all the names of the bus stops. They have to be listed in orderstarting from La Trobe University. Part of the output is shown below:La Trobe Uni TerminusLa Trobe Uni Thomas Cherry Buildingdef loadData():passdef listAllBusStopNames(): passdef listAllStreetsOnRoute(): passdef listAllSuburbsOnRoute():passdef searchByNumber(start: “int, value: a stop number”, end: “int,value: a stop number >= start”):passdef searchByName(nameKey): passdef searchByStreet(streetKey): passdef searchBySuburb(suburbKey): passdef searchByAnyField(key):pass#== Tests ==# Add tests to test each of the functions8Kingsbury DrCrissane RdPercy St …Exhibition BuildingExhibition StMelbourne CentralElizabeth StLittle Bourke StLittle Collins StlistAllStreetsOnRoute()This function lists all the streets along the route. The streets along the routecorrespond to the third field of the lines of the input data file. They have to be listedin order starting from La Trobe University. Part of the output is shown below:Science DrWaterdale RdDougharty RdOriel RdLivingstone St …Bennett StHolden StBrunswick RdRathdowne StLonsdale St QueenStlistAllSuburbsOnRoute()This function lists all the suburbs along the route. The streets along the routecorrespond to the the fourth field of the lines of the input data file. They have tobe listed in order starting from La Trobe University. Part of the output is shownbelow:BundooraHeidelberg WestBellfieldIvanhoe …Brunswick EastCarlton NorthCarltonMelbourne CitysearchByNumber(start, end)The function lists all the stops in this requested range. For example, if start is 5 andend is 10, the output should look like this:Stop:5/Percy St/Waterdale Rd /Heidelberg WestStop:6/Waterdale Rd/Dougharty Rd /Heidelberg West9Stop:7/Kolora Rd/Dougharty Rd /Heidelberg WestStop:8/Ramu Pde/Oriel Rd /Heidelberg WestStop:9/Outhwaite Rd/Oriel Rd /Heidelberg West Stop:10/MorobeSt/Oriel Rd /Heidelberg WestsearchByName(nameKey)This function lists all the bus stops whose names contain the search string nameKeyas a substring. The matching ignores the difference between upper and lowercases. The matching bus stops are to be listed in the order starting from La TrobeUniversity. A sample run is shown below for ]cd nameKey being de :Stop:8/Ramu Pde/Oriel Rd /Heidelberg WestStop:12/Malahang Pde/Oriel Rd /Heidelberg WestStop:37/Dennis Railway Station/Victoria Rd /NorthcoteStop:61/Carlton Gardens/Rathdowne St /CarltonNote: If the search returns no bus stops, display message “There are no matches!”.searchByStreet(streetKey)Similar to the previous function, but the search is on the street along the route.searchBySuburb(suburbKey)Similar to the previous function, but the search is on the suburb along the route.searchByAnyField(key)This function lists all the bus stops whose name or street or suburb contains thesearch string key. Again, case differences are ignored, and the bus stops must belisted in the order starting from La Trobe University. A sample run is shown belowfor key being gar:Stop:38/Westgarth St/Victoria Rd /NorthcoteStop:39/Simpson St/Westgarth St /NorthcoteStop:40/Northcote Park/Westgarth St /NorthcoteStop:41/Westgarth Railway Station/Westgarth St /NorthcoteStop:42/High St/Westgarth St /NorthcoteStop:61/Carlton Gardens/Rathdowne St /Carlton
