MT2 Info
Overview and Process
- Location: (Based on Last Name)
- SLH 200 A - Ga
- THH 301 Ge - Lo
- HAR 101 Lu - Ta
- SGM 101 Te – Z
- 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.
- Format: Online on Codio
- 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 100 minutes battery run-time. Don’t count on outlet access.
- Format: The exam is a coding exam on Codio. The first session on Nov. 14th will involve 3 coding questions. The second session on Nov. 21st will involve 2 coding questions.
- 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 use the “Code Insights” feature of Codio to identify students who paste code. The coding problems will have autograders that you must run in order to get credit for the problems. Make sure to work incrementally and run the checks as you go.
- 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:
- You are allowed (1) 8.5x11 HANDWRITTEN (double-sided) cheatsheet with your USC email address and name written in the top-left corner of the cheatsheet on BOTH sides. What is printed on your cheatsheet MUST be handwritten (directly on the sheet or on a tablet and then printed) and MAY NOT contain prints of slides, copy/pasted code from homeworks/projects, etc. You can handwrite code from a past assignment, but just cannot copy/paste print. The reason is because by writing things, they will stick longer in your head and force you to recall what your code was doing, helping you learn.
- In addition to the cheetsheet you may access the following resources: course website, course slides, your assignment and lab work on Codio and cppreference.com
- No calculators, phones, or textbooks are allowed.
- You must request to use the restroom or leave the classroom for any reason and only 1 person will be allowed to leave at a time.
- You may not have headphones or earbuds in.
- With 15 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..
- Grading
- All code will be autograder, there will not be any hand-grading of code.
- There will be 5 problems across the two sessions, we will take partial credit across all problems as your grade for this exam.
- If you get full credit on two or more problems in the first session, you do not need to sit for the second session.
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- Use of
getline()
- Checking an input stream for failure
- Using C++
string
class
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
vector<T>
anddeque<T>
basic operation- Efficiency of their operations
Unit 4c
- Doubly linked lists
deque<T>
class- Implementing basic operations
- Efficiency of various operations given variations of their implementation (with or without tail pointer, etc)
Unit 4d
- Multidimensional arrays
- Memory layout of a multidimensional arrays
- Passing multidimensional arrays to functions
Unit 4e
- syntax and use
- advantages of passing by reference
const
references
Unit 4f
- Checking for failure when opening a file
- Using C++
ifstream
andofstream
classes for File I/O - Checking for failure when attempting to receive input (extract a value from the stream)
Unit 5a
- Operator overloading
- Global operator overloads
- Class member function overloads
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:
- Using structs and classes
- Writing code to perform operations on singly- or doubly-linked lists
vector<>
anddeque<>
- File stream objects and reading in data using the
>>
; operator - Using C++
string
s - 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 (Gradescope and Codio)
- Solutions to coding problems.
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
- Part 2 Solutions
- 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) << x
to print the doublex
in the right format.
-
- Practice Exam 3: Hats. The test files are available here.
-
The C++ versions of the prototypes should be:
bool isD(int r[], int length); int maxCycleLength(int arr[], int N);
- You can assume the permutation length is at most 100.
- You should use
cin.fail()
to detect the end of input.
-
-
Practice Exam 4: Birthdays. No test files are available.
-
Practice Exam 5: Restaurants. No test files are available.
Short Practice Problems
In case you want some practice that takes less than 90 minutes, here are 5 smaller exercises (use “Select an Exercise”) of varying difficulty. They may be less relevant to topics on the midterm 2, but can serve as additional practice if desired.
Straightforward:
Medium to Challenging: