Winter 2004 CS 31
Programming Assignment 1
Getting Started with C++
Time due: 10:00 PM Wednesday, January 14th
Questions regarding this specification may be sent to your TA
or to Joe Shinnerl.
Before you ask, see if your question hasn't already been addressed by the
Project 1 FAQ. Read the FAQ before you start work
to be sure you didn't misinterpret anything.
The purpose of this assignment is to have you start learning how to use the
Visual Studio .NET environment and understand a variety of programming
errors.
Here's what you are to do:
- (optional) Obtain a copy of Visual Studio .NET and install it. If you do
not do this step, you will presumably either do all your work on the SEASnet
computers or do your development using another environment and use a SEASnet
machine only for the finishing touches.
- Enter this C++ program into your development
environment.
- Build the executable from the program, fixing any errors as necessary.
- Execute the program with a variety of inputs to ensure it runs as one
would expect from reading the source code.
- Using the program as given, run it with input numbers that causes it to
produce incorrect, unusual, or nonsensical results.
- Starting from the program as given, introduce into the source code at
least one error that someone might make that, while not preventing a
successful build, causes the program to produce incorrect results from
reasonable input.
- Again starting from the program as given, introduce at least two
distinct types of mistakes that someone might make, each of which would
cause the program to fail to compile correctly.
What you will turn in for this assignment is a zip file containing
- A file named original.cpp that contains the program as
given.
- A file named logic_error.cpp with the program you produced
in step 6.
- A file named compile_error.cpp with the program you
produced in step 7.
- A file named one of the following---
- report.txt (an ordinary text file (ASCII) )
- report.html (an HTML file)
- report.ps (a postscript file)
- report.pdf (a PDF file)
- report.doc (in Microsoft Word format) ---
that describes the
input you provided in step 5 and each of the errors you introduced into
the logic_error.cpp and compile_error.cpp programs. Briefly discuss any
error messages the compiler reported, and incorrect, unusual, or
nonsensical results. This report may well end up being much less than a page
long.
-
A file named flowchart.sss, where the suffix
"sss" is one of the same suffixes listed above for the main report:
.txt, .html, ps, .pdf, or .doc; or possibly .jpg.
This file contains an extremely simple one-page (at most) flowchart for
the given code.
You can create flowcharts in MS Word, e.g., by selecting
Insert--Picture--AutoShapes from the pull down menus.
The AutoShapes toolbar includes a "flowchart" category
with all the shapes and connectors you'll need. To add text to a shape,
right-click on the shape and select "Add text" from the menu.
Do not include anything else in the zip file. To create
a zip file, you may use the TurboZip utility (available on the SEASnet machines
or obtainable from FileStream), or any other utility that creates files
in zip format (e.g., WinZip or PowerArchiver).
The
"Submit Project 1"
link on the
Project 1 webpage
enables you
to turn in your zip file electronically. Turn in the file by the due time
above. Remember that most computing tasks take longer than expected; this
applies especially to steps 1, 2, and 3 above. Start this assignment now!
Here is the C++ program:
// Code for Project 1
// Determine a simple statistic
#include <iostream>
using std::cout; // see p. 37 in Savitch book
using std::cin;
using std::endl;
using std::ios;
int main()
{
int allStudents;
int CSStudents;
cout << "How many students are enrolled in CS 31? ";
cin >> allStudents;
cout << "How many of them are CS majors? ";
cin >> CSStudents;
double percentage = 100.0 * CSStudents / allStudents;
cout.setf(ios::fixed); // see p. 32 in Savitch book
cout.setf(ios::showpoint);
cout.precision(1);
cout << percentage << "% of CS 31 students are CS majors" << endl;
}