MT2 Info
Overview and Proces
Time/Date: Monday, April 13th 7-9pm Pacific - 120 minutes.
- Location: (Based on Class Section)
- 8am: THH 201
- 6pm: THH 101
- OSAS Accommodations: If you have USC approved accommodations, you will need to coordinate in advance with the OSAS office to schedule your exam at the testing center.
- Do not sit in the back row of the classroom.
- Bring: A pencil and good eraser or a pen if you feel brave.
- Format: The problem will mainly be fill in the blank and multiple choice but related to tracing and coding (e.g. choose which code choices should should be filled into a blank)
- Questions: Raise your hand, but PLEASE try not ask excessive questions (and if you know that you tend to ask questions, sit on the aisle or up front.)
- Policies:
- The exam is Closed book, Closed Internet (search/reference). Your mind, a 2 sided (8.5 X 11 inches) HANDWRITTEN cheat sheet. Are the only resources allowed. No calculators, phones, or textbooks are allowed. We may ask you to turn in the cheat sheet after the exam.
- You must request to leave the classroom for any reason and must hand your exam to an instructor for safekeeping untill you return. You must also leave all electronic devices in the classroom.
- You may NOT have headphones or earbuds in.
- All writing must cease by the exam end time and anything after that will be consider a violation and WILL result in penalties!
- All final answers must be written in the answer section, scratch paper will not be scanned
Topics
The following is the list of topics that you should be familiar with. Use it as a guide to help your studying.
Unit 3a
- Basic objects (structs)
- Assignment of objects
.and->operators- Using C++
stringclass
Unit 3b
- Defining your own classes
- public vs. private
- Constructors and Destructors and when they execute
- Defining member functions
- Splitting your class into files
Unit 4a
- Linked Lists
- Implementing basic operations (push, pop to front, middle, or back)
- Efficiency of various operations given variations of their implementation (with or without tail pointer, etc)
- Pros and cons compared to arrays
Unit 4b
- Doubly Linked lists and operations
Unit 4c
vector<T>basic operation- Efficiency of their operations
Unit 4d
- Deque implementations (which can work vs. cannot work)
- Efficiency of various operations given variations of their implementation (with or without tail pointer, etc)
deque<T>class
Unit 4e
- Use of
getline() - Checking an input stream for failure
- Checking for failure when opening a file
- Using C++
ifstreamandofstreamclasses for File I/O
Unit 4f
- Maze Project (no BFS questions)
Unit 5a and Unit 5b
- Operator Overloading
- Copy Semantics
Unit 5c and Unit 5d and Unit 5e
- Inheritance
- Polymorphism
- Virtual Functions
- Static keyword
Summary of Important Topics: All the topics from MT1 and prior assignments are also still requisite knowledge but the majority of the focus will be on the topics listed above. Be sure you are very comfortable with:
- Writing code to perform operations on singly- or doubly-linked lists.
- Using structs and classes
vector<>- File stream objects and reading in data using the
>>; operator
Other topics that you should be familiar with:
- Using C++
strings - Pointers (pass-by-reference, pointer arithmetic, pointers to pointers, etc.)
- C-strings and pointers to C-strings. Arrays of
char*s (likeargv[]) - Dynamic memory allocation (when it should be used and how to use it) and specifically how to allocate 1 and 2D arrays.
Practice Problems
Simple Tasks You Should Be Able To Do
File I/O and Arrays: Assume an input file with data values (strings or ints) separated by whitespace. Assume the first item in the list IS an integer of how many more items will appear. Read in all of the data items (after the first integer) and print them out in reverse order. Check to ensure each item was read successfully and quit if any item fails to be read correctly (e.g. if a string appears in the file of ints).
Sample MT2 (Codio)
-On Codio you will find a practice coding MT2 with a C-string problem and the “Electorial College” problem. This exam has been given several times as a coding midterm but this time around we are doing a written midterm. the old question is still good practice.
Spring 2023 MT2
- Exam PDF
- While this old midterm is indicative of the kinds of questions on the new midterm, the code questions will be shorter on the new midterm.
Previous and Related Programming Exams
Here are some practice materials. Note that the topics they cover might be slightly different from our list of topics.
-
Spring 2015 Exam and cost.cpp solution and scale.cpp solution.
-
MT2 Prep exercises are old exams created by a former faculty of USC and Princeton. This material is from Princeton University, which has a similar programming exam but gave 2 problems for the whole period and did so in Java. Naturally, you should practice them in C++ and not Java, and the questions on our exam are much much shorter, but more numerous (see the Spring 2023 midterm)
-
Foodlympics
- Part 1 Solutions
- Assume
mainalways has the prototypeint main(int argc, char* argv[]) -
We provide some specific notes below on how best to ”translate” them to C++.
- Practice Exam 1: Foodlympics. The test files are available here.
-
The C++ versions of the prototypes should be:
int score(int judgeRatings[], int J); // J: number of judges string best(string countries[], int C, int scores[]); // C: # countries - You can assume there are at most 100 judges and at most 100 countries.
- Use
#include <cmath>to access theroundfunction of C++.
-
- Practice Exam 2: Snow. The test files are available here.
-
The C++ versions of the prototypes should be:
double meltage(double currSnow, int temp, int salt); void printArray(double arr[], double length); - You should use
cin.fail()to detect the end of input (i.e. when it fails, assume the input is over.) - For part 2, you can assume there are at most 100 scenarios.
- Use
#include<iomanip>andcout << setw(8) << setprecision(3) << xto print the doublexin the right format.
-

