CS 160 - Programming Concepts and Applications

Summer II 2018 - Lab 1A - Hello World!

Quick Links: Canvas | John Cabot | Piazza | zyBooks

|   Home |  Contact |  Syllabus |  Assignments |  Schedule |  Resources   |

This lab is due by Tuesday, July 3, 2018, 11:59 PM.


The IDE



This lab teaches you how to create a C++ program from scratch. Codenvy is an Integrated Development Environment (IDE) designated to facilitate the development of software solutions. Codenvy includes an editor, a compiler, a linker, and many other additional tools to help programmers write high quality software.

Depending on its complexity, a software project will have many different files associated with it, such as the source code (instructions written using a programming language), header files (mostly definitions), resource files (images, sounds), data files, and configuration files. Most IDEs, including Codenvy, require programmers to organize all of these files into an entity called a project. More complex software may be built from many inter-related projects that are organized into a solution (a container for projects). But, in our course this semester, we will only develop single-project solutions.


Creating a C++ Empty Project



Now you may proceed to create your first C++ Codenvy project. How exciting! On the right hand side, click "Create Project" (or navigate through the menus Workspace > Create project). Select "C++" from the left hand menu. Then name it L1A and provide a brief description. Read the next paragraph about file naming before moving on.

Let us now provide you with a few important notes about names for projects, solutions, and development files in general. Do not use spaces or any special characters when naming your project. We highly recommend using short names (less than 10 characters). If you want to use more than one word, use underscores to connect the words or appropriate use of upper/lower case (e.g., MyGame). Also, make sure your chosen name has a meaning so you can remember what the project is later (e.g., L1A).


Editing A C++ Source Code File



If you haven't already, be sure to click create.

You will already have a hello.cpp file that is started for you. We will want to rename it by right clicking and selecting "Rename...". Name this file main.cpp. This file will contain our program. Begin by deleting the default contents of the file.

You can now start typing code. Sweet! Since this is a programming class, not a typing class, enter the code between the following lines with cut/paste:

/* CS 160 Lab 1A: XXXX (_GIVE_BRIEF_DESCRIPTION_HERE_)
 *
 * Author: XXXX (_INSERT_YOUR_NAME_HERE_)
 *
 * More complete description here...
 */

// The include section adds extra definitions from the C++ standard library.
#include <iostream> // For cin, cout, etc.

// We will (most of the time) use the standard library namespace in our programs.
using namespace std;

// Define any constants or global variables below this comment.

// Must have a function named "main", which is the starting point of a C++ program.
int main() {

  /******** INSERT YOUR CODE BELOW HERE ********/

  cout << "Hello world!" << endl; // print Hello world! to the screen

  /******** INSERT YOUR CODE ABOVE HERE ********/

  return 0; // signals the operating system that our program ended OK.
}
	

Next, edit all places where XXXX appears in your main.cpp file with the appropriate information. When you are done, you can save main.cpp by typing Ctrl+s.


Running your Code



The easiest way to compile and execute your project is to click the blue arrow button at the top menu bar and select "run". A new tab should appear below with the following output:

command: cd /projects/L1A && make && ./a.out
make: *** No targets specified and no makefile found.  Stop.

We need to add one more file to our folder. Download this file and then in Codenvy select "Project > Upload File" from the top menu bar and upload the file you just downloaded. Now press the blue run button again.

Congratulations! You've written and compiled your very first program! We will discuss what the building and linking steps are doing very soon. Next, you'll see the new tab appear with the contents:

command: cd /projects/L1A && make && ./a.out
[make]: Compiling main.o
g++ -Wall -g -O3 -std=c++11  -c -o main.o main.cpp
[make]: Linking a.out
g++ -Wall -g -O3 -std=c++11 -o a.out main.o

Hello world!

Congratulations! You've run your very first program! The "Hello World" line is the output of your program.


The Iterative Process



Now that your program is running, we are going to add two more output statements following the "Hello world!" line. Add a second cout statement that prints

How are you?

Run your program again to verify you are seeing the new output on the screen. Finally, add a third line to print (note the spaces)

   (I'm fine).

Run your program again. When you are complete, your program should output

Hello world!
How are you?
   (I'm fine).

You just went through a short iterative process, or as programmer's say an incremental build. Once you knew you had your program running properly, you made a small change to the program and reran the program to verify the change was correct. Once again, a small change was introduced to the code and the program was run to verify the proper output. You should become very familiar with this process as it will make future projects go smoother if you make small changes at a time.

This lab taught you how to create a C++ Codenvy project from scratch and output statements to the screen. You need to know how to create an empty project from scratch. Thus, feel free to create a second new empty project for grins (i.e., do this lab a second time when you start Lab1B).


Optional Material: Details on the Codenvy Interface



The default interface can be described in four sections: the menus, left pane, Code Window, and Output Window..

The menus have the same functionality of most Microsoft Windows programs (e.g., Open File); there are, however, menu items that are specific to programming.

The left pane has several different views. You will almost always use the Project tab which is similar to Windows Explorer. All of the code files associated with your projects (i.e., program) will appear here.

The Code Window is where you will type/edit your C++ programs. It works similar to a text editor with the bonus of syntax coloring and segment grouping. You can have multiple code windows open - they will stack as tabs at the top of the Code Window. These tabs allow you to easily jump between multiple files when editing. You can drag a tab to open to windows side by side for easy viewing.

The Output Window keeps track of information from the compiler. When you build your program (or code), this window will list any problems that it found and give you tools to help you find and fix those problems. If there were no errors building your program, then the output from your program will appear in this window.


Lab Submission



You will submit your solution to this lab with the rest of Set1. Detailed instructions for doing this are posted in Assignment 1.


This lab is due by Tuesday, July 3, 2018, 11:59 PM.

Last Updated: 07/01/18 22:03


Valid HTML 4.01 Strict Valid CSS! Level Triple-A conformance, W3C WAI Web Content Accessibility Guidelines 2.0