need answer key for old exams computer prgramming
Spring 2014 CSCI 111 Final exam � of �1 6
1. (2 points) Flip over this test. On the back of this test write your name in the upper, left-hand corner.
2. (2 points) What are the four parts of the compiling process (just give me 4 words, not a paragraph).
3. (4 points) Which of the four steps of the compiling process occurs only once, regardless of the number of source files your application has?
4. (4 points) Write a line of code that causes the preprocessor to generate an error.
5. (4 points) Write a line of code that causes the compiler to generate an error.
6. (5 points) Describe how you could incorrectly compile the joust project to cause the linker to generate an error.
7. (5 points) Given:
1 float* fp; 2 //... 3 float pi; 4 pi=*(314 + fp);
Rewrite line 4 using array subscript notation.
Spring 2014 CSCI 111 Final exam � of �2 6
8. (5 points) Given:
1 float arr[100]; 2 for(int x=0; x<100; ++x) 3 arr[x]=100-x;
What does the following expression print out? cout << *arr << endl;
9. (14 points) Given: int a=0; int b=6; int x=0;
Circle each if-expression that evaluates to true:
A) if(b)
B) if(x)
C) if(a=b==6)
D) if(a=b==5)
E) if(a=b=5)
F) if(a=x=0)
G) if(a=x==0)
Spring 2014 CSCI 111 Final exam � of �3 6
10. (10 points) Given:
1 #include<iostream> 2 using namespace std; 3 4 int main() 5 { 6 int x; 7 cout << "Enter a number greater than 10" << endl; 8 while ( x < 10 ) 9 { 10 cin >> x; 11 } 12 return 0; 13 }
This program compiles just fine, and sometimes it runs as expected. But sometimes when you run it, it exits immediately after printing "Enter a number greater than 10". That is, the program doesn't pause for you to enter a number. Why are you getting this inconsistent behavior?
11. (4 points) What is the output of the following:
int x=4; int y=3;
A) cout << x / y << endl;
B) cout << x % y << endl;
C) cout << x << "%" << y << endl;
D) cout << "x" << '%' << 'y' << endl;
Spring 2014 CSCI 111 Final exam � of �4 6
12. (16 points) What is the type of the expression. That is, what is the kind of thing that each expression evaluates to. For example:
3 + 4 integer You may assume that the variable a has been declared as an integer.
A. a + 4
B. a = 4
C. 3.14 + 4.49
D. 3 + 3.14
E. 'a'
F. cout << a
G. new float[30]
H. new float
Spring 2014 CSCI 111 Final exam � of �5 6
13. (5 points) Write a for-loop that prints out the numbers between 1 and 100 that are evenly divisible by three.
14. (5 points) Write a while-loop that prints out the numbers between 1 and 100 that are evenly divisible by three.
15. (5 points) Write a do-while-loop that prints out the numbers between 1 and 100 that are evenly divisible by three.
Spring 2014 CSCI 111 Final exam � of �6 6
16. (10 points) Given: 1 #include<iostream> 2 3 class Willow { 4 public: 5 Willow(int g); 6 private: 7 float f; 8 }; 9 10 Willow::Willow(int g) : f(g) 11 { 12 } 13 14 void display(int g) 15 { 16 std::cout << g << std::endl; 17 } Write a main-function that: A. Creates a Willow object B. Calls the display function