Programming in C++ assignment

jpFlute

Writing and Calling Functions

Part A 

True or False? 

  1. A function has exactly one return statement.
  2. A function has at least one return statement. 
  3. A function has at most once return value.
  4. A procedure (with return value void) never has a return statement. 
  5. When executing a return statement, the functions exists immediately. 
  6. A function without parameters always has sideeffects. 
  7. A procedure (with a return value void) always has a side effect. 
  8. A function without side effects always returns the same value when called with the same parameter values. 
Part B

Consider these functions: 

  • Double F(double x) { return g(x) + sqrt(h(x)); } 
  • Double G(double x) { return 4 * h(x); }
  • Double H(double x) { return x * x + k(x) – 1; }
  • Double K(double x) { return2 * (x + 1); }

Without actually compiling and running a program, determine the results of the following function calls: 

  1. Double x1 = F(2);
  2. Double x2 = G(H(2));
  3. Double x3 = K(G(2) + H(2));
  4. Double x4 = F(0) + F(1) + F(2);
  5. Double x5 = F(-1) + G(-1) + H(-1) + K(-1);
Part C

Write a procedure sort3(int& a, int& b, int& c) that swaps its three inputs to arrange them in sorted order.

For example: 

int v = 3;

int w = 4;

int x = 1;

sort3(v, w, x); //V is now 1, w is not 3, x is now 4

Submit a screenshot of the executed program and the code of the program.

    • 10 years ago
    • 20
    Answer(1)

    Purchase the answer to view it

    NOT RATED
    • assignment_c.docx