Home Previous Next

CSC100AA :: Lecture Note :: Week 01
Assignments | Handouts | Resources | Email Thurman {Twitter::@compufoo Facebook::CSzero}
{GDT::Bits:: Time  |  Weather  |  Populations  |  Special Dates}



Handouts: Syllabus | AboutCSC100AA | HowToSubmitAssignments | DevC++IDE

Code: HelloWorld.cpp | HelloWorld.c | template.txt | BadHelloWorld.cpp | PrimitiveTypes.cpp | Constants.cpp | ArithOps.cpp

Syllabus Review

It is the student's responsibility to read and understand the syllabus.

The following are a small number of "tips for success."

CSC100AA Syllabus

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

CSC100AA::About the Course

First day of class: Raise your hand if you are a SCREAM student.

This course introduces the discipline of Computer Science (CS) to non-CS majors. The course has an emphasis on computer programming using the C++ programming language. It is assumed students can use a computer (email and surf the web). The course also assumes students can do basic arithmetic along with some algebra. {More...}

   "If you're joining the company in your 20s, unlike when I joined, you're 
    going to learn to code. It doesn't matter if you're in sales, finance, 
    or operations. You may not end up a programmer, but you will know how 
    to code." -- Jeff Immelt, chairman/CEO of General Electric

Twitter tweet...

   The 2018 Top Programming Languages 
   http://spectrum.ieee.org/computing/software/the-2018-top-programming-languages via @IEEESpectrum

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

hello, world

What is a Computer?

A computer (hardware) is a programmable electronic device that can store, retrieve, and process data. [Via Wikipedia.org: "A computer is a general purpose device that can be programmed to carry out a finite set of arithmetic or logical operations."]

Data is information that has been put into a form (i.e. format) that a computer can use (i.e. understand). ["Big Data" is a popular buzzphrase in 2012. #BigData]

A computer is comprised of six logical components:


Archive.org::How It Works... The Computer [original edition 1971; revised edition 1979]

Sloan.Stanford.edu::The First Computer Mouse (circa 1964) was invented by Doug Engelbart.

GDT::Computing::Bit::History of Computing Presented Using YouTube Videos [created 22 August 2009]

LongStreet.Typepad.com::The Computer Tree (1945-1960s)
[via Texas Advanced Computing Center (TACC) Facebook posting on 7 August 2012]

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

History of the Internet (in a nutshell)

1957 -- Sputnik launch by USSR [ listen (113K)]
1957 -- U.S. government creates Defense Advanced Research Projects Agency (DARPA)
1965 -- The term hypertext is coined by Theodore Nelson.
1969 -- UNIX operating system is created. (C progamming language)
1969 -- First four hosts (nodes) on the ARPAnet.
1972 -- Electronic mail and Telnet applications
1973 -- FTP application
1979 -- Usenet
1982 -- Internet and TCP, UDP, and IP
1984 -- DNS (Domain Name Service)
1988 -- CERT is formed; IRC application
1990 -- November 12th... WorldWideWeb: Proposal for a HyperText Project
1991 -- Gopher; Tim Berners-Lee posts the first code for the WWW
1992 -- Lynx text web browswer
1993 -- Mosaic (GUI-oriented web browser which became Netscape)
1995 -- Java Programming Language (Applets)

Timeline of Net Terms and Concepts by Keith Lynch
Short History of Hypertext by Jakob Nielsen
Hobbes' Internet Timeline by Robert H'obbes' Zakon

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

What are Bits, Bytes, and Words?

Memory consists of a sequence of binary digits (or bits). A bit is either on or off (true or false, 1 or 0). Bits are usually grouped into bytes. Typically, there are 8 bits to a byte. A computer that has 16 megabytes (MB) of memory has approximately 16 million (16,000,000) bytes. A group of bytes is often referred to a word.

tera- ... peta- ... exa-
1 kilobyte (1K) 1024 bytes (2 to the power of 10)
1 megabyte (1MB) 1024K or 1,048,576 bytes (2 to the power of 20)
1 gigabyte (1GB) 1024MB or 1,073,741,824 bytes (2 to the power of 30)

[More...] Wikipedia.org:: Binary prefix

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

Computer Languages: machine, assembly, high-level, 4GL

ThurmNet Technologies created a family of pretend programming languages to help discuss the various generations of programming languages.

1st-Generation: Machine Language (tnt1GL)

The tnt1GL machine language has four "commands" and supports the use of the hexadecimal digits 0 through F.

The commands are:

   0000 -- START
   0011 -- PRINT
   0001 -- END
   1111 -- ABORT

The supported hexadecimal digits are:

   0 -- 0000
   1 -- 0001
   2 -- 0010
   3 -- 0011
   4 -- 0100
   5 -- 0101
   6 -- 0110
   7 -- 0111
   8 -- 1000
   9 -- 1001
   A -- 1010
   B -- 1011
   C -- 1100
   D -- 1101
   E -- 1110
   F -- 1111

Each program begins by issuing a START command. The PRINT command takes one operand -- a "digit." The END command that "terminates" a program. The ABORT command "abnormally terminates" a program.

The following is a tnt1GL written program that prints gdt's age at the end of 2019.


   To aid readability assume the program can be written as follows:

      0011 0110
      0011 0010

GDT::Images::Real programmers code in binary.

2nd-Generation: Assembly Language (tntASML)

The following is the same program written in tntASML (i.e. TNT assembly language):

   PRINT 6
   PRINT 2

Prior to executing, an assembly program is submitted to an assembler program that converts it into machine language.

3rd-Generation: High-level Language (tnt3GL)

The following is the same program written in tnt3GL (i.e. TNT 3rd-generation language):

   main() {
      printint 62; 

Prior to executing, a high-level language is submitted to a compiler program that "translates" it into machine language.

Some of the early popular 3rd-generation languages were Fortran (1957; Formula Translation), COBOL (1959; COmmon Business Oriented Language), and BASIC (1964; Beginner's All-purpose Symbolic Instruction Code).

The 3rd-generation programming languages C and C++ were created circa 1972 and 1980, respectively.

[tidbit] When I decided to minor in CS in 1977 the first language learned was BASIC, followed by assembly then PL/I. In 1980 graduate school, Pascal was the primary language used.

4th-Generation: 4GL (tnt4GL)

Finally, the same program writting in tnt4GL (i.e. TNT 4th-generation language):

   print 62 and exit

[Definition] Portable refers to the ability to move a program from one machine to another without having to modify the code.

Machine and assembly languages are not portable. Many 3rd-generation languages are, but they portable if and only if programmers write with portability in mind.

[More...] Wikipedia.org::Programming Languages

GDT::Computing::Bit:: What is a real programmer?

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

Introduction to the Software Development Cycle

Question: Why do we write programs?

Answer: We write programs typically in response to a need from a "user."

The user generates a requirements (or specification) document and gives it the programmer. The programmer reviews the requirements. If they are understood, then work begins on the program(s); otherwise, the user addresses the concerns raised by the programmer and updates the requirements. The reviewing of the requirements can be (and usually is) an iterative process.

Do not work on a program unless you understand what you are being asked to program.

[More...] Wikipedia.org:: Software development cycle

[More...] Images.Google.com:: waterfall software development cycle

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

The C and C++ Compilation Process

C and C++ are high-level, 3rd-generation languages. These types of languages must be translated into a machine language in order to be executed by a CPU. The process of translating high-level language into machine language is called the compilation process.

The compilation process consists of the following steps.

   edit source code ->  compile   ->   link    ->   execute
      (editor)         (compiler)    (linker)       (loader)

Program source code is entered into a file using a text editor. After the code has been entered, a compiler program is started that translates the source into an object code file. The object code file is linked with other object code files that come with the compiler and an executable file (or program) is created. In order to execute the program, a program called the loader copies the executable file into the memory of the computer and sends an execute command to the CPU.

It should be noted that errors can occur during each step

source      +----------+      object     +--------+      executable
file   ---> | compiler | ---> file  ---> | linker | ---> file      ---+
(x.c)       +----------+      (x.o)      +--------+      (x)          |
                                             ^                        |
                                             |                        v
                                             |                    +--------+
                                             |                    | loader |
                                     Standard C Library           +--------+
                                     (stdc.lib                        |
                                          stdio.o                     |
                                          stdlib.o                    v
                                          math.o                     CPU

A source file ending with ".c" contains C source code; whereas, a file ending with ".cpp" is a C++ file (note: ".C" suffix may also indicate a C++ source file). A file ending with ".h" can be both a C and C++ header file. Sometimes the suffix ".hpp" (or ".H") is used to indicate a C++ only header file.

The compiler is a program that usually consists of many phases. The first phase of compilation is called preprocessing. The preprocessor does many things, but two features that must be learned immediately are file inclusion and macro (manifest constant) definitions. After preprocessing, the compiler executes two primary steps: lexical analysis and parsing. During lexical analysis, the source code is broken up into tokens and the tokens are passed to the parser. The parser does syntax and semantic analysis, which includes the generation of object code (i.e. machine language).

The linker "combines" all object code files into an executable file (by default, named a.out on Unix systems). Typically, the object files created by your source files are linked with object files that are packaged into libraries.

Most implementations allow each step of the compilation process to be executed as a stand-alone procedure. For example, compile a source file but do not invoke the linker; execute the preprocessor only; or, invoke the linker only.

Some older compilers translate C source code into assembly language, then execute an assembler program to translate the assembly language into machine language.

Early C++ compilers (those prior to 1992) translated C++ code into C code and then executed the C compiler.

The loader reads a program (i.e. executable file) into memory. Once this is completed, it becomes a process and the CPU executes it.

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

Introduction to the cout Object

In order to use the C++ Streams I/O, the iostream.h header file must be included. In addition, inclusion of iomanip.h is often needed.

   #include <iostream>
   #include <iomanip>

Upon program startup, the cout object of class ostream is instantiated.

Output to the terminal screen (or the standard output) is performed using the cout object, and the left bit-shift operator << in combinations.

   cout << EXPR;
   // in many instances, EXPR needs to be inside ()'s

Multiple values can be output by executing the following.

   cout << EXPR << EXPR << EXPR << ...;

Only one EXPR is allowed after each << The << points in the direction of the data flow to cout (the standard output) and is referred to as the insertion operator.

A cout object does not automatically place spaces between values being output, and it does not automatically add a newline at the end of its output.

Both "\n" and '\n' result in a newline being printed to the standard output. In addition, the endl I/O manipulator can be used to print a newline. Example: the following statements all print a newline followed by the value of an EXPR followed by another newline:

   cout << endl << EXPR << endl;
   cout << "\n" << EXPR << "\n";
   cout << '\n' << EXPR << endl;
   cout << endl << EXPR << "\n";
   cout << '\n' << EXPR << '\n';

C and C++ I/O can be mixed on a per-character basis, but to ensure data is sent/received in the proper order a call to sync_with_stdio() should be made.

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

About Escape Sequences

Escape sequences are used for the following reasons.

C and C++
  \a  Alert   \b  Backspace   \f  Formfeed
  \n  Newline   \r  Carriage return   \t  Horizontal Tab
  \v  Vertical Tab   \"  Double quote   \'  Single quote
  \\  Backslash   \?  Question Mark   \0  Null Character
There are two types of numeric escape sequences: octal and hexadecimal.
Java Escape Sequences
Java will not compile a source file if it contains invalid escape sequences. [ Example]

  \b  Backspace   \f  Formfeed   \n  Newline
  \r  Carriage return   \t  Horizontal Tab   \"  Double quote
  \'  Single quote   \\  Backslash   \uhhhh  Unicode; 4 hexadecimal digits
  \ooo  C style; 3 octal digits

All of the Java escape sequences -- except for Unicode \u -- can only be used within string and character literals.

   String doubleQuote = "\"";
   char singleQuote = '\'';
   char bestGrade = '\u0041';    // set to 'A'
   char worstGrade = '\106';     // set to 'F'

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

Coding and Printing Long String Literals

Printing long string literals (e.g. a multi-line paragraph) posses two programs: keeping the source code nicely formatted, and making sure the program's output is readable (e.g. that the lines are not too long, word breaks are reasonable, and so on).

In general, to keep you code nicely formatted, you need to split your long string literal into multiple string literals and then use one of the following techniques.

The LongStringLiteral.cpp source code example uses all of the aforementioned techniqes.

You cannot press the ENTER key in the middle of a string literal. That results in a compile-time (i.e. syntax) error.

The following technique is an example of using a single cout statement with multiple insertion operators.

   cout << "This is a long string literal that does not fit on"
        << " a single line.  Therefore, I split it into multiple"
        << " string literals.  Unfortuneatly, this string literal"
        << " doesn't contain any newline characters; consequently,"
        << " when it does print, it will not display properly."
        << endl;

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

Primitive Data Types

The primitive data types are built-in to the language. They are also referred to as basic, atomic, fundamental, base, and so on.

The C and C++ languages support the following primitive data types.

* The bool primitive data type is in C++ only; however, it has been added to the newest versions of C.

The   char  short   int  long   primitive data types are  integral  data types; whereas,   float  double  long double   are  floating-point  types.

When you define a variable, memory is allocated.

The amount memory allocated is implementation-dependent. For example, on system A an int may take 4 bytes; whereas on system B is takes 2 bytes.

The amount of memory allocated dictates the minimum and maximum values that can be stored in variables.

{TopOfPage} {Tutorial (text)} {C++ Programming (video)} {C at MIT (course)} {online IDEs: CodingGround | CPP.sh | jdoodle} {GDT::C/C++ Resource}

Home Previous Next