CS1411 - 160 - Programming Principles I, Spring 2005

Lab assignment 1

Motivation

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

Mandatory work

Your TA will check that you have done the following things (you may leave once their done) :

Write a simple program that will output:

This is my first program!

(or something similar) with both the XCode and the Visual Studio environment! (in Visual Studio select Win32 console application, in XCode select C++ Tool)

Write a program that will ask the user for its name and then prints

Hello, Max!
It is nice to meet you

in two lines as shown (where it will print the inputed name instead of Max)

Optional work

Some other things that you might try:

  • change the two-lines program so that you use only one cout statement (other than the asking for the name)
  • change the two-lines program so that you use one cout line for every word that is outputted
  • Try inputting an empty name
  • Try adding a second variable: string city;. Ask the user: Where are you from? and output something like Hi Max, glad you came all the way from Lubbock to be here!
  • Open Explorer (Windows) or Finder (Mac) and try to find your program on the hard disk. It should be a file with the extension .cpp. Open that file with a text editor (notepad on windows, textedit on Mac).
  • At home: Install Visual Studio or XCode on your machine. Write a simple program there.

How?

Please check the labs page on how to get started. There are instructions for visual studio (use version 6) and XCode

Please give the Macs a try. If you simply cannot work with them, go to PE 119, but let your TA know.

Sample programs

Here are two sample programs from class to get you started

#include <iostream>
using namespace std;

int main()
{
  cout << "Hello, world!" << endl;
  return 0;
}



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

int main()
{
  string name;
  cout << "What is your name? ";
  cin >> name;
  cout << "Good morning, " << name << "!" << endl;
}

Help!

For help: ask your TA! He is here to help you!

If the instructions are unclear or you have any other questions, please email me