CS 54 - Lab 1


Web Browsers

Internet Explorer tends to display C++ code embedded in my web pages strangely. I would highly recommend Firefox instead.


Program Template

// Name: <Your Name>
// Class and Section: CS 54, Section <n>
// Date: <Date>
// Purpose: <Statement of Purpose>


#include <iostream>
using namespace std;

int main()
{
  // Actual program goes here
  return 0;
}

Last week we typed this out without really understanding what this code was about. Naturally, we will cover certain parts in more detail as the semester progresses. For now, here's an overview of what this all means.

CodeMeaning
#include <iostream>Include functions that read & write to the UNIX (bash) prompt.
using namespace std;Include standard C++ language features.
int main()Begin the main() function. This function is automatically executed by the UNIX operating system. All C++ programs start here.
return 0;This signals the operating system your program is done. Your program will exit after this point.

Review of the Compiler

See the last lab for more detail on how the compiler works. Remember to compile a file called file.cpp into an executable called executable, we will use this mile long command:
g++ -Wall -W -s -pedantic-errors file.cpp -o executable
And then to run the executable, type this at the bash prompt:
./executable
HINT: Remember the up arrow remembers your last command so you don't need to retype that tedious command again.


Lab Assignment

Today's assignment is a Lab Worksheet in the Microsoft Word format. You may do the worksheet in Microsoft Word or by hand, just be sure it's readable (and henceforth, gradeable).


Lab Assignment - Part I

This week we will go into more detail about the wonderful world of compiler errors. Last week we saw the effect of removing a semi-colon from our code and how compiler errors aren't always easy-to-understand or perfect. This week, we will be working with a broken piece of code and will fix it bit-by-bit. cd into your cs54/lab01 directory and use jpico to create a new file called lab01.cpp:

// Programmer: <Your Name>
// Class & Section: CS 54, Section <n>
// Date: 28 August 2007
// Purpose: This will read two numbers, multiplies them,
//          and displays the results to the screen


#include <iostream>
using namespace std;

int main()
{
  int product;
  int number1;
  int number2;

  // read in first number
  cout << "Please enter the first factor: ";
  cin >> number1;

  // print a blank line
  cout << endl

  // read in the second number
  cout << "Please enter the second factor: ";
  cin >> numbr2;

  // print a blank line
  cout << endl;

  // multiply the two numbers
  product = number1 / number2;

  // print the result
  cout << number1 << " * " << number2 << " = " product << endl;

  return 0;
}

Type this code in and Do NOT compile it yet! Instead, follow the istructions and answer the questions on the Lab Worksheet.


Lab Assignment - Part II

Read & understand the CS 54 Style Guide. Answer the questions on page 2 of the Lab Worksheet.


Lab Assignment - Part III

We will be turning in our assignments using Blackboard. Today, I want you to turn in your lab worksheet on Blackboard (if you hand-wrote the worksheet, just submit a blank worksheet on Blackboard so you know how to do use Blackboard). Here's a quick tutorial on how to turn in your assignments on Blackboard.

  1. Open a web browser and go to http://blackboard.umr.edu/webapps/login/.
  2. Enter in your user ID and password (the same that you use to log in to all campus machines).
  3. Under My Courses click on the entry for CS 54.
  4. In the left pane, click on Assignments.
  5. Click on the Lab 01 assignment.
  6. Click Browse... and browse for your cs54_debugging_style.doc file. It should be under s:\cs54\lab01.
  7. Click on Submit to submit the assignment.

[Dilbert]