Spring 2025 CS 31

Programming Assignment 1
Getting Started with C++

Time due: 11:00 PM Tuesday, April 8

The purpose of this assignment is to have you start learning how to use g31 and either the Visual C++ or Xcode environments, and understand a variety of programming errors.

Here's what you are to do:

  1. (optional) Obtain a copy of Visual C++ and install it. You don't need to do this if you prefer to use Visual C++ on the SEASnet Windows Server or if you prefer using Xcode.

    (optional) Obtain a copy of Xcode and install it. You don't need to do this if you prefer using Visual C++.

  2. Enter this C++ program into your development environment. Do not change the program yet.

  3. Build the executable from the program. (Fix any typos you may have made when entering the program.)

  4. Execute the program with a variety of reasonable input integers to see if it runs as one would expect from reading the source code. If you're running Visual C++ and the console window disappears when your program finishes executing before you have a chance to see the output, either you launched your program by double-clicking on the .exe file, or you're running Visual C++ 2017 and you either selected Start Debugging or forgot to do step 4 from the Visual C++ writeup.

  5. Using the program as given, without changing it in any way, run it with input integers that cause it to produce incorrect, unusual, or nonsensical output. (Notice we're saying to try input integers, not input like 1273.54 or lots.)

  6. Starting from the program as given, introduce into the source code an error that someone might make that, while not preventing a successful build, causes the program when it runs to produce incorrect results from reasonable input.

  7. Again starting from the program as given, introduce two distinct types of mistakes that someone might make, each of which would cause the program to fail to compile correctly.

You should create a separate project for each of steps 2, 6, and 7, since neither Visual C++ nor Xcode allow you to have multiple files in the same project if more than one has a main routine.

In addition to running the programs under Visual C++ or Xcode, run them using g31 as the g++ with Linux writeup tells you. (As the Project Requirements document tells you, "run using g31" is shorthand for "run using g31 on cs31.seas.ucla.edu" — that specific command (g31, not g++) on a SEASnet machine reached via that specific name.)

What you will turn in for this assignment is a compressed file in zip format containing exactly four files: