CMPE 261: Large Scale Programming
Problem Solving 8
Anıl Demirel
December 9, 2024
Instructions
This worksheet contains 8 problems covering topics discussed in Week 10 of
CMPE 261. You are encouraged to solve these problems independently. Use
Python, Java, or C++ as specified in each problem. Submit your solutions
as a single compressed folder containing the source code for each problem.
Problem 1: Memory Management Compari-
son
Write a program to compare memory management in Python, Java, and
C++:
• Allocate memory dynamically for a list (or array) of integers of size 10.
• Initialize the list with values from 1 to 10.
• Print the contents of the list and free the memory (where applicable).
Languages Required: Python, Java, and C++
Sample Output (Python):
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Problem 2: String Concatenation Performance
Write a program to measure the time taken to concatenate strings in a loop:
1
• Concatenate 100,000 strings using a naive approach.
• Optimize the code using efficient methods (StringBuilder in Java,
std::stringstream in C++, and join in Python).
Languages Required: Python, Java, and C++
Output: Report execution time for both naive and optimized approaches.
Problem 3: Cross-Platform Independence
Demonstrate platform independence by writing a simple calculator program
that:
• Accepts two numbers and an operator (+, -, *, /) as input.
• Outputs the result of the operation.
Languages Required: Python, Java, and C++
Input Example:
Enter first number: 10
Enter operator (+, -, *, /): *
Enter second number: 5
Output Example:
Result: 50
Problem 4: Matrix Multiplication (Large Data
Processing)
Implement a program that performs matrix multiplication for two 100x100
matrices filled with random values. Compare execution times in Python,
Java, and C++.
Instructions:
• Generate two matrices of size 100x100 with random values.
• Multiply the matrices and display the execution time.
Output: Report the execution time for each language.
2
Problem 5: Error Handling
Write a program that demonstrates error handling:
• Ask the user to input a number.
• Divide 100 by the input number.
• Handle division by zero or invalid inputs gracefully.
Languages Required: Python, Java, and C++
Sample Output:
Enter a number: 0
Error: Division by zero is not allowed.
Problem 6: Threading and Concurrency
Write a program to demonstrate threading and concurrency:
• Create 3 threads/tasks, each printing numbers from 1 to 10.
• Ensure threads run concurrently.
Languages Required: Python, Java, and C++
Output Example:
Thread 1: 1 2 3 4 5 6 7 8 9 10
Thread 2: 1 2 3 4 5 6 7 8 9 10
Thread 3: 1 2 3 4 5 6 7 8 9 10
Problem 7: Data Analysis
Write a Python program to analyze COVID-19 data:
• Use pandas to load and filter data from a CSV file.
• Calculate and display the top 5 countries with the highest cases per
million.
• Plot a bar chart showing these values.
Required Library: pandas, matplotlib
Output: A bar chart and the top 5 countries with their case counts.
3
Problem 8: OOP Features Comparison
Write a program demonstrating polymorphism:
• Create a base class Shape with a method getArea().
• Derive two classes Rectangle and Circle.
• Calculate and display the area for objects of both derived classes.
Languages Required: Python, Java, and C++
Sample Output:
Rectangle Area: 20
Circle Area: 28.27