Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [20pts] Assume the following delcarations and function definitions fill in the table. Note: "error" is a possiblity! Note: each question is independent, i.e. no side effects of one expression shoudl be taken to carry over to the next.
    Tip: If necessary, write a code and test it!

    
    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); }
    

    expressiontype (or error!)value (or error!)
    XN/A
    AN/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])
    1. [80pts] Write a program with source file named hw.cpp that works like this:
      • The program takes two vectors v and w as input.
      • It outputs the dot products <v,w> and <w,v>.
      • As shown in the sample runs below, your program should print out how the dot products are computed.

      ~/$ ./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