Internet Explorer tends to display C++ code embedded in my web pages strangely. I would highly recommend Firefox instead.
// 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.
| Code | Meaning |
| #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. |
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.
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).
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.
Read & understand the CS 54 Style Guide. Answer the questions on page 2 of the Lab Worksheet.
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.
![[Dilbert]](dilbert.gif)