Professional Documents
Culture Documents
fc763f - Lecture - 02 (CSC-110) Introduction
fc763f - Lecture - 02 (CSC-110) Introduction
CSC-110
Lecture: 02
(Introduction to Programming)
Engr.Muhammad Asad
MS Computer Software Engineering NUST
BS Computer System Engineering GIKI
1
Agenda for Today
Intro. to Programming, Structure of C++, Preprocessor
Directives, Header Files
Reading
2
Computer Languages
High‑level Language Translators
compiler
source
or object program
program
interpreter
3
Phases of C++ Programs
Program is created in
Editor Disk the editor and stored
on disk.
Primary
Memory
CPU
CPU takes each
instruction and
executes it, possibly
storing new data
..
values as the program
.. executes.
..
4
First program
#include <iostream>
int main()
{
std::cout << "Welcome to C++";
return 0;
}
5
6
Another Basic Step for Java
Programming
Debugging
– Check program execution and output to ensure
program compiles and runs as expected
– If it doesn’t, make corrections in the edit
phase and repeat the remaining steps
7
Basics Input/output functions
Common Input/output functions
– cin
Standard input stream
Normally keyboard
– cout
Standard output stream
Normally computer screen
– cerr
Standard error stream
Display error messages
8
Before writing the programs
– Comments
Document programs
Improve program readability
Ignored by compiler
Single-line comment
9
Before writing the programs (Cont..)
Header Files
Header files contain
– Function prototypes
– Definitions of data types and constants
Header files ending with .h
– Programmer-defined header files
#include “myheader.h”
Library header files
#include <cmath>
10
Quick Example
// A first program in C++.
//Printing a Line of Text
#include <iostream>
11
CSC-110
Explanation
Standard output stream object
– std::cout
– “Connected” to screen
– <<
Stream insertion operator
Value to right (right operand) inserted into output
stream
Namespace
– std:: specifies using name that belongs to
“namespace” std
– std:: removed through use of using
statements
12
Escape Sequences
Escape Sequence Description
13