Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
int n = 2;
string s = "hard";
double x = 2.25;
int* A = new int[3];
string* B = new string[2];
double* X = new double[3];
A[0] = 6; A[1] = 9; A[2] = 8;
B[0] = "hi"; B[1] = "bye";
X[0] = 5.1; X[1] = 5.4; X[2] = 5.7;
double sqr(double z) { return z*z; }
bool isneg(int k) { return (k < 0); }
expression | type (or error!) | value (or error!) |
X | N/A | |
A | N/A | |
X[0] | ||
A[1] - x | ||
A[0] = X[n] | ||
++A[2] | ||
B[1][0] | ||
A[1] + X[1] | ||
sqr(A[0]) | ||
sqr(X[0]) | ||
isneg(X[0]) |
hw.cpp
that works like this:
v
and w
as input.
<v,w>
and
<w,v>
.
~/$ ./hw N = 3 X = [1.1, 2.2, 3.3] Y = [1, -1, 0.1] <X,Y> = 1.1 * 1 + 2.2 * (-1) + 3.3 * 0.1 = -0.77 <Y,X> = 1 * 1.1 + (-1) * 2.2 + 0.1 * 3.3 = -0.77 |
~/$ ./hw N = 1 A = [-1.2] B = [-4.3] <A,B> = (-1.2) * (-4.3) = 5.16 <B,A> = (-4.3) * (-1.2) = 5.16 |
Tip: We haven't learned how to pass arrays to functions yet, so don't try to use functions for this programming assignment to manipulate arrays -- just put everything in main(). However, if you see a use for functions that doesn't require an array, you can use it if you like.
Turn In the codeprint of your program.
Submit:
~/bin/submit -c=IC210 -p=hw19 hw.cpp