0% found this document useful (0 votes)
60 views14 pages

Computer Software and Programming: Dr. Sajid Anwar

This document summarizes a lecture on computer software and programming. It introduces computer programming, explaining that programs provide instructions to the computer to solve problems in a defined order. It then provides examples of simple C++ programs, explaining how they use functions and input/output streams. It also discusses formatting text output using escape characters and sequences. Finally, it lists a reference used in the lecture.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views14 pages

Computer Software and Programming: Dr. Sajid Anwar

This document summarizes a lecture on computer software and programming. It introduces computer programming, explaining that programs provide instructions to the computer to solve problems in a defined order. It then provides examples of simple C++ programs, explaining how they use functions and input/output streams. It also discusses formatting text output using escape characters and sequences. Finally, it lists a reference used in the lecture.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

Lecture 04: Computer Software CS 101: Introduction to Computing

Computer Software and Programming

Dr. Sajid Anwar

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 04: Computer Software CS 101: Introduction to Computing

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.

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 04: Computer Software CS 101: Introduction to Computing

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

Calculate and print the average grade of 3


tests for the entire class
• Input
– 3 test scores for each student
• output
– Average of 3 tests for each student
• Process
1. Get three scores
2. Add them together
3. Divide by three to get the average
4. Print the average
5. Repeat step 1 to 4 for next student
6. Stop if there are no more students

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


Lecture 04: Computer Software CS 101: Introduction9to Computing
A Simple Program:
Printing a Line of Text
• std::cout
– Standard output stream object
– “Connected” to the screen
– std:: specifies the "namespace" which cout belongs to
• std:: can be removed through the use of using
statements
• <<
– Stream insertion operator
– Value to the right of the operator (right operand) inserted into output
stream (which is connected to the screen)
– std::cout << “Welcome to C++!\n”;
• \
– Escape character
– Indicates that a “special” character is to be output
Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi
Lecture 04: Computer Software CS 101: Introduction10
to Computing

Simple Program:
Printing a Line of Text
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.

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi


This is an example of Matlab code.
Ignore the code. The only point to
focus is on the breakpoints.
The code is run sequentially.
Instruction on line1 executes earlier
than on line 2 and so on.
In other words, the control flow is
Sequential.
Lecture 04: Computer Software CS 101: Introduction to Computing

References
Dietal and Dietal : How to Program C++
3rd Edition

Ghulam Ishaq Khan Institute of Engineering Sciences and Technology, Topi

You might also like