Assignment 4: Vectors
We want to create a large, menu-driven vector manipulation program, where a vector is simply the mathematical term for an array. We want to include operations such as adding, subtracting, and multiplication of two vectors, finding the sum, product, and dot-product of a vector, and so on.
Since this is going to be a large project, we will do it in groups. Each group will get some well-defined tasks (i.e. functions) that they will have to solve. Then, all functions will be combined into the complete project via #include statements.
The functions we need to declare to handle vectors (or arrays) are grouped into several files, and are declared as follows. More details about these functions can be found at the end.
Group 1:Filename:
Functions:
|
Group 2:Filename:
Functions:
|
||||||||||||||||||||||||||
Group 3:Filename:
Functions:
|
Group 4:Filename:
Functions:
|
The way we will attack this large project is as follows: we will form teams of people, each team consisting of 3 people. Each team has to create all functions in group 2, group 3, and group 4. They have to test all functions and save the functions, exactly as defined, in the filenames for the groups, exactly as defined, on their kitten account. I will - actually, I already have - create the functions in group 1. You must follow the exact definition and spelling of the functions and of the file names !
I will also create a menu program that will use the functions you have defined for a complete program via appropriate #include statements, and "give" each group the appropriate files so that they can each have their own, complete program.
While you are testing your program, you can already use the functions defined in group 1 (which I did). You will, however, not get the complete menu program until the assignment is finished.
To use my functions for testing your own functions, you could proceed as follows:
You must be logged in to the MathSci account, using a floppy, if necessary, if your account is not on MathSci. Suppose you are working on the function "add", which is to add two arrays, or vectors, into a third one. Your code, while working on the function, would look as follows:
You can also work on your kitten account to develop the functions. Your code, while testing, would look exactly like above, with one difference:
Instead of
you would use the line
Once your function "add" is tested, you would move only the code for that
function into the file "vectalg.cpp" and proceed to test the next function. Once
that works, add that code to the file "vectalg.cpp". Keep doing this until all
functions necessary for group 1 are defined.
void add(double A[], double B[], double C[], int N);
A, B: two arrays of the same size | |
N: the size of all arrays |
output:
C: an array where each element is the sum of the corresponding elements of A and B |
void sub(double A[], double B[], double C[], int N);
A, B: two arrays of the same size | |
N: the size of all arrays |
output:
C: an array where each element is the difference of the corresponding elements of A and B |
void mult(double A[], double B[], double C[], int N);
A, B: two arrays of the same size | |
N: the size of all arrays |
output:
C: an array where each element is the product of the corresponding elements of A and B |
void reverse(double A[], double B[], int N);
A = the array to be reversed | |
N = the size of the array |
output:
B is the array A in reverse order |
void addNum(double A[], double c, double C[], int N);
A: an array of doubles | |
c: a double number | |
N: the size of all arrays |
output:
C: an array where each element is the sum of the corresponding element from A and the number c |
void subNum(double A[], double c, double C[], int N);
A: an array of doubles | |
c: a double number | |
N: the size of all arrays |
output:
C: an array where each element is the difference of the corresponding element from A and the number c. |
void multNum(double A[], double c, double C[], int N);
A: an array of doubles | |
c: a double number | |
N: the size of all arrays |
output:
C: an array where each element is the product of the corresponding element from A and the number c. |
void getVector(double A[], int N);
A: a declared, but undefined array | |
N: the size of the array |
output:
A: will contain values that the user has entered. |
void display(double A[], int N);
A: an array | |
N: the size of the array |
output:
None, but prints the values of the array on the screen. |
void wait(void);
none |
output:
None, but waits for the user to press the RETURN key |
void clearScreen(void);
none |
output:
None, but clears the screen by printing 25 empty lines |
double max(double A[], int N);
A: an array | |
N: the size of the array |
output:
returns the largest value of the array |
double min(double A[], int N);
A: an array | |
N: the size of the array |
output:
returns the smallest value of the array |
void swap(double A[], int pos1, int pos2);
A: an array | |
pos1, pos2: two integers between 0 and the size of the array |
output:
None, but the elements at pos1 and pos2 will have switched places with eachother. |
void sortInc(double A[], double C[], int N);
A: an array | |
N: the size of the array |
output:
C: will be the same as array A, but sorted in increasing order of magnitude |
void sortDec(double A[], double C[], int N);
A: an array | |
N: the size of the array |
output:
C: will be the same as array A, but sorted in decreasing order of magnitude |
double sum(double A[], int N);
A: an array | |
N: the size of the array |
output:
returns the sum of all elements in the array A |
double product(double A[], int N);
A: an array | |
N: the size of the array |
output:
returns the product of all elements in the array A |
double dot(double A[], double B[], int N);
A, B: two arrays of the same size | |
N: the size of the arrays |
output:
returns the dot product of the two arrays. The dot product is obtained by first multiplying the corresponding entries of A and B together, and then computing the sum of those products (see class notes for details). |