You are on page 1of 15

INTRODUCTION TO C AND C++

PROGRAMMING MODEL

Gerald L. Almodiel

CS331: Computer Organization, Architecture and


Assembly Language Programming

College of Computer Studies


AMA Computer University
Topics Outline
2

 History of C and C++

 C++ Standard Library

 C++ Development Environment

 Introduction to C++ Programming

 Sample Programs

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013


History of C and C++
3

 History of C
 Evolved from two programming
languages
 BCPL and B

 Martin Richards – developed BCPL


and B in 1967

 Dennis Ritchie – evolved C language


from B in “Bell Laboratories”

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013


History of C and C++
4

 History of C++
 C++ is an extension of C

 Bjarne Stroustrup - early1980’s

 1983 – C with classes


redesigned and called C++

 1985 – C++ compilers made


available

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013


C++ Standard Library
5

 What is C++ programs ?


 Built from pieces called functions and classes

 What is C++ Standard Library?


 Rich collections of existing classes and functions

 Compiler Vendors
 Standard Library generally provided by
Software Vendors

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013


C++ Development Environment
6

 C++ System
 C++ System generally consist of 3 parts:
 Program Development Environment
 Languages
 Standard Library
 C++ programs typically go through 6 phases:
1. Edit
2. Process
3. Compile
4. Link
5. Load
6. Execute

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013


C++ Development Environment
7

Editor Program is created in


Disk
the editor and stored
on disk.
 Phases of C++ program Preprocessor Disk Preprocessor program
processes the code.

1. Edit
Compiler creates
Compiler Disk object code and stores
it on disk.
2. Process
Linker links the object
Linker Disk code with the libraries,
creates a.out and
3. Compile
Primary
stores it on disk
Memory
Loader

4. Link
Loader puts program
Disk
in memory.
..
..

5. Load
..

Primary
Memory

6. Execute
CPU
CPU takes each
instruction and
executes it, possibly
.. storing new data
..
.. values as the program
executes.
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013
Introduction to C++ Programming
8

 Input/output
 cin
 Standard input stream
 Normally keyboard

 cout
 Standard output stream
 Normally computer screen

 cerr
 Standard error stream
 Display error messages

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013


Introduction to C++ Programming
9

 Standard output stream object


 std::cout
 “Connected” to screen
 <<
 Stream insertion operator
 Value to right (right operand) inserted into output stream
 Standard input stream object
 std::cin
 Receiving input from the user
 >>
 Stream insertion operator
 Value to left (left operand) inserted into input stream
CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013
Introduction to C++ Programming
10

 Namespace
 std:: specifies using name that belongs to
“namespace” std
 std:: removed through use of using statements

 Endl
 Indicates the end of a specific line

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013


Introduction to C++ Programming
11

 Comments
 Document programs
 Improve program readability
 Ignored by compiler
 Single-line and Multiline comments
 Begin with //
 Begin with /* and ends with */

 Preprocessor directives
 Processed by preprocessor before compiling
 Begin with #

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013


Introduction to C++ Programming
12

 Scape Sequence
Escape Sequence Description

\n Newline. Position the screen cursor to the


beginning of the next line.
\t Horizontal tab. Move the screen cursor to the next
tab stop.
\r Carriage return. Position the screen cursor to the
beginning of the current line; do not advance to the
next line.
\a Alert. Sound the system bell.
\\ Backslash. Used to print a backslash character.
\" Double quote. Used to print a double quote
character.

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013


Sample Program
13

// This is a sample code


// This program outputs Welcome to C++

#include <iostream> //allows the program to output the data to the scree

// function main begins programs execution


int main()
{
std::cout << “Welcome to C++ \n” ; //display message

return 0; //indicate the program ended successfully


}

CSCI6B : Computer Organization, Architecture and Assembly Language


12/7/2013
Programming
Computer Organization, Architecture and Assembly
Language programming
14

ANY QUESTIONS ?

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 12/7/2013


15

~ FIN

CSCI6B : Computer Organization, Architecture and Assembly Language


12/7/2013
Programming

You might also like