Chris Pollett>Old Classes>PIC 10a, Spring 2000>Practice Final

Spring 2000 PIC 10a Practice Final

Although the final can in principle cover any of the material this quarter it will primarily concentrate on material starting section 4.2 in the book. That is, Chapter 4 after 4.2, Ch 5-7, pp. 453-455, 458-462, Ch 9, 589-596, 610-612, Chapter 11. In addition, you should know how to dynamically allocate multidimensional arrays and recall the union type we talked about in class, continue statements and goto. The material in Ch7 on short-circuit evaluation of &&, || and on scoping rules for local variables was covered before the midterm so is less likely to be on the final. The final will be about the same difficulty as this practice final. It will be shorter though having 6 problems rather than 10. One problem from this practice final is guarenteed to be on the final.

Here is how I would study for this final in the order from most to least important... (1) Make sure I understand and can do the problems on the practice test reasonably quickly. (2) Read lecture notes making sure to go over and understand the examples given. Examples are often sources for test problems. (3) Review homeworks and their solutions since midterm. (4) Read the relevant sections from the book.

Practice final questions...

  1. Define the following C++ terms and give an example:
    1. call-by-reference
    2. postcondition
    3. inheritance
    4. accessor function
    5. friend function
  2. Write a short program that writes out the decimal numbers between 0 and 100 in .001 increments. The output should be aligned left in a fixed point field of width 10. Number should be output to a precision of three decimal places.
  3. Write a short program which gets a filename from the user and then an integer. It then writes the integer to this file and then closes it. Your code should check to make sure the file was opened correctly.
  4. Consider the class:
    class Book
    {
    	public:
    	    Book( char name[], bool stat);
    	    void getName(char copiedName[]);
    	    bool getGheckOutStatus();	
    
    	private:
    	    char name[10];
    	    bool checkOutStatus;
    	   
    }
    
    Write code for the three member functions of the above class. The constructor should set the name and status of the book object, so getName should use copy the name of the Book object into the array copiedName and getCheckOutStatus should return the check out status of the Book object.
  5. What would the following code fragment print to the screen?
    for(int i=0, int j=3;i*j < 5; i++, j=(j+1)%4)
    {
    	if(i==1) continue;
    	cout <<  "i: " <<  i <<  " j: " <<  j <<  endl; 
    }
    
  6. Write a function with prototype int GradesToGPA( char grade); which takes a letter grade of type A, B, C, D, F and returns an integer. Use a switch statement.
  7. Explain how goto and break work in the context of loops. Give an example.
  8. Explain using English and showing the intermediate steps how SelectionSort would sort the following list of numbers from lowest to highest:
    7 4 2 6 8.
  9. What does the following code fragment print out?
     
    int *p, *q, v=7;
    
    cout <<  "v:" <<  v <<  endl;
    
    p =&v;
    
    cout <<  "*p:" <<  *p <<  endl;
    
    *p = 1;
    
    cout <<  "*p:" <<  *p <<  endl;
    
    q = new int;
    
    *q= 4;
    
    p=q;
    
    cout <<  "*p:" <<  *p <<  endl;
    
    
  10. Write a program that first asks for two positive integers. If these integers were n and m it then dynamically allocates an nXm array of chars. It then uses a for loop to get n strings from the user and stores them in this array. Finally, it then prints out the strings it has gotten.