As a reminder from the syllabus, labs are due at midnight on the lab day.
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.
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.cppThis 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" | ./lab1Note 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.