Lab 1 - Using Sleipnir and Basic Compilation

The purpose of this lab is to review how to access the department server for your assignments and then make a small C++ program with variables.

Part 1: Review of CMPS 150/215 Topics

If you did not attend CMPS 150 or 215, see me for your account information sheet, which has your username and password for Sleipnir. If you did attend CMPS 150/215, be sure to remember your username and password or bring the account information sheet to the lab.

This section of the lab will review pertinant concepts from 150/215 about how to log into Sleipnir, manipulate files, use vi and send emails. I'll also show you how to secure your files so that other students cannot read them.

Refer to my connection guide for more details on how to connect to Sleipnir and log in.

Part 2: Lab Assignment

For this part of the lab, we will write a small C++ program that asks the user to enter an integer and then a double. You may have a lab partner for this part of the assignment. Make sure to put both your name AND your lab partner's name in the comment section at the top of your code so you both get credit.

Program Requirements: Print a prompt that asks the user to type an integer. Read what the user types into an integer variable. Then prompt the user to enter a double and read what the user types into a double variable. Finally, echo the contents of the variable to the screen to verify that you read them in correctly.

The program output should appear similar to the following:

Enter an integer: 9
Enter a double: 5.3
You entered the integer 9 and the double 5.3.
Use vi to create the program with the filename lab1.cpp (e.g. give the command vi lab1.cpp). Make sure you have changed into your CMPS 221 directory before issuing the vi command (e.g. cd cs221).

When you are done with writing the source code, you will need to compile it into an executable. To compile the lab1.cpp source code file, issue the following command on Sleipnir:

g++ -o lab1 lab1.cpp
This will create an executable called lab1. If you made any syntax errors, they will print onto the screen. Note the line numbers given and reopen your lab1.cpp file in vi, go to those line numbers and try to fix the problem. Repeat this until no errors are given, which means your code has compiled into an executable.

To run the executable, give the following command:

./lab1

Run the program a few times (repeat the ./lab1 command) and experiment with giving different input such as entering a double instead of an integer for prompt 1 and an integer instead of a double for prompt 2. Also try entering both numbers at once with just a space between them instead of hitting enter after each number. Finally, try this command from your Sleipnir prompt:

echo "5 1.3" | ./lab1
Note how the numbers you gave to echo are used as input to the program.

Lab Submission: Email me and attach your lab1.cpp file (the source code) to the email. Do NOT email me your lab1 file (the executable). You should also CC your lab partner so they have a copy of the source code since you'll modify Lab 1 as part of Homework 1.