CS1411 - Programming Principles I, Fall 2005

Lab assignment 1


This weeks you will get started writing and compiling simple C++ programs

The Lab Environment

You will be working with the Eclipse environment on Macintosh computers. This environment will be used in all testing, so please become comfortable with it. (Instructions are below for downloading and installing it on your PC so you can have the same environment at home.)

You should have 24 / 7 access to the Lab with your student id. If this is not working, please let your instructor know. Plan to test in the evening before relying on your card to work.

You will have a personalized account. The username is the same as your eRaider username, your first password is your SSN. Please save your files only in your personal home directory. Everything saved anyplace else can and will be deleted at random!

For more information, see the CS TTU Labs Webpage (http://labs.cs.ttu.edu).

Finding your group

For this lab, you will be working in pairs, assigned by the TA. Please find your group partner. There should be two of you in front of every computer. There should always be one person on the keyboard, and the other one helping.

Log in / change your password

Please check both of your accounts and verify if they are both working. Once logged in, please change your password according to the instructions on the labs webpage. If an account is not working, please let your TA know. Once your done, continue working in one of your accounts.

Starting, first project, hello world!

Open eclipse (switch to finder, go to applications, then the eclipse directory, double click eclipse). When asked for you workspace, make sure it is inside your personal home directory!.

Once inside, create a new project (make sure it is managed make c++. Use any name you like, but do not use spaces or dots

add a new .cpp source file. Again, use any name, but no spaces. Make sure the name ends in .cpp

Write your first program, just like this:

/* CS 1411-16x, lab 50x
   John Smith, 
   Student ID:  123-45-6789
   Lab 1, part 0

   Description:  sample hello world program.

#include <iostream>
using namespace std;

int main()
  cout << "\nHello, world!\n\n" << endl;
  return 0;

save (it will compile automatically) and run your program. Check your output. If you do have compiler errors, try to fix them.

Assignment 1

Now rewrite the program to output:

*      Welcome     *
*        to        *
* Computer Science *

Show your program output to your TA when you're done.

Log out again. Now switch users. The person previousely on the keyboard should now be the person helping, and the other way round. Log in under your name.

Assignment 2

To make people feel welcome, a company wants a personalized welcome program. The program should ask for a name and welcome that person.

Open up eclipse, create a new project, create a new source file. This time, we will write a larger program using input and output.

Write a program similar to this one:

/* CS 1411-16x, lab 50x
   Jane White, 
   Student ID:  987-65-4321
   Lab 1, part 2

#include <iostream>
#include <string>
using namespace std;

int main()
  string name;
  cout << "What is your name?";
  cin >> name;
  cout << "Hello, " << name << endl;
  return 0;

Compile and run the program. Test it.

Since you are two students, the program should ask for both of your names. Rewrite the above program to ask for to names, and then print something like Welcome Max and Fernando! (of course, with the names you typed in). When you're done, have your TA check your work.

If you still have time

If you still have time, try the following things:

  • Try some of the escape sequences (the ones starting with a \) listed in the book: \a, \r, \n, \\, \", \t
  • When typing in names, type in a first and last name (e.g. "Max Berger") or a name with middle names (e.g. "George W Bush"). See what happens


As a homework, try to install the eclipse environment on your home machine. Make sure you follow all the steps (Eclipse Setup instructions)

If the instructions are unclear or you have any other questions, please email Max Berger (max@berger.name)