Homework 1 - Hello World

Purpose:
The purpose of this homework assignment is to familiarize yourself using the Vi text editor, compiling C++ source code with g++, and to run the executable within the Unix environment.

In this homework, you will be writting your first C++ program. You will copy the provided code, compile the code, and run your first C++ program.

// Homework 1 - Hello World
// First Name Last Name Date
// Class Section

#include<iostream>
using namespace std;

int main() {

  cout << "Hello World";
  cout << endl;

  return(0);
}

During lecture, we will discuss what each line statement is used for in the provided code. You may not know much about what is going on yet, but by next week you will. This assignment is more so a 'copy/paste' and follow the instructions kind of deal, but again, the purpose is to familiarize yourself with Unix and standard compilation. We will learn the details very soon.

  1. Log in and change directory to your cs2010 directory
  2. Open vi and manually copy the code above, do not paste the code
    vi hw1.cpp
    Save the file and exit Vi so that you're back in Unix environment
  3. We will be using the GNU Compiler Collection (GCC) which includes a compiler for many languages, but we will be using GCC version 6.3.0
    g++ hw1.cpp
    This will compile, assemble, link, and build the following executable with a default name of a.out. Optionally you can name your executable using the flag '-o <exec_name>':
    g++ hw1.cpp -o helloWorld
    You may name the executable what ever you want, as long as it contains letters, numbers, hyphens, or underscores. DO NOT name your exec the same filename as your source code (hw1.cpp)
  4. To run your executable, you must include a period followed by a forward slash, then the name of your executable (no spaces)
    ./a.out or for a named exec ./helloWorld
    After running it, take notice of what output we see. Only the quoted text was printed and no other keywords or lines within our source code.
  5. You will use this example to 'build onto' this program. Use Vi again and open your hw1.cpp source code file and add another line of output that will include your full name after the line with the 'endl'
    cout << "First Last";
    cout << endl;
  6. Save the source code, exit, and recompile the source code. If there were no errors, run the executable and take notice of the changes.

Once completed, you will compose an email and attach your source code only (hw1.cpp). For the subject of the email, write the hw/lab # and cs2010-01 (morning) or cs2010-03 (afternoon). For example:
To :derrick@cs.csubak.edu
Cc :
Attchmnt:hw1.cpp
Subject :hw1 cs2010-1
----- Message Text -----
Here's my homework 1 submission

That's it, congratulations, and you're done. If you have any questions, feel free to ask me during office hours, before class, after class, email me, call me, or find me and I'd be happy to help. Also, there's the walk-in lab (SCI III rm 324) where there are tutors there to help if you cannot reach me