DSA II Lab - SPL Review
DSA II Lab - SPL Review
Review For-Loop:
1. Write a program that will take N numbers as inputs and compute their average.
(Restriction: Without using any array)
Sample input
N Sample output
numbers
7
39.57
4 256 2 4 3 3 5
2. Write a program that will run and show keyboard inputs until the user types an ’A’ at
the keyboard.
4. Write a program that prints the number of occurrences of each unique elements of an
array.
Sample input Sample output
4 occurs 2 times
256 occurs 1 times
4 256 2 4 3 3 5 2 occurs 1 times
3 occurs 2 times
5 occurs 1 times
Review Function: 2
Review Function:
5.
Write a code for the following scenario:
Input: number1 and number2
Output: print all the factorials of numbers within [number1, number2]
The code should contain
(i) A function calc_factorial that returns the factorial of a given number
(ii) A main method to that takes inputs number1 and number2 from user and uses
the function calc_factorial to find all the numbers
6.
Write a code that will take n integer numbers into an array, and then reverse all the integers
within that array. Finally print them all from 0 index to last valid index.
The code should contain
(i) A function reverse_array that takes as input an array and reverses the array
inside the function
(ii) A function print_array that takes as input an array and prints it
(iii) A main method that uses the functions reverse_array and print_array to
produce the output
Review String:
7.
Write a code for the following scenario:
Input: A sentence
Output: converts the sentence into lowercase and removes all whitespace
The code should contain
(i) A function conv_to_lower that takes a string and returns a lowercase string
(ii) A function remove_ws that takes a string and removes the whitespaces
(iii) A main method that takes the input from user and uses the functions remove_ws
and conv_to_lower to get the desired output
8.
Write a Program that will take as input a string, and toggle cases of all the letters.
Sample input Sample output
SPL Laboratory spl lABORATORY
United International University uNITED iNTERNATIONAL uNIVERSITY
Review Structure: 4
Review Structure:
9.
Write a program to take as input the name, height in cm and age of n employees, and
sorts it according to height in descending order. If two employees have the same height then
sorts according to age in descending order. Print the employees in the sorted order.
10. Write a program to take as input an array of N names, an array of N ids and an array
of N salaries where the name, id, and salary of the 𝑖 th index belongs to the same
person. Store them in a structure and sort them according to salaries (ascending) and
then by ids (ascending). Print the person in the sorted order.