Computer Software and Programming: Dr. Sajid Anwar
Computer Software and Programming: Dr. Sajid Anwar
Computer Programming
• Computer is a powerful tool
• It is not intelligent!
• In order to use computer to solve our problems, we
must tell it what we want to be done and the order in
which we want it to be done.
• These instructions are called computer program.
• This process is called computer programming.
• The person giving these instructions is called a
computer programmer.
3
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
1 // Fig. 1.2: fig01_02.cpp
2// A first program in C++ Comments
Written between /* and */ or following a //.
3#include <iostream>
Improve program readability and do not cause
4 the computer to perform any action.
5int main()
6{ preprocessor directive
7 std::cout << "Welcome to C++!\n"; Message to the C++ preprocessor.
Lines beginning with # are preprocessor
8 directives.
9 return 0; // indicate that program #includeended<iostream>
successfully tells the preprocessor
to include the contents of the file <iostream>,
10} C++
whichprograms
includescontain one oroperations
input/output more functions,
(such as
one of which must be
printing to the screen).main
Parenthesis are used to indicate a function
Welcome to C++! int means that main "returns" an integer value.
Prints the string of characters contained
More in Chapter 3. between
the quotation marks.
return is a way to exit a function
from a function. A leftstd::cout,
brace { begins
The entire line, including thethe
<< body of every
return 0, in this case, means function andtoa right brace and
} ends it.
operator, the string "Welcome C++!\n"
that the program terminated
the semicolon (;), is called a statement.
normally.
All statements must end with a semicolon.
Lecture 04: Computer Software CS 101: Introduction to Computing
Simple Program:
Printing a Line of Text
Escape Sequence Description
References
Dietal and Dietal : How to Program C++
3rd Edition