A1 Oop
A1 Oop
A1 Oop
Assignment Number 1
CL-1004 Object Oriented Programming
Fall 2024
Instructions:
You need to write a function that reverses the content of the array. It should receive the following
arguments
You need to use two pointer method, where one pointer points to start of the array while the other
pointer points to end of the array. And they move towards each other after each swap
• if the array is NULL then throw runtime error “Cannot reverse a null array.”
• if the size of array is zero then throw runtime error “Cannot reverse an empty array.”
• if the type of array is other than char/int/bool then throw runtime error “Cannot reverse
array of any type other than char/int/bool”
You are given a square matrix of size N x N. Write a C++ function to transpose the matrix in place.
2
The transposition of a matrix involves swapping its rows and columns. For example, the transpose
of the matrix:
Copy code
1 2 3
4 5 6
7 8 9
is:
Copy code
1 4 7
2 5 8
3 6 9
Constraints:
Your implementation should correctly transpose the given matrix without using any additional
memory (i.e., no extra matrix). Ensure that your solution works efficiently for large matrices.
You are given a sentence as a null-terminated C-style string (char array). Write a C++ function to
capitalize the first letter of each word in the sentence.
For example, given the string "hello world", the function should modify it to become "Hello
World".
Constraints:
Your implementation should correctly capitalize the first letter of each word in the given sentence
without using any additional memory. Ensure that your solution works efficiently for sentences of
varying lengths and word counts.
Write a C++ program to develop a system to manage music playlists where each playlist can
contain a different number of songs, each song is stored dynamically.
Allow users to create, modify, and delete playlists and songs dynamically.
Sample input
Enter a decimal number: 63
Sample output
Binary: 111111
Octal: 77
Hexadecimal: 3F
Create a C++ program that performs matrix addition, subtraction and multiplication
using 2D pointers. Users should input two matrices, and the program should dynamically
allocate memory to store the matrices, perform the chosen operation, and display the result.
Sample Input:
4
12
34
Enter the number of rows and columns for Matrix B: 2 2
Enter elements for Matrix B:
56
78
Enter 1 for addition or 2 for multiplication: 1
Sample Output
Matrix Addition Result:
68
10 12
Q8: Momentum
Momentum is defined as the product of an item’s mass and its velocity. Mass is a scalar value,
whereas velocity is generally expressed as a vector quantity with three components. The product
of the scalar mass and the velocity yields momentum as a vector quantity.
and return a dynamically allocated array representing the momentum. Note the momentum is
determined by multiplying the scalar mass by each element of the vector array.
5
Test your momentum function by constructing a short main program that will ask the user to input
values for the velocity and mass from the console, and then display the momentum.
Write a program to determine the average momentum of a collection of items with random
velocities and masses. Do this using the following outline:
1. Construct a function named randVec that will take no arguments and return a dynamically
allocated 3-element array of doubles. Each element in the array should be a randomly generated
value in the range -100.0 through +100.0.
2. Using randVec and your momentum function from the previous part, generate momentum
vectors for 100 items, each of which has a random velocity (as described above) and a randomly
generated mass in the range 1.0 through 10.0. Save the momentum vectors using a suitable array
of pointers.
3. Determine and display the average momentum vector of the items using a for loop.
[Hint: the average should be done component by component.]
Write a function that will take a string and return a count of each letter in the string. For example,
"my dog ate my homework" contains 3 m's, 3 o's, 2 e's, 2 y's and one each of d, g, a, t, h, w, r and
k.
Your function should take a single string argument and return a dynamically allocated array of 26
integers representing the count of each of the letters a ….. z respectively. Your function should be
case insensitive, i.e., count 'A' and 'a' as the occurrence of the letter a. [Hint: use the letter to integer
conversion functions.] Do not count non-letter characters (i.e., spaces, punctuation, digits, etc.)
Write a main function that will solicit a string from the user using getline, call your letter frequency
function and print out the frequency of each letter in the string. Do not list letters that do not occur
at least once.
Example:
Enter a string: my dog ate my homework
Letter frequency
a1
d1
e2
6
g1
h1
k1
m3
o3
r1
t1
w1
y2