COSC 1320 - C++ Programming
Bob Comer, Professor, CIS/CSC
Exam 2 Review Exercises
To prepare for Exam 1, I recommend that you look over these exercises taken from the ends of the chapters in your textbook. I will NOT grade these exercises. Some answers are given in the book, the other answers are here. Feel free to discuss the answers with your classmates or me (this is a good place to use the listserve).
Chapter 4
Self-Review Exercises: 4.1 through 4.5.
Other Questions:
1. Write a value-returning function that calculates and returns the sum of the elements in a one-dimensional array of float values. The array and the array length should be parameters to the function.
2. Write a value-returning function that calculates and returns the sum of the elements in a two-dimensional array of int values. Assume that global constant NUM_COLS contains the number of columns in the array. The array and the number of rows in array should be parameters to the function.
3. Write a C++ function that searches an integer list that is sorted in increasing order and returns the index of the first element that is larger than a specified value. The search value, the list, and the size of the list should be parameters to the function.
4. Write a function that sets all values in a two-dimensional array of double values to 1.0. Assume that global constant NUM_COLS contains the number of columns in the array. The array and the number of rows in array should be parameters to the function.
Chapter 5
Please note: you can implement strings in a program using the C++ string class or using the older method, sometimes referred to as C strings. This course (and this chapter) only covers C strings. Do not use the C++ string class on this exam.
Self-Review Exercises: 5.1, 5.3, 5.4 (exclude j & l), 5.5 (exclude c & d), 5.6 (exclude e & g).
Exercises: 5.8, 5.11, 5.22, 5.31.
Other Questions:
1. To copy one string into another, you should use the strcpy() function (the assignment operator will not work). To help you understand how C strings work, try to write your own version of the strcpy() function. Make it a void function. Your function prototype should look like this:
void strcpy( char toString[], char fromString[] );
Chapter 5 Study Notes
Sections 5.1 thru 5.3 - You need to know this information.
Section 5.4 - This section should be called "Call-by-reference with pointer arguments". This section describes how C programmers implement call-by-reference. It is important to know in case you are asked to maintain C code. I would recommend that you use reference parameters in place of pointer parameters whenever you can.
Section 5.5 - The const qualifier and parameters - good stuff.
Section 5.6 - another example of using pointer parameters (see 5.4 above) and the relationship between pointers and arrays - good stuff.
Sections 5.7 thru 5.9 - More good stuff on pointers, the relationship between arrays and pointers, and arrays of pointers.
Section 5.10 - The rand() function will not be covered on the exam.
Section 5.11 - This section on function pointers will not be covered on the exam.
Section 5.12.1 - Be sure you understand the difference between using the extractor operator to read strings and using the getline() function.
Section 5.12.2 - I expect you to know how to use the basic string functions: strcpy(), strcat(), strcmp(), and strlen().
Copyright: Ó
2001 by the Austin Community College.
Department of Computer Studies. All rights reserved.
Comments to: Bob
Comer
Last updated: March 20, 2001