MT2 Info
Overview and Proces
Time/Date: Thurs, Nov. 20th at 7 PM Pacific Pacific - 120 minutes.
- Location: (Based on Last Name)
- A-Pe: THH 101
- Ph-Z: THH 301
- 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 each room or column closes to the wall as we need to be able to see your laptop screens for proctoring purposes.
- Do not angle your laptop screen toward the wall or use privacy screens. We must be able to see your screen reasonably well from the back of the room.
- Bring: A laptop or tablet with a minimum of 90 minutes battery run-time. Don’t count on outlet access.
- Format: The exam will consist of several coding problems to be completed in Codio. There will be more probablems available than is necessary to get full marks on the exam.
- You MUST write your code in Codio. You MAY NOT use your own editor. Failure to follow this will result in a 0 on the exam. We will be using the “paste detection” built into Codio to look for large pastes. We know some students like developing in other editors, however this will help us ensure that students do not use AI assistiants.
- Questions: Any questions about the content of the exam (clarification, etc.) should be asked on EdStem (and not by raising your hand) to avoid disrupting your neighbors.
- Policies:
- During the exam you may access the following websites: Codio, bytes.usc.edu (you may use the course slides as a reference during the exam), cppreference.com (for C++ documentation), and EdStem (for asking questions).
- You may bring a 8.5” x 11” (standard sheet of paper) HANDWRITTEN note sheet.
- No calculators, phones, or textbooks are allowed.
- You must request to use the restroom or leave the classroom for any reason.
- You may not have headphones or earbuds in.
- With 10 minutes remaining, no one will be allowed to leave the classroom (no bathroom use or leaving if you are finished). If you finish, simply close your laptop and sit quietly. Do NOT work on anything else.
- All answers and code must be submitted on Codio by 9:00 p.m., the exam will close automatically at 9:05pm.
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
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 and is an excellent example of the type of problems we will have for the exam.
Spring 2023 MT2
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 on EdStem Lessons which 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.
-
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.
-

