0% found this document useful (0 votes)
4 views3 pages

Lab 08

Uploaded by

furkankalkan3169
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Lab 08

Uploaded by

furkankalkan3169
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

CS 115 - Introduction to Programming in Python

Lab Guide 08

Lab Objectives: Recursion. Searching and Sorting.


1. Download the class, Course, that represents a university course. The class will store the following attributes:

 The class stores the following attributes: courseName, code, credits.

2. Update the class, Course to include the following:


 __eq__method: Two courses are equal if their codes are the same.
 __lt__ method: A Course is less than another if its code comes before the other alphabetically.

3. Create a script, CourseApp.py, that includes the following functions:


 load_courses(): takes a filename as a parameter and returns a list of Course objects contained in
the file. Each line in the file contains the data used to create a Course object separated by comma. The
list should not contain duplicate Courses.
 sort_courses_by_id(): takes a list of Courses as a parameter and sorts the Course objects by
their codes using the bubble sort algorithm.
 search_course_by_code(): takes a list of Courses and a course code as parameters and finds and
returns the Course object with the given code. (returns None if no matching Course found).
Use a recursive binary search algorithm with two parameters.

4. Create an application that does the following:


 Loads the Courses in the file, courses.txt, into a list and displays the list.
 Sorts the list of Courses by code and displays the sorted list.
 Inputs a code from the user and displays the Course with the given code. Display appropriate message
if no matching Course is found.

Sample Run1:

duplicate - course Algorithms and Programming 2 CS102 4 not added...


duplicate - course Computer Networks CS353 3 not added...
Original list of Courses:
[Course name: Introduction to Programming in Python Code: CS115 Credits: 4
, Course name: Algorithms and Programming 1 Code: CS101 Credits: 4
, Course name: Introduction to Computer Applications and Programming Code: CS121 Credits: 3
, Course name: Algorithms and Programming 2 Code: CS102 Credits: 4
, Course name: Computer Networks Code: CS421 Credits: 3
, Course name: Fundamental Structures of Computer Science II Code: CS202 Credits: 3
, Course name: Object-Oriented Software Engineering Code: CS319 Credits: 4
, Course name: Summer training Code: CS299 Credits: 0
, Course name: Introduction to Data Analysis for Social Sciences Code: CS125 Credits: 3
, Course name: Computer Networks Code: CS353 Credits: 3
, Course name: Programming Languages Code: CS315 Credits: 3
, Course name: Fundamental Structures of Computer Science I Code: CS201 Credits: 3
, Course name: Software Engineering Project Code: CS413 Credits: 3
]
Courses sorted by Code:
[Course name: Algorithms and Programming 1 Code: CS101 Credits: 4
, Course name: Algorithms and Programming 2 Code: CS102 Credits: 4
, Course name: Introduction to Programming in Python Code: CS115 Credits: 4
, Course name: Introduction to Computer Applications and Programming Code: CS121 Credits: 3
, Course name: Introduction to Data Analysis for Social Sciences Code: CS125 Credits: 3
, Course name: Fundamental Structures of Computer Science I Code: CS201 Credits: 3
, Course name: Fundamental Structures of Computer Science II Code: CS202 Credits: 3
, Course name: Summer training Code: CS299 Credits: 0
, Course name: Programming Languages Code: CS315 Credits: 3
, Course name: Object-Oriented Software Engineering Code: CS319 Credits: 4
, Course name: Computer Networks Code: CS353 Credits: 3
, Course name: Software Engineering Project Code: CS413 Credits: 3
, Course name: Computer Networks Code: CS421 Credits: 3
]

Enter course code to search: CS202


Course name: Fundamental Structures of Computer Science II Code: CS202 Credits: 3

Sample Run2:

duplicate - course Algorithms and Programming 2 CS102 4 not added...


duplicate - course Computer Networks CS353 3 not added...
Original list of Courses:
[Course name: Introduction to Programming in Python Code: CS115 Credits: 4
, Course name: Algorithms and Programming 1 Code: CS101 Credits: 4
, Course name: Introduction to Computer Applications and Programming Code: CS121 Credits: 3
, Course name: Algorithms and Programming 2 Code: CS102 Credits: 4
, Course name: Computer Networks Code: CS421 Credits: 3
, Course name: Fundamental Structures of Computer Science II Code: CS202 Credits: 3
, Course name: Object-Oriented Software Engineering Code: CS319 Credits: 4
, Course name: Summer training Code: CS299 Credits: 0
, Course name: Introduction to Data Analysis for Social Sciences Code: CS125 Credits: 3
, Course name: Computer Networks Code: CS353 Credits: 3
, Course name: Programming Languages Code: CS315 Credits: 3
, Course name: Fundamental Structures of Computer Science I Code: CS201 Credits: 3
, Course name: Software Engineering Project Code: CS413 Credits: 3
]
Courses sorted by Code:
[Course name: Algorithms and Programming 1 Code: CS101 Credits: 4
, Course name: Algorithms and Programming 2 Code: CS102 Credits: 4
, Course name: Introduction to Programming in Python Code: CS115 Credits: 4
, Course name: Introduction to Computer Applications and Programming Code: CS121 Credits: 3
, Course name: Introduction to Data Analysis for Social Sciences Code: CS125 Credits: 3
, Course name: Fundamental Structures of Computer Science I Code: CS201 Credits: 3
, Course name: Fundamental Structures of Computer Science II Code: CS202 Credits: 3
, Course name: Summer training Code: CS299 Credits: 0
, Course name: Programming Languages Code: CS315 Credits: 3
, Course name: Object-Oriented Software Engineering Code: CS319 Credits: 4
, Course name: Computer Networks Code: CS353 Credits: 3
, Course name: Software Engineering Project Code: CS413 Credits: 3
, Course name: Computer Networks Code: CS421 Credits: 3
]

Enter course code to search: CS481


No Course with the code CS481 exists!

You might also like