









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: Electrical Engr Computations; Subject: Electrical And Computer Engr; University: University of Tennessee - Knoxville; Term: Unknown 1989;
Typology: Exams
1 / 17
This page cannot be seen from the preview
Don't miss anything!










CS 102 / ECE 206 โ Section 04 โ Spring โ
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
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
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
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
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;