1. Course Information

What We Will Cover


Exercise 1.1

Instructions

Use the next 10 minutes to complete the following.

  1. Join a group of 3-4 people and prepare an answer to one of the following questions.
  2. Select one member from your group as a representative to describe your answer to the class.

Exercise Questions

  1. What "burning questions" do you have about the course outline?
  2. What can you hope to learn by the time you complete this course?
  3. How do you plan to balance the work required by this course with the other activities in your life?

Note: You do not have to turn in the answers to this exercise. However, you are expected to submit answers to subsequent exercises.

1.2: Succeeding in This Course

Objectives

At the end of the lesson the student will be able to:

  • Describe how to study effectively for this course
  • Use computers in the CTC for homework
  • Install software used in this course at home

1.2.1: Elements of Success

  • Programming requires you to know many facts and procedures
  • Also, you must learn how to solve problems
  • To help you master the materials, I provide you with exercises and assignments in addition to lectures
  • To succeed in this course, you need to make use of this material

Attend Class

  • You need to attend class and pay attention
  • When asked questions, you need to respond
  • When you cannot attend class for some reason, you need to catch up before the next class meeting

Complete In-Class Exercises During Class

  • In-class exercises are problems you are given class-time to complete
  • You should complete these problems during the allotted time in class
    • However, you have about one-week to complete them after class
    • See WebCT for the exact date and time
  • You can discuss them with partners or the instructor
    • Much easier to solve problems in the classroom than at home
  • You should submit the exercises to WebCT before you leave the classroom
    • Ensures that something is turned in on time
    • You can always unsubmit them if you want to make changes during the week
  • Graded on a best-effort basis
    • You get full credit for just attempting to complete the exercise

Complete On-line Exercises On-time

  • Online exercises (CodeLab) are due about a week after we discuss the topics
  • CodeLab gives you a series of graduated exercises with "instant" feedback
  • I suggest that you complete the on-line exercises before the homework assignment

Complete Homework Assignments

  • Homework assignments have you apply and explore lecture concepts
  • Homework assignments can include reading, quizzes and writing code
  • If you get confused about or stuck on an assignment:
  • Submit homework to WebCT at least the day before it is due
    • Even if you are not done, turn it in
    • You get some credit for what you did complete
    • Make sure to state an accurate status in the README.txt file
  • Note that homework deadlines are real -- late homework is not accepted
  • Instead, most homework has extra credit possibilities

Study for Exams

  • Most students do not have perfect memories
  • You need to refresh your memory about programming details before an exam
  • Plan on spending time studying for exams
  • I will discuss study techniques before the exams

1.2.2: Time Estimates

  • Students often ask how much times is needed for a course
  • Estimated average course time per week:
    • 1 hour reading the lecture notes and textbook before class
    • 4 hours in the classroom
    • 8 hours for on-line exercises and homework assignments (excluding extra credit)
  • I collect time estimates from students for homework assignments

1.2.3: Using the CTC for Homework Assignments

  • First you will need a login and password
  • You can use either Linux, Macintosh or Windows computers for your assignments
  • For more information, follow the link to the CTC homepage

1.2.4: Can I Run This On My Own Computer?

  • All the technology we use runs on most any computer
  • Compiler used is called g++ and is free from GCC
  • For Windows, you can Install Cygwin, which contains the g++ compiler
  • For Linux/UNIX/OS-X users, you can just install gcc and g++ compilers.

1.2.4: Summary

  • Elements of success in this course:
    1. Attend class and actively participate
    2. Submit the in-class exercises before you leave
    3. Complete on-line exercises on-time
    4. Do your homework assignments and turn them in on time
    5. Prepare for and attend exams
  • You can complete homework assignments in the CTC
  • Also, you can install the necessary software at home or work

Exercise 1.2

With no more than a single partner, take 5 minutes to complete the following.

  1. Label this exercise: Exercise 1.2
  2. Submit all exercises for this lesson in one file unless instructed otherwise
  3. Complete the following and record the answers to any questions in exercise1.txt.

Specifications

  1. List the elements of success for this course
  2. What is the average time you can expect to spend outside the classroom on this course?
  3. Where do you plan to work on your programming assignments?

1.3: Introduction to C++

Objectives

At the end of the lesson the student will be able to:

  • Describe the programming process
  • Describe how source code becomes a running program

1.3.1: About C++

  • C++ is a programming language
  • A programming language allows a programmer to describe a computation
  • C++ is a high-level language
  • High-level programming languages are easier to use than low-level languages

History of C++

  • C developed by Dennis Ritchie at AT&T Bell Labs in the 1970s
    • 1973 - UNIX kernel rewritten in C
    • 1978 - K&R C specified based on the book The C Programming Language
    • 1989 - ANSI C standard released
  • C++ developed by Bjarne Stroustrup at AT&T Bell Labs in the 1980s
    • 1979 - Stroustrup begins work on "C with Classes"
    • 1982 - Name changed to C++
    • 1983 - First used by AT&T
    • 1985 - First commercial use
    • 1988 - ANSI C++ standard released
    • 1998 - ANSI-ISO standard released (ISO/IEC 14882)

More information

1.3.2: What Programming is About

  • Programming is about solving problems using a computer program
  • As such, programming requires a number of steps
  • Note that the first two steps do not require a computer

Programming Process

  1. First step is to define the problem
    • You need to describe the nature or basic properties of a problem
    • In addition, you need to describe your goal
    • Understanding a problem to this degree prepares you to solve it
  2. Next step is to define an algorithm
    • Set of steps for performing a task
    • Often has steps that repeat or require decisions
    • Can be expressed using psuedocode
  3. Then you actually write the program using a programming language
    • The language we use for this course is called C++
  4. As you write the program code, you translate human-readable source code into a language understood by the computer
    • Usually with a program called a compiler
    • Discuss compiling later today
  5. After code compiles, you test it to make sure it:
    • Does what it is supposed to do
    • Does not do what it is not supposed to do
    • Does what it used to do
  6. When it works well, you document and deliver the program

More information

1.3.3: Processing Source Code

Converting C++ source code into a program takes five steps

  1. Writing the source code
    • Programs written in a high-level language like C++ are call source code
    • Source code is written in a programming language
    • A programming language has rules and syntax like a natural language
  2. Compiling the source code to object code
    • A compiler is a program that converts source code to machine language
    • The machine-language version of source code is called object code
  3. Link the object modules
    • C++ has many prewritten code modules called libraries
    • In addition, you may produce many object modules for more complex programs
    • The linker combines all these object modules into one executable file
  4. Loading the executable code
    • The computer must load the executable files from storage into main memory
    • A program called a loader does this task
  5. Executing (running) the program
    • The final steps is to start the program running at the location into which it was loaded
    • Many programs run at the same times in most computer systems

1.3.4: Summary

  • First step to take when creating a program is to define the problem
  • Second step is to develop an algorithm that solves the problem
  • Only after verifying that the algorithm works do you translate it to C++
  • When you have C++ source code, you must go through a number of steps to produce a running program

Exercise 1.3

  1. Label this exercise: Exercise 1.3
  2. Submit all exercises for this lesson in one file unless instructed otherwise
  3. Complete the following and record the answers to any questions in exercise1.txt.

Specifications

  1. On what language is C++ based?
  2. Why do you test a program?
  3. What is the purpose of a compiler?

1.4: Editing, Compiling and Running Programs

Objectives

At the end of the lesson the student will be able to:

  • Start a command-line session
  • Navigate directories from the command line
  • Compile and run C++ programs
  • Display program output to the command line

1.4.1: Introducing Cygwin

  • Cygwin provides a UNIX-like environment for Windows
  • UNIX is an operating system that was originally written in the C programming language
  • To use Cygwin, you type commands at a command prompt
  • $ pwd
  • After typing a command, you press the Enter key

Starting Cygwin

  • Select the Cygwin Bash Shell from the Start menu

Stopping Cygwin

  • At the command line, type exit

Getting Help

  • Once you have a command line, you can use the UNIX help facility: man commandName
  • For example, to view the man(ual) page for the cat command:
  • man cat
    
  • To quit viewing a man page, press the q (for quit) key

1.4.2: Navigating Directories

  • When Cygwin starts, you are located in your home directory:
  • You can verify the current directory location using pwd (print working directory)
  • pwd
  • You can list the files in the current directory using ls
  • ls
  • View a file using any of the commands: cat, more or less
  • cat exercise1.txt
  • Change to a lower subdirectory level: cd directoryName
  • cd "My Documents"
  • Change up one directory level: cd .. (change directory)
  • cd ..
  • Change to the root of the file system: cd /
  • cd /
  • Change to any location in the file system: cd path
  • cd /cygdrive/c/cygwin
  • Change to your home directory cd ~
  • cd ~

1.4.3: Writing, Editing and Saving Source Code

  • Can use most any text editor to write and save C++ source code
  • Make sure to save the file using the extension: cpp
  • myprogram.cpp

About Using IDEs

  • Many Integrated Development Environments (IDEs) are available for C++
    • Typically provide visual tools for designing forms and debugging code
  • I do not recommend using an IDE while learning C++
    • IDE will generate code for you, which does not help you learn
    • IDEs are complex tools that themselves are difficult to learn
    • Can distract you from your goal of learning C++
  • I do recommend using IDEs once you have a good understanding of C++
    • Easier to develop user interfaces
    • Improves programmer productivity
  • Any program you submit for this course must run within Cygwin

1.4.4: Example C++ Source Code

  • Example program we can save as a source code file
  • #include <iostream>
    using namespace std;
    
    int main() {
        cout << "Hello, World!\n";
        return 0;
    }
    
  • Copy this into a text editor and save the file as: hello.cpp
  • Next step is to compile and run the program

1.4.5: Compiling and Running Programs

Compiling Source Code

  • General procedure for compiling a C++ program:
  • g++ -W -Wall --pedantic -o outfile sourcefile.cpp
  • Compiler options:
    • -W: Print extra warning messages for some problems
    • -Wall: Enable all the warnings about questionable code
    • --pedantic: Show all the warnings demanded by strict ISO compliance
    • -o outfile: place the output in outfile

For Example

  1. Open Cygwin
  2. Change directory (cd) to where program source code is stored
    • Alternatively, save the source code where Cygwin starts
  3. Type: g++ -W -Wall --pedantic -o hello hello.cpp
  4. If no errors, the compiler creates the file: hello.exe

Running a Program

  • Type: ./hello
    • Operating system runs the file hello.exe
    • Note that Cygwin automatically appends an .exe suffix
  • Program starts running at the function named main

Further Information

1.4.6: Summary

  • Cygwin provides a UNIX-like environment for Windows
  • To use Cygwin, you type commands at a command prompt
  • To start Cygwin, select the Cygwin Bash Shell from the Start menu
  • To stop Cygwin, type exit at the command prompt
  • At the command prompt, you can get help using UNIX man pages
  • man commandName
  • You can verify the current directory location using pwd
  • You can list the files in the current directory using ls
  • You can change directories using cd path
  • You can use almost any text editor for writing and editing source code
  • To compile a program, use the g++ command with appropriate options
  • g++ -W -Wall --pedantic -o outfile sourcefile.cpp
  • To run an application, type ./ and its name after the command prompt
  • ./outfile

Exercise 1.4

Use the next 5 minutes to complete the following.

  1. Start a text file named exercise1.txt
    You will be adding to this file during the lesson, so save it often.
  2. Prepare the exercise header as described in the HowTo on submitting exercises
  3. Label this exercise: Exercise 1.4
  4. Do not submit exercises until all of them from today's lesson are finished
  5. Save your answers in a text file following the instructions on How To Submit In-Class Exercises
  6. Complete the following exercises and answer any questions.

Exercises and Questions

  1. Open a Cygwin window and type: man pwd
  2. Q1: What is the purpose of the pwd command?

  3. Type q to quit the man page, and then type: pwd
  4. Q2: What information did pwd provide?

  5. Save the file shown below as hello.cpp and save it in the current Cygwin directory.
  6. #include <iostream>
    using namespace std;
    
    int main() {
        cout << "Hello, World!\n";
        return 0;
    }
    
  7. At the Cygwin command prompt, type: ls
  8. Q3: Do you see your hello.cpp file? If not, ask a classmate or the instructor for assistance.

  9. Display the contents of the file using cat.
  10. Q4: What information did cat provide?

  11. Change the directory by typing cd ..
  12. Q5: What directory are you in now?

  13. Change the directory by typing cd ~
  14. Q6: Now what directory are you in?

  15. Compile and run the hello.cpp program.
  16. Q7: What is the output of the program?

Note: do not forget to turn in your exercises following the instructions on How To Submit In-Class Exercises.

Wrap Up

Due Next:
A1: Information Please! (9/9/04)
Exercise 1 and CodeLab Lesson 1 (9/9/04)

Home | WebCT | Announcements | Day Schedule | Eve Schedule
Course info | Help | FAQ's | HowTo's | Links

Last Updated: July 13 2004 @14:48:10