0% found this document useful (0 votes)
9 views11 pages

Week 5

This document provides an introduction to C++ programming, including the basic structure of a C++ program with pre-processing directives, header files, main functions, and print statements. It discusses writing, compiling, and running a basic C++ program in Dev C++. It also covers escape sequences, arithmetic operators, practice questions to calculate values like age and percentages, and assigning patterns using escape sequences and cout statements. Students are assigned reading from Introduction to C++ Programming and C++ Programming by DS Malik to reinforce the concepts.

Uploaded by

usmanaslam17621
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views11 pages

Week 5

This document provides an introduction to C++ programming, including the basic structure of a C++ program with pre-processing directives, header files, main functions, and print statements. It discusses writing, compiling, and running a basic C++ program in Dev C++. It also covers escape sequences, arithmetic operators, practice questions to calculate values like age and percentages, and assigning patterns using escape sequences and cout statements. Students are assigned reading from Introduction to C++ Programming and C++ Programming by DS Malik to reinforce the concepts.

Uploaded by

usmanaslam17621
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Computing Fundamentals

Introduction to C++ Programming


Week 5 Instructor: Shehzad Aslam
Program
 Instructions
 Can accept data
 Can output results
 Written by programmer
 Many languages
 Machine Language
 Assembly language
 High level languages
 C, C++, Java, Python, Ruby, PHP,
JavaScript, .Net etc
Basic C++ Program Pre-Processing Directive

Header file
#include <iostream>
using namespace std;
Main Function
int main()
{ Function Body

cout<<“First Program.”<<endl;
return 0;
Print Statement
}
Writing Program using Dev C++
 Create a Project (File> new>Project
 Write Project name and select Console application & C++ Project
 Select the location to save (create new folder to save in)
 A C++ source file will be created, you can use it or create own file
 Write the Code and save
 Goto Execute > Compile or Press F9
 Correct the errors if any
 Goto Execute > Run or Press F10
 Or Compile & Run by Pressing F11
Quick Questions about Print Statement
 Anything written inside double quotes will appear as-it-is on screen
 cout is object defined in iostream
 << is stream insertion operator
 endl put the insertion pointer at new line
 You can combine multiple strings / expressions using << operator
 What will be displayed?
 cout<<“2+3”<<endl<<“is 5”;
 cout<<“2+3 is”<<5;
 cout<<“2+3”<<“is”<<2+3;
Formatting the Output

Escape Sequence Details


\n Gives line break
\t Gives tab
\” Display double quotes
\’ Display single quote
\a Gives beep from speaker
\b Gives backspace
\r Shift insertion pointer at start of line
Escape Sequence Example

cout<<“T\rIts 10O\’ Clock\nSecond Lecture is


started\t…..\b!”;
Arithmetic Operators
 +, -, *, /, %
 How they work … ?
Practice Questions
 Display you bio in given format, Age must be calculated by program (subtract Byear
from 2021), marks and percentage must be calculated by program. Note new lines a
quotes too. Aggregate must be calculated by program
I am Ali from ‘Wazirabad’. I am almost 19 years old.
I got admission in “RCET” with aggregate xyz. My Education is as under
------------------------------------------------------------------
Degree Marks Percentage
------------------------------------------------------------------
FSc 890/1100 xyz%
Matric 890/1100 xyz%
Entry Test 300/400 xyz%
Practice Escape Sequance
 Create the below patterns using cout statement only
Reading

 Chapter 1: Section Evolution of Programming Languages + Processing C+


+ Program from C++ Programming by DS Malik
 Chapter 2 form DS Malik

You might also like