CMPSC 201
Exam Information
Exam #1 - Exam
#2 - Final Exam
This exam will cover variables, data types, statements, if statements, & files from Chapters 1 - 4, 7.2 & 8 from our class website lecture notes. The first portion of the exam will consist of True/False questions. You must use a #2 pencil to answer this portion of the exam. The second part of the exam will require you to write full working C++ statements and programs on lined paper. You will not be able to use a computer. In order to study for the exam, you should review notes taken during class & review the online notes. You should also review all assigned homework. Complete the following practice exam as well.
Part I - True/False
1. String variables are the same thing as char variables.
2. The statement numItems++; is
equivalent to the statement numItems
+= 1; .
3. If the value of the variables a and b are 0 and 1, respectively, then the
value of the expression (b
| | a && a) is TRUE (as opposed to FALSE).
4. The - symbol is the logical NOT operator in C++.
Part II - Write a C++ statement (or statements) that efficiently performs each of the following tasks. If necessary, use 3.14 for the value of pi.
This exam will mainly cover loops, functions, & arrays from Chapters 5, 6 & 11 from our class website lecture notes. However, you are still responsible for material studied earlier in the semester. The first portion of the exam will consist of True/False questions. You must use a #2 pencil to answer this portion of the exam. The second part of the exam will require you to write full working C++ statements and programs on lined paper. You will not be able to use a computer. In order to study for the exam, you should review notes taken during class & review the online notes. You should also review all assigned homework. Complete the following practice exam as well.
Practice Exam #2
Part I - True/False
1. A formal parameter would be found in the calling function.
2. while loops are examples of determinate
loops.
3. If the for statement for
(i = 1; i <= 3;
i++ ) i <= 3 is the initializing list.
4. In the function header void
swap(int & num1,
int num2) the parameter num1 has been
passed by value.
Part II - Write a C++ statement (or statements) that efficiently performs each of the following tasks. If necessary, use 3.14 for the value of pi.
1. Write a declaration statement that declares a two-dimensional array named twoD that has 5 rows and 4 columns.
2. Write a while loop that allows the user to input amounts of money in the range of $0 - $10.00 until the sentinel value -99 is entered. Keep a running total of the amount of money entered in a variable named runningTotal. Declare any necessary variables above the loop and include a statement that would display & explain the result after the loop.
3. Write a for loop that uses the loop variable j and that would efficiently display the first 12 numbers in the sequence 1, 2, 4, 8, 16, 32, 64, etc. to the screen with each value on a separate line.
4. Write a function that computes and returns the discriminant (of the Quadratic Formula) given floating-point values for a, b, & c.
5. Write a function named divisible2 that receives an integer that is passed by value. The function must return the value 1 if the passed integer is even. Otherwise, the function must return the value of 0.
6. Write a full program that efficiently finds and displays the
row number and column number of the largest value in a two-dimensional array
named table that is initialized with the values {1, 32, 87, 45}, {2, 0, 98,
4} where there are 2 rows with 4 columns.
7. Write a complete program that uses a for loop to allow the user to input 10 integers and that displays the largest inputed value.
8. Write a complete program that allows the user to input two integer values. The program must pass those two values to a function named computeAve which returns the average of the two parameters. The main function should then display the final average rounded to the nearest whole number.
As soon as a student supplies Mr. Minich with answers to this Practice Exam, he will post them here.
This exam will cover the methods of finding roots, numerical integration, & solving systems of linear equations material from Ch. 14 of our class website lecture notes. However you are still responsible for being able to demonstrate the ability to use C++ syntax learned earlier in the course.
Particularly you are responsible for the two methods of finding roots, Bisection Method and Method of False Position, & Modified Method of False Position . You must be very familiar with the Bisection Demo & Modified Method of False Position Demo programs.
The exam will also cover the two methods for numerical integration, Trapezoidal Rule and Simpson's 1/3 Rule. Be able to outline these methods in essay and/or diagram form. You should be able to interpret and understand pseudocode and C++ code for these methods. Also be able to recite the actual formulas.
Finally, the exam will cover the methods for solving systems of linear equations, Cramer's Rule, Gauss Elimination, & Gauss-Jordan. You must be able to solve two and three-equation systems by hand and show your steps as well as to interpret and understand pseudocode or C++ code for these methods.
The first portion of the exam will consist of True/False questions. You must use a #2 pencil to answer this portion of the exam. The second part of the exam will require you to write essay questions and/or to draw diagrams. You will also have to write working C++ statements, functions, and/or programs on lined paper. Finally, you may have to fill-in missing parts of pseudocode or code segments. You will not be able to use a computer. In order to study for the exam, you should review notes taken during class & review the online notes. You should also review all assigned homework. Complete the following practice exam as well.
Part I - True/False
1. A root of f(x) =2x - 2 is x = -1.
2. It is wise to initially draw a graph of a function to determine an initial
guess for a root.
3. Generally, the Bisection Method approximates roots better than the Modified
Regula Falsi Position.
4. The maximum number of iterations should be specified when using the Bisection
Method because there is no way to predict the number of iterations that will
be necessary to obtain a root that is known to exist within an interval.
Part II - Write the following code segments, programs, and essays.
1. In an essay in paragraph form, describe how the Trapezoidal Method is used to approximate integrals. Use diagrams to illustrate your answer.
2. What is the purpose of the control expression (f1 * f2 <= 0.0 ) in the nested if statement in the Bisection Demo program?
3. Use Gaussian Elimination to solve:
2x + y - z = 1
5x + 2y + 2z = -4
3x + y + z = 5
Show and label your work to receive full credit.
4. Write a function named AreaTrap that receives the integer parameters, b1, b2, and h. The function returns the area of a trapezoid which has a base length of b1, another base length of b2 and a vertical of height of h.
5. Compute the determinant of the following 3 x 3 matrix using any means that we studied in CMPSC 201. Label and show your work for full credit.
1
|
0
|
8
|
3
|
-3
|
1
|
0
|
4
|
5
|
6. Write a function named det3 which uses the function header
int det3(int mat[3][3])
that computes and returns the determinant of a 3 x 3 matrix of integers named
mat that is passed to the function. Your det3 function may call a function named det2, which uses function header int
det2(int a11, int a12, int a21,
int a22); where the arguments are the first and second row of a 2 x 2 matrix.
That is, you do not have to write the det2 function but rather you can assume
that it correctly computes and returns the determinant of a 2 x 2 matrix.
7. Use Cramer's Rule to solve:
2x + y - x = 1
5x + 2y + 2z = -4
3x + y + z = 5
Show and label your work to receive full credit.
Part III - Bisection & Modifed Method of False Position Demo Programs Fill-in-the-Blank
Fill in the blanks found in this version of the Bisection Demo program.