You are on page 1of 2

ASSIGNMENT - 4 (PSCP LAB Sections A to F) Duration: Three weeks

1. Write an algorithm that calculates and prints the product of one large number (having
more than 10 digits) by a single digit number. Write C++ code for the algorithm.
2. Write a program to swap the position of largest and smallest elements in a given array.
3. Write a program to merge two sorted arrays in ascending order into a single array sorted
in descending order (use pointers to refer the elements of the array).
4. Write a program that reads a line of text and prints a table indicating the number of
occurrences of each word in the text.
5. Given a string, write a recursive function to count the number of vowels and convert the
consonants from uppercase to lowercase and vice-versa.
6. Consider an integer array a of size n+1 with a[0] and a[1] as 0 and rest all with 1.
Starting with index 2, identify the first element at index i, whose value is 1, make all a[j],
where j( > i) is a multiple of i, as 0, if it is already not 0. Continue the process till no more
element of the array a is convertible to 0. When the process terminates, the indices i of
the array a where a[i] is 1 are the prime numbers between 1 and n. Write a program to
simulate the above procedure to determine all the prime numbers between 1 and n.
7. Write a function to find the norm of a matrix. The norm is defined as the square root of
the sum of squares of all elements in the matrix.
8. Write a program that creates an array of 100 random integers in the range of 100 to 300,
and then using the binary search, searches the array 100 times using randomly generated
targets in the same range. Perform the linear search for the same. Display the number of
comparisons done using linear search and binary search for the above problem. Display
the percentage of successful searches for both the searching methods (Is it equal or
different?). Write two separate functions for linear search and binary search.
9. Consider a matrix A with m rows and n columns with non-repeating integers. The
elements in each row of the matrix A are sorted in ascending order and stored in the
respective row of another matrix B. Similarly the elements in each column of the matrix
A are sorted in ascending order and stored in the respective column of another matrix C.
Given the two matrices B and C, write a program to construct the matrix A. HINT:
Consider comparing the elements in row of B and columns of C. For example, consider
7 12 23
9
2
3
the two matrices B and C:
B= 2 3
C = 12 7
9
4
4 19 21
19 21 23
12 7 23
Your program should generate and print the matrix A = 9
2
3
19 21 4
10. Write a program to find the trace of a matrix and find the sum of all odd numbers in the
given matrix.
11. Write a program to shuffle the deck of cards using the following techniques (a) Single
card shuffling (b) Bunch card Shuffling (c) Scissoring.
12. Write a program to find the smallest number in a given array of elements using recursion.
13. Using pointers, write a function that receives a character string and a character as
argument and deletes all occurrence of this character in the string. The function should
return the corrected string with no holes. Write a complete program for this.
14. Given an input text file (plaintext.txt) and a key k (any value between 1 and 255), write a
program to replace each character c of given file by c', where c' = c XOR k, and write c'
in "encryptedtext.txt" file. Similarly, read the characters from "encryptedtext.txt" and
convert the characters to its original form (i.e., c' to c) and display it.
15. Write a program to determine the given string is palindrome or not and also write a
recursive function to find the length the given string.
16. Write a program to sort the given words and count the number of characters, words, lines
in a given input text.
17. Write the user defined functions for the library functions strncpy, strncat and strncmp.
18. Write a program to find the xy, where x and y are large integers.
19. A point on the 2-D plane can be represented by two numbers: an X-coordinate and YCoordinate. For example, (2, 3) represents a point 2 units to the right of the origin along
the x-axis and 3-units up the y-axis. The product of the two points can be defined as new
point whose x-coordinate is the product of the X-coordinate of the two points, and whose
y-coordinate is the product of their y-coordinates. Write a program that uses a structure
called point to model a point. Define three points, and have the user input values to two

of them. Then set the third point equal to the product of the other two, and display the
value of the new point.
20. Two files FILE1 and FILE2 contain sorted lists of integers. Write a program to produce a
third file DATA which holds a single sorted, merged list of these two lists.
21. Write a program that reads a text file and creates another file that is identical except that
every sequence of consecutive blank spaces is replaced by a single space.
22. Create a structure to specify data of customers in a bank. The data to be stored is:
Account number, Name, Balance in account. Assume maximum of 200 customers in the
bank. Write a function to print the Account number and name of each customer with
balance below Rs. 100. A customer requests for withdrawal or deposit, which is given in
the form: Acct. no, amount, code (1 for deposit, 0 for withdrawal). For withdrawal
operation minimum balance need to be checked.
23. Write a C++ program to implement a class called rational number containing four integer
fields (Sign, numerator, denominator, exponent (raised to the power of 10)). Provide
operations for addition, subtraction and multiplication using operator overloading. Keep
always the values in lowest terms (Example: 8/12, should be represented as 2/3). Write a
private function for conversion to lowest terms. Also provide input and output functions.
(Do not use floating point operations).
24. Create a base class called Vehicle that has manufacturers name , number of cylinders in
the engine and owner (type Person)). Then create a class called Truck that is derived
from Vehicle and has additional properties: the load capacity in tons and towing or
pulling capacity in pounds. Be sure your classes use constructor and destructor functions.
Write a program that creates at least two Vehicle objects and each Vehicle object is
having at least two Truck objects. The program should test all the member functions
defined in the respective classes. (Note: Define by yourself, the class Person and the
member functions)
25. Consider the four arrays of strings called article, noun, verb and preposition, where
article contains {"the", "a", "one", "some", "any"}, noun contains {"boy", "girl", "dog",
"town", "car"}, verb contains {"drove", "jumped", "ran", walked", "skipped"} and
preposition contains {"to", "from", "over", "under", "on"}. Write a program to create a
sentence by selecting a word at random (using random number generator function
(between 0 and 4)) from each array in the following order: article, noun, verb,
preposition, article and noun. As each word is picked, concatenate it to the previous
words in the sentence. The words should be separated by spaces.

You might also like