Laboratory 1 : Getting Started
EECS 1050/EECS 1530
Spring 2003

Goal:

Log into your engineering account. Remember your password is case sensitive!

At the end of the laboratory turn in a printed copy of the program, with your name on it in the comments, to the lab assistant.

Microsoft Visual C++

All labs have this package installed -- you may have to look for it in the Start menu at the bottom left corner of the screen. Once you start it up you should get a screen that looks like:

Now pick File->New from the menu. This will bring up a dialog to select what kind of project you wish to create This window looks like:

You should select Win32 Console Application from the list and you will also need to type in a path for your project. (on the right hand side). In the location box type in "U:\" and in the Project name box type in project1. When you have done all this click on the OK button. The U drive is your account on the engineering server and should probably be the location that you normally store your programs.

Once you press OK a second screen will come up to ask you what should be in the initial project. We will normally start with an empty project. Select "An empty project" and press the finish button. This will build a project with no files. An information screen will then pop up:

Click the OK button on this window. Once you have done that you should be back at the main application window and it should now appear as:

The two tabs on the left hand side, Class View and File View show either the files in your project or the classes. By default they come up with classes. Click on the File View tab to get the file view. Your screen should now look like:

Now, we can add our file to the project. To do this click on File->New and a dialog will come up to let you choose the type of file to add to the project. This dialog looks like:

Select "C++ Source file" from the list of possible file types and then type in the filename "lab1.cpp" in the middle of the right hand side (File name) and click on OK. Once you do this you will come back to the main screen and it will appear as:

You may start typing the following program into the window labelled project 1.

#include <iostream>
#include <cstdlib>
using namespace std;
//

// Program -- Lab 1
// Author: Your Name Here
//
int main (void)
{
cout <<"Laboratory 1" << endl;
return EXIT_SUCCESS;
}

Once you have finished you can build the file by selecting Build->Build All or by clicking on the icon for the build. Once you do this the results of the build will be displayed in the bottom window. If there are no errors it should appear something like:

Finally to run your program you can click on the exclamation point (run button). When you do this you will get the following run window:

Again, you can press a key to continue on.

 

Making Some Changes

We will now modify the program. First, add a declaration for floating point variables named radius, circumference, and area. These should go after the opening brace "{" and will look like:

float radius, circumference, area;

or

float radius;
float circumference;
float area;

Next we will add a statement to input the radiaus from the keyboard. This should be placed immediately after the declarations you just added. The two lines to do this should be:


cout << "Input the radius : ";

cin >> radius;
cout << "Radius is " << radius << endl;

 

Recompile and run your program. It should now ask for the radius. It is a good practice to recompile and run the program as you make changes -- it makes it easier to find mistakes. Next we will add the statements to compute the area and the circumference after the input statements.

circumference = 2.0 * 3.14159 * radius;
area = 3.14159 * radius * radius;

 

Recompile and run your program to check whether or not it is correct. Finally, we want to output the results. we need dome additional cout statements after the assignment statements to do this. These would be:

cout << "Circumference is " << circumference << endl;
cout << "Area is " << area << endl;

 

Recompile and run your program. Congratulations you have created your first C++ program! Print (Go to File and select print. The printer you select should have the same number as your room) and turn a copy of your program in to the lab instructor. The entire program should look like:


#include <iostream>
#include <cstdlib>
using namespace std;
//

// Program -- Lab 1
// Author: Your Name Here
//
int main (void)
{
float radius;
float circumference;
float area;

cout << "Input the radius : ";
cin >> radius;
cout << "Radius is " << radius << endl;
circumference = 2.0 * 3.14159 * radius;
area = 3.14159 * radius * radius;
cout << "Circumference is " << circumference << endl;
cout << "Area is " << area << endl;
cout <<"Laboratory 1" << endl;
return EXIT_SUCCESS;
}