Basic UNIX command

<[Spring 2018]> IFT 250: Shell & Script Programming with Unix
Lab Activity 2C: Basic Compilation

Learnings

· Basic UNIX commands

· The Nano editor

· Compiling and running a C++ program

Part I: Getting to know Nano

Complete each step listed below and give the command you used to accomplish it.

1. Change your current working directory to the IFT250 directory

1. Using the Nano editor, create a file named first

2. Now in the file first, type the following on separate lines:

your first name, your last name, and your major.

3. Using the commands listed at the bottom of the screen, save what you have written

4. Once you have saved your work, exit the Nano editor.

5. Ensure that the file first exists and contains the content that you just typed.

Part II: Hello World!

Complete each step listed below and give the command you used to accomplish it.

1. If you are not already in the IFT250 directory, move there now.

2. Create a new file in the Nano editor named hello.cpp

3. Enter the following lines in the hello.cpp file:

//**************************************************** // // your_name // IFT250 Spring 2018 // Class Assignment 1 // File: hello.cpp // Discription: print a message to standard output // Compile: g++ -o hello hello.cpp // //**************************************************** #include<iostream> using namespace std; int main() {

cout << “Hello World!\n”;

return 0; }

1. Save the file as before and exit the Nano editor.

You have just created a C++ source file. While it is a valid program, it cannot be executed directly. First you must compile it into an executable program.

2. Compile the hello.cpp file into an executable file named hello using the command: g++ -o hello hello.cpp

3. Run the file using the command: ./hello

4. Take some to experiment with the program. Try figuring out what each line does, and even try to make the program output something different. Just remember to compile the program after you make changes.

Submissions

Once you’ve completed all the activities, perform the following steps for submission:

1. Ensure that all your answers as well as the files you created in this lab are correct and complete.

Page | 4