Professional Documents
Culture Documents
Week 12 Lab Exercises PDF
Week 12 Lab Exercises PDF
Exercise 1:
Write a C++ program which allows the user to manipulate two vectors (arrays) A and B of real numbers with the
following menu options:
1. Add A and B into a new vector C (i.e. C=A+B) and display the vector C
Q. Quit
The program must first allow the user to enter the size of the vectors (n) from the keyboard, generate the elements
of the 1st vector (say A) randomly and finally read the elements of the 2nd vector (say B) from an input file. Once
the above preparation has been done, the program should keep displaying the menu options and perform the
corresponding task of each option until the user selects the option Q (i.e. Quit).
Note:
a. Assume that the maximum vector size is 20 (but can be smaller)
b. Implement and test the menu options one at a time
c. You may or may not use functions to perform each menu option
Exercise 2:
Modify the above program to add and implement the following menu option:
3. Perform the Dot Product of A and B. The dot product (i.e. A.B) can be calculated using the following
formula:
1. Write a C++ program which uses two functions each is accepting a string of any length and perform the
following tasks:
a. The first function convert the string’s character to UPPER cases. The function has the following
prototype: string upper(string tname)
b. The second function convert the string’s character to LOWER cases.
(Hint: Use the C++ built-in functions toupper() and tolower() to convert each character of the string)