Note:

This is an HTML translation of an old final exam, so there may be some small errors. Use this as a guide to help you study. It is unlikely that the actual final will contain one of these problems. However, it will cover material necessary to solve these problems.

Bruce

Name: ____________________

  CS 112
  Final---Fall 1999
Bruce Bolden December 16, 1999

Answer questions as indicated. Closed book/Closed Notes.
No Calculators or other PDAs (personal digital assistants).

Basic Concepts---20 points

Circle the correct answer. Each problem in this section is worth 2 points.

Problem 1. While loops are executed at least once. True False

Problem 2.

Global variables should never be used. True False

Problem 3.

Functions simplify programming tasks. True False

Problem 4.

Function prototypes serve no purpose. True False

Problem 5.

C++ is a compiled language. True False

Problem 6.

x.0 is a valid variable name. True False

Problem 7.

Variables must be initialized before they True False
can be used.

Problem 8.

C++ is case sensitive. True False

Problem 9.

Binary searches should always be used True False
when searching an array.

Problem 10.

for loops should always be used True False
when repetition is required.


Name: ____________________

Short Answer---20 points

Fill in the blank. Each problem in this section is worth 5 points.

Problem 11. Describe the difference between a function prototype and a function definition.

Problem 12. What is the difference between a for loop and and do--while loop?

Problem 13. Why are arrays useful?

Problem 14. What are the most important features of an array?


Name: ____________________

Program Analysis---10 points

Problem 15--17. What is printed by the function func() in the following program? Show All Work!

//  Final.cpp
#include <iostream.h>

int func( int i, int j, int &k );

main() { int j = 1; int k = 2; for( int i = 1 ; i <= 5 ; i += 2 ) j = func( i, j, k ); return 0; } int func( int i, int j, int &k ) { if( 3*i-j/5 > 4 ) cout << j << " " << i << " " << k++ << endl; else cout << j++ << " " << ++i << " " << k++ << endl; return ++j; }

Problem 15. ______________

Problem 16. ______________

Problem 17. ______________


Name: ____________________

Functions---30 points

For all problems in this section, show all additional variable names and types that you choose to use.
Use meaningful function names!

Problem 18. Write a function that will print the value of the function sigmoid(x) for real values of x = -45 to 45
in increments of 5. Output is written to the screen.

Problem 19. Write a function that will find and return the minimum value in an array of real numbers.


Name: ____________________

Problem 20. Write a function that will swap two integer values.

Problem 21. Write a function that will count the number of vowels in a string. Hint: the string is an array of characters.


Name: ____________________

Problem 22. (10 points) Write a function that will generate a multiplication table for display on a Web site using HTML. The table is to go from 1 to 9. A table begins with <TABLE> and ends with </TABLE>. Table rows begin with <TR> and end with </TR>. Each item in a table begins with <TD> and ends with </TD>. Output is to be written to the file stream object fOut.


Name: ____________________

Programming---20 points

Show all variable names and types that you choose to use. Use meaningful function/variable names!

Problem 23. Write a complete program that will convert RGB (red-green-blue) records for one system to another. The values (integer) in the original system range from 0---65535. The new values range from 0--255. The original data is stored in a single column. The output is stored in three separate columns. The original data is contained in three files

 Red.dat, Green.dat, and Blue.dat
(just numbers). The program output is to be stored in RGB.pal and the conversion (scaling) is to be done in a function.
Hint: the conversion factor is 255/65535)


Name: ____________________

Bonus Problem: Two points. List the basic data types in C++: