# CSCI 103 Fall 2017: Introduction to Programming

## Programming Exam

When: March 30th from 7-8:30 PM

Where: [Read carefully below which room you will be in]

• Room SGM124 (all students)

### Laptop and Wireless Concerns

Be sure to charge your laptop in advance. Also if classroom wireless issues cause problems, do not freak out. We will deal with the problem as best we can and arrive at a fair solution.

If you have academic accommodations you need to talk to your instructor right away to find the location for the exam.

### Format

The programming exam will be like a small assignment. We will give you a description of some task(s) and maybe some starter files, and you will be asked to write one or more programs and upload them to the course website. Like an assignment, basic checks can be run on demand, but more thorough testing will be done during grading.

The exam is:

• open-textbook (but only the official course textbook)
• open-notes
• you can consult the course website as much as you want
• you can consult all programs and notes you've written down for CSCI 103
• you are allowed to read reference pages from cplusplus.com and cppreference.com BUT NOT their forums
• you can READ the course Piazza
• but you are not allowed to ASK questions
• no other websites are allowed
• and needless to say, you may not communicate with any humans other than course staff during the exam

The exam will likely run for 90 minutes.

• You are not allowed to leave until your row clears out. This is to minimize disturbances to the other students.
• You may bring a book or papers to work on if you finish early. Please close your laptop when you are done.

### Topics

This list of topics is tentative.

All the topics from the written midterm, prior PAs, prior Labs, and prior HWs may appear on the exam. So the main topics are data types, loops, conditionals, arrays, functions, dynamic memory/pointers, objects, file I/O, and basic input/output. Be sure you are comfortable with:

• File stream objects and C++ string objects.
• Dynamic memory allocation
• Structs and classes are covered on this midterm but you will not have define major new classes. You should be able to use a class provided to you and modify it as needed.
• The draw library won't be used (because we're concerned about compatibility).

### Practice

#### 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).

#### 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.

We suggest you consider the following material from Princeton University, which has a similar programming exam, though in a different language. Naturally, you should practice them in C++ and not Java.

• Assume  main always has the prototype  int main(int argc, char* argv[]).
• We provide some specific notes below on how best to "translate" them to C++.
• You can practice the first 3 exams here on the Websheets page. Use "Select an exercise".
1. 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 the round function of C++.
2. 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.
• For part 2, you can assume there are at most 100 scenarios.
• Use #include <iomanip> and cout << setw(8) << setprecision(3) << x to print the double x in the right format.
3. 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.
4. Practice Exam 4: Birthdays.
5. Practice Exam 5: Restaurants. We won't ask you to sort data on the real exam. But, it is good practice.

#### Short Practice Problems

In case you want some practice that takes less than 90 minutes, here are 5 smaller exercises (use "Select an Exercise"):

http://bits.usc.edu/websheets/?folder=cpp/practice

Straightforward:

• fizzbuzz (number classifier)
• diamond (text art)

Medium to Challenging:

• ascii_table (nested loops and ASCII)
• triangle (number classifier)
• openclose (string analysis)