- Home
- CSC/BIF 243
- CSC/BIF 243 Introduction to Object Oriented Programming Lab 10

$40.00

Category: CSC/BIF 243

Description

5/5 - (3 votes)

**Problem 1:**

Implement a variation of the Selection and of the Insertion sort function in such a way to display the list before being sorted and to display the content of the list at each iteration.

Write a program that:

- Reads from Keyboard numbers and stores them in a List1
- Makes a copy of List1 and call List2.
- Calls Selection sort on List1 and Calls insertion Sort on List2

** **

**Problem 2: **

Write a function to sort a list of points based on their y-coordinates. Each point is a list of two values for x- and y-coordinates.

# Returns a new list of points sorted on the y-coordinates

**def **sortPoints(points):

For example, the points [[**4**, **2**], [**1**, **7**], [**4**, **5**], [**1**, **2**], [**1**, **1**], [**4**, **1**]] will be sorted to [[**1**, **1**], [**4**, **1**], [**1**, **2**], [**4**, **2**], [**4**, **5**], [**1**, **7**]].

Write a test program that displays the sorted result for points [[**4**, **34**], [**1**, **7.5**], [**4**, **8.5**], [**1**, **-4.5**], [**1**, **4.5**], [**4**, **6.6**]] using **print(list)**.

Sample Input:

[[4,34], [1,7.5], [4,8.5], [1, -4.5], [1,4.5], [4,6.6]]

Sample Output:

[[1, -4.5], [1, 4.5], [4, 6.6], [1, 7.5], [4, 8.5], [4, 34]]

** **

** **

**Problem 3: **

- Given a square matrix n*n (rows=columns), the problem is to sort the given matrix by row. The matrix is sorted by row if:

- All elements in a row are sorted in increasing order
- and for row ‘i’, where 1 <= i <= n-1, first element of row ‘i’ is greater than or equal to the last element of row ‘i-1’.

**HINT: To solve this problem, you may use the built-in sort function on a single list.**

** **

Sample Input:

3

9 5 1

8 2 6

4 7 3

Sample Output: (After Sorting)

1 2 3

4 5 6

7 8 9

- Now adapt your code of part a) to give another program that does the sort by column.

Sample Input:

3

9 5 1

8 2 6

4 7 3

Sample Output: (After Sorting)

1 4 7

2 5 8

3 6 9

** **

** **

**Problem 4:**

Write a function that generate a List of random numbers. Your function should take 3 arguments and return a List:

*def genList( Len, Low, Upp):*

* # Len for length of the list, *

* #Low for the lower bound , Upp for the upper bound of the numbers*

Write a program that includes the an implementation of the *genList* , linearSearch and binarySearch Functions.

Your program should:

- Generate a list of random numbers. (Use a very large value for Len)
- Prompt the user to enter a Value. (This should be done for several values)
- Search for the entered value using both search functions measuring the time it takes for each function.
- Output the results.

** **

**Recall:**

**Problem 5: **

Write a program that repeatedly prompts the user to enter a capital for a state. Upon receiving the user input, the program reports whether the answer is correct. Assume that 50 states and their capitals are stored in a two-dimensional list, as shown below. The program prompts the user to answer all the states’ capitals and displays the total correct count. The user’s answer is not case sensitive. Implement the program using a list to represent the data in the following table.

Alabama Montgomery

Alaska Juneau

Arizona Phoenix

… …

… …

Use this link to know the names of the US states along with their capitals.

https://www.memory-improvement-tips.com/list-of-states-capitals.html

**Here is a sample run:**

What is the capital of Alabama? Montogomery

The correct answer should be Montgomery

What is the capital of Alaska? Juneau

Your answer is correct

What is the capital of Arizona? …

…

The correct count is 35

__ __

__ __

__Attention!__

**Policy on Cheating and Plagiarism: **

**Plagiarism on assignments and project work is a serious offense. If plagiarism is detected, a student will be subject to penalty, which ranges from receiving a zero on the assignment concerned to an “F” in the course.**

** **

WhatsApp us