Practice Final Exam - Electrical Engineering Computations | ECE 206, Exams of Electrical and Electronics Engineering

Material Type: Exam; Class: Electrical Engr Computations; Subject: Electrical And Computer Engr; University: University of Tennessee - Knoxville; Term: Unknown 1989;

Typology: Exams

Pre 2010

Uploaded on 08/26/2009

koofers-user-4ze
koofers-user-4ze ๐Ÿ‡บ๐Ÿ‡ธ

10 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 102 / ECE 206 โ€” Section 04 โ€” Spring โ€˜09
Practice Final Exam
Name:
Instructions:
1. Spread out! There should be at least one seat between you and any of your neighbors.
2. Write clearly; if we cannot read your answer, it will be counted as incorrect.
3. Be complete and concise. Circle your answers if there might be any question as to what you
want considered for grading.
4. Coding questions require only a code segment unless otherwise stated.
5. Coding questions will be graded on efficiency and style, as well as correctness.
6. NO CALCULATORS, NO CELL PHONES, NO HEADPHONES! Having a cell phone during
the exam will result in a grade of zero for the exam. Please keep all electronics turned off and
put away during the exam.
-page 1 of 17-
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Practice Final Exam - Electrical Engineering Computations | ECE 206 and more Exams Electrical and Electronics Engineering in PDF only on Docsity!

CS 102 / ECE 206 โ€” Section 04 โ€” Spring โ€˜

Practice Final Exam

Name:

Instructions:

  1. Spread out! There should be at least one seat between you and any of your neighbors.
  2. Write clearly; if we cannot read your answer, it will be counted as incorrect.
  3. Be complete and concise. Circle your answers if there might be any question as to what you want considered for grading.
  4. Coding questions require only a code segment unless otherwise stated.
  5. Coding questions will be graded on efficiency and style, as well as correctness.
  6. NO CALCULATORS, NO CELL PHONES, NO HEADPHONES! Having a cell phone during the exam will result in a grade of zero for the exam. Please keep all electronics turned off and put away during the exam.

Who can see member variables and functions that are declared: (a) private (b) protected (c) public

2. (4 points) What is the effect of the following statements? int x = 1/2; assert (x > 0); 3. (4 points) You have the following code fragment. What is printed with the indicated input values? cin >> x; switch(x) { case 20: x *= 4; break; case 40: x--; x--; break; case 60: x = -5; case 80: if(x != 0) x = 100; break; default: x++; } cout << x << endl; a) input: 20 _________ b) input: 60 _________

// prototypes for constructors Circle(); Circle(double r); private: double radius; // radius of circle in feet }; #include #include "Circle.h" using namespace std; int main() { Circle circle_1; // invokes the default constructor Circle circle_2 (5.123); // invokes constructor with an arg. // code for main() would be here } // a. *** Implement default constructor that sets radius to 0 / b. *** Implement constructor that sets radius to the argument if the argument is >= to 0, and sets it to 0 otherwise./**

Explain what is wrong with the following code segment? int* X = new int; *X = 1; delete X; *X = 0;

7. (4 points) Complete function read_it() to read values into integer vector v. Stop when either the vector is full or you reach eof. You may assume valid data. vector read_it(vector & v) { }

Study the recursive function below. For each of the function calls listed, state what gets printed and tell how many times recur() is invoked, counting the original call. int recur(int x, int y) { if(y == 0) return x; else if(y >= 0) return recur(x + 1, y โ€“ 1); else return recur(x - 1, y + 1); } a. cout << recur(5, 0) << endl; times called: output: b. cout << recur(5, -1) << endl; times called: output: c. cout << recur(5, 1) << endl; times called: output:

What is the output from the following code segment? int x = 628; cout << x / 10 % 10 << x % 10 << x / 100 << endl;

12. (4 points) What is printed from the code segment below? enum Color_Type {green, red, blue, black, clear}; Color_Type pen, pencil; pen = clear; // invisible ink pencil = red; if(pen <= black) cout << "stupid spy" << endl; else cout << "spot on" << endl; if(pencil >= 2) cout << "good choice" << endl; else cout << "not so much" << endl;

Complete the following function, which sorts the vector V in ascending order. Your sorting algorithm does not have to be efficient. Make sure to declare any variables that you need. Hint : Write an outer loop, with i = 0 to V.size(), and on each iteration use findLowest to find the index of the smallest number from i to the end of the vector. Swap them so that at the end of each iteration the first i elements of V are sorted. int function findLowest (const vector& V, int start) { //start looking at index start } void function sort (vector& V) { }

What does the word virtual mean in front of a function declaration?

16. (4 points) What (not how) does the following code do? Hint: Trace with input 123. int x, y; for(y = 0, cin >> x; // expr x != 0; // expr y = x % 10 + y * 10, x /= 10); // expr3, null body cout << endl << y << endl; 17. (4 points) Given the following structure definitions, write an output command to print the rank of the 27th^ card in deck. struct Card { int suit, rank; }; struct Deck { vector cards (52); }; Deck deck;

Define a subclass of employee (see question # 19 ) called manager that has an additional public member variable, subordinates, which a vector of pointers to employee records.

21. (4 points) Why are private member variables and member functions important for program maintenance? 22. (4 points) Complete the following definition of a member function add(), which adds two complex numbers. That is, X.add(Y) should return the sum of the complex numbers X and Y. (Recall that the real part of the sum is the sum of the real parts, and the imaginary part of the sum is the sum of the imaginary parts.) class complex { public: double real, imag; complex add (complex Y) { complex sum; return sum; } // end of add };

Write a definition to overload the "+" operator to add two complex numbers and return their sum. (You may assume that you have the add function that you defined in question # 22. Treat the operator as a standalone function.)

24. (4 points) What do you use the "::" operator for? 25. (4 points) Define an enumeration type Month for (abbreviated) names of the months (JAN, FEB, etc.), but define it in such a way that JAN has the numerical value 1.

Carefully study the nested loops. What is displayed? a. x = y = 0; for(i = 200; i > 100; i--) { x++; for(j = 30; j < 30; j++) y++; } printf("Result: %d %d %d %d\n", i, j, x, y); b. x = y = j = 0; // reset variables to 0 for(i = 30; i < 30; i++) { x++; for(j = 200; j > 100; j--) y++; } printf("Result: %d %d %d %d\n", i, j, x, y);

29. (4 points) What does inheritance refer to in the context of object-oriented programming?

What is displayed by the code segment below if the input is 1234? Be careful! int i, power, n, x; i = x = 0; power = 1; cin >> n; // assume a non-negative value for n while (n > 0) { x += n % 10 * power; power *= 10; n /= 10; } cout << x << endl;

Note: The actual Final Exam will be a little shorter than this practice exam.

A further note: Make sure you understand your mistakes on Exams I and II and what the

correct answers should be!