| Date Assigned: | Tue Oct-3 |
| Date Due: | Wed Oct-4 |
This assigment requires the use of apvector.cpp and apvector.h. Remember to place both of these files into the same directory as your main.cpp, but to only include apvector.h in your project.
Your task, should you choose to accept it: Write a program with the following I/O behavior:
Enter size of array (0 to exit): 5Some comments: You should create two apvectors of type <int> for this. On each iteration, use the resize() method to set the vector to the appropriate size. The element values must be random numbers between -128 and 128 inclusive (see below for details on random number generation). You should not print out more than 8 numbers per line -- if there are more than that, you should start a new line, and indent the numbers so that the first number displayed on each line is left-aligned with the first number in the array (that is, so element[0] and element[8] and element[16] and so on are all left-aligned). Next, the dot-product of two vectors is: the sum of the products of each pair of elements at the same index. That is, a[0]*b[0] + a[1] * b[1] + ...Random vector 1 = [2,19,22,-17,4]
Random vector 2 = [3,24,-102,22,73]Dot product = <whatever it is>
...
So, how do you create a random number generator? You can use the built-in function "rand()", which returns random numbers from 0 to MAX_RAND. To convert it to return 0 to max (inclusive), you might use the following function:
#include <math.h> // you must include this to use rand()It is left to you to understand why that works (study it), and to adapt it to return from -128 to +128, as the assignment requires.int rand(int max)
{
return int(rand() * ((max+1) * 1.0 / RAND_MAX));
}
Good luck, and may some force or another be with you.