CSE 283 Introduction to Object Oriented Design

Barbara Nostrand, Ph.D.

CSE 283 Labs
Welcome to the site for CSE 283 Labs!


Lab 0: C++ Project

Prev | Next | Lab 0



1. Practice using the text editor and C++ compiler.
2. Gain experience with sequential programming.
3. Practice using the I/O facilities.
4. Learn about parameter passing in C++.


The mechanism for obtaining the command line in C and C++ is somewhat similar to the mechanism in Java.  However,  there are several differences to be aware of:

  • The array of arguments returned by C and C++ includes the name of the program being run as the 0-th element of the array. 
  • Strings in C and C++,  are not objects,  they are null-terminated character arrays. 
  • The following mechanism is used to obtain the number of strings and the location of the array of strings:  main(int argc, char *argv) where argc gives the number of arguments including the program name,  and argv locates an array of C/C++ strings. 

About include and import

Note that an include in C++ does something completely different from an "import" in Java.  In C++,  the include statement causes the reader portion of the C++ compiler to read the indicated file at that point just as if the contents of the specified file had been included in the file containing the include.  There are two kinds of include.  The one in the example above specifies a file called iostream.h which is stored in a system directory.  The second form of the include statement retrieves files from a specified path which defaults to the the directory in which you are compiling.  For example,  include "myFile.h" would insert the contents of the file myFile.h stored in your current directory into the point of the include statetment in your currently active file. 

About Compiling and Linking

Unlike Java,  C++ generates directly executable files.  This takes at least two steps.  The first step translates C++ source code files such as hello.cpp to an object files such as hello.o.  Although object files contain machine language programs,  they are not executable.  This is because they need to be connected to other object files and system services first.  This processes is called linking.  If you are writing a small program with only one source file,  then you will be able to compile and link the file by pressing the plus-plus icon in JGRASP.  Later on, l; we will look at how make files are used to control compilation and linking of programs stored in more than one source code file. 


Implement a version of Echo in C++.  Your C++ version of Echo need not produce a GUI interface.  You may simply echo the parameter string to cout.  Here is a Hello World program in C++ which will help you out:

#include <iostream.h>	// Defines cin, cout, <<, >>
using namespace std;	// Assumes std:: prefix -- simplifies std::cin to cin

    cout << "Hello World!";
    return 0;

Don't forget to clean up your directory when you are all finished. 

Prev | Next | Lab 0




Lab 0

Lab 1

Lab 2

Lab 3

Lab 4

Lab 5

Lab 6

Lab 7-8

Lab 9

Lab 10

Lab 11

Lab 12

Lab 13

Last modified: 2007 OCT 28