MCIS-4135

Homework Assignment 2

Purpose:

This assignment will help you create and run your first C++ program, and begin to use formatting commands for your input and output.

What to hand in:

Please hand in code listings and output that are legible and formatted for ease of reading.

Submissions should be in hardcopy, so that the instructor can mark the papers with specific comments and suggestions where needed.

Problems:

  1. A Compiler To Know and Love

Type in, compile, and run very simple C++ programs, such as those in the text. One such follows:

// Your Name Here

// MCIS-4135 Summer 2008

#include <iostream>

using namespace std;

int main() {

cout << “This is my very first C++ program” << endl;

return 0;

}

  1. Data Types to Know and Love

Describe two different ways you could represent a particular date (e.g., today or your birthday) in terms of C++-supported basic data types. Describe the advantages and disadvantages of each.

  1. Algorithms To Know and Love

Describe the design of an algorithm by which you would add a particular number of days to a date (a date is as in the last problem) and compute the representation of the resulting date.

Consider that the number of days could be positive or negative.

You may assume dates are between January 1st, 1901 and December 31st, 2099.

Notes:

For part A, the main point is to make sure you have the mechanics of editing, compiling, running, and getting output under control.

For part B, think about how many ways there are to represent a date, and the kinds of problems you are likely to solve that have a date as part of them. This may help you describe the advantages and disadvantages of each.

For part C, start off simple, and then add cases. In the given year range, every year which is divisible by 4 is a leap year. Note that your choice of representation of date (from part B) changes this algorithm a lot! Remember, this is not a C++ coding exercise, but an algorithm exercise!

Evaluation Criteria:


30

Sample C++ program, formatted nicely, with output provided.

30

Representations of date

40

Algorithm description for adding days to a date


1 of 1