CS211 Midterm 1 Review Guide
The test will be on paper, available Wednesday, Feb 25, through Sunday, March 1, but our testing center is not open during the weekend. 10 pages of notes are allowed, 8.5 by 11, both sides. Some things I'd suggest for your notes:
- List of data types that are common, along with their sizes. Common are types like char, int, float, double, etc. Uncommon would be things like short, size_t (for this test anyway).
- A couple examples of how to use control structures, like one of each type of loop, an if statement, etc.
- An example of how to write a function and how to call a function
- Any terms you tend to forget.
- A bit longer example that might have pieces that are useful
Test Topics
- How to set up a C++ program (includes, namespace standard, main function, etc)
- Printing with cout and reading from the user with cin
- Variables (how to declare them, change them, types, etc)
- If/else statements and loops (while, for, and do/while, NOT goto). Switch won't be on the test. Loop control like break and continue.
- Arrays and vectors. How to use stack arrays (int arr[];) and vectors (vector arr;). Not new or delete, yet. New and delete will be on the second midterm, but not this one.
- Objects and classes, at a chapter 7 level. No inheritance, virtual functions, operator overloading, friend functions. Keywords static, private, protected, and public are not on this test.
Test Layout
The test will have a page of multiple choice, three points per question with 8 questions. After that, the rest of the test will be short answer format. Questions will ask for either a short answer in English, a short piece of code, or the output for some code, or a correction or amendment to some code.
Example Questions
Short answer: What does the following program print out?
#include <iostream>
using namespace std;
int main(){
int gerbil = 23;
int gerbil_mites = gerbil / 5;
int gerbil_hairs = gerbil % 5;
cout << gerbil_mites << endl;
cout << gerbil_hairs << endl; // Remember endl in your answer
return 0;
}
Short answer: What does the following program print out?
#include <iostream>
using namespace std;
string hamster(string message){
for(int i = 0; i < message.length(); i++)
if(message[i] == ' ')
message[i] = '_';
return message;
}
int main(){
string ham = "I'm stuck in a cage!"
cout << hamster(ham) << endl;
cout << ham << endl; // Might save this for the second midterm
return 0;
}
Short answer: Write a program that will read a two numbers from the user, a number of volts and a number of amps. The program will multiply these two numbers together, and print the result followed by the word "watts". The interaction with the user should look like this:
Enter the number of volts: 100
Enter the number of amps: 1.5
The power is 150 watts
Coding on the test
For the test, you'll have to write some code on paper. Please try to be as neat as possible! Make sure your code is close enough to something that compiles and works that it looks like you know what you're doing.