Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)

Slides:



Advertisements
Similar presentations
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Advertisements

Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
COSC 120 Computer Programming
Three types of computer languages
1 Key Concepts:  Why C?  Life Cycle Of a C program,  What is a computer program?  A program statement?  Basic parts of a C program,  Printf() function?
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
C++ fundamentals.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Exposure C++ Chapter IV Introduction to C++ Programs.
COMPUTER SCIENCE I C++ INTRODUCTION
Input and Output in Console Mode UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) ADNAN BABAR MT14028 CR
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
Lecture #5 Introduction to C++
Week 1 Algorithmization and Programming Languages.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Chapter 2 part #1 C++ Program Structure
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
CHAPTER 1: INTRODUCTION C++ Programming. CS 241 Course URL: Text Book: C++ How to Program, DETITEL & DEITEL, eighth Edition.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 06 FUNCTIONS 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1.
Learners Support Publications Introduction to C++
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Topic Pre-processor cout To output a message.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Chapter 1: Introduction to computers and C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CSC201: Computer Programming
Completing the Problem-Solving Process
Computing Fundamentals
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Beginning C++ Programming
Introduction to C++.
Chapter 2 part #3 C++ Input / Output
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
Chapter 3: Input/Output
Programming Fundamentals Lecture #3 Overview of Computer Programming
Programs written in C and C++ can run on many different computers
Capitolo 1 – Introduction C++ Programming
C++ Programming Basics
Introduction to Programming - 1
Chapter 1 c++ structure C++ Input / Output
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER) 1

Chapter NoChapter Name 1. Introduction to C++ 2. Variables,constants,expressions 3. Conditional statements 4. Loops 5. Arrays 6. Functions 7.Classes 8.Inheritance 2 Course Contents BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER) Recommended book:oop in c++ by Robert lafore 2

Introduction to C++ : Differences between C and C++: C++ is derived from the C language. C is a structured language, while C++ is an object-oriented language. Dennis Ritchie developed C in 1970, while Bjarne stroustrup developed C++ in the early 1980 at Bell Laboratories. 3

Conti….. C++ is an object-oriented version of C. Object-oriented programming involves concepts that are new to programmers of traditional languages such as BASIC, Pascal and C. It goals clear, more reliable and more easily maintained programs. 4

Conti… As compare to C, C++ has many features like improved approach to input/output and a new way to write comments. C++ inherits much of the efficiency of C language, as well as the readability and ease of writing programs. C++ supports the concept of encapsulation and data hiding through the creation of user- define types, called Classes. 5

Conti…. C++ supports the polymorphism concept. Polymorphism means to create multiple definitions for operators and functions. 6

Writing c ++ program The source code of c ++ program is stored on the disk with extension cpp (cpp stand c plus plus). The program is stored in a text file on the disk. any text editor can be used to write and edit c++ source code. The c++ compiler translates a c ++ program into the machine code. the machine code is called object code. it is stored in a new file with extension obj. 7

Conti….. The object code is then linked to the libraries. After linking the object code to the libraries, an executable file with extension.exe is created. The executable program is then run from operating system command line. For example a source code of program in c++ is written and stored in file first.cpp. After compilation the object code is saved in file first.obj and executable code is stored in file first.exe. 8

Structure of c++ program A c++ program consists of three main parts. These are: Preprocessor directives The main () function C++ statements 9

Preprocessor directives The instruction that are given to the compiler before the beginning of the actual program are called preprocessor directives. These are also known as compiler directives. These directives normally start with a number sign # and keyword “include” or “define “.for example preprocessor directives are used to include header files in the program. 10

Header file Header file is a ++ source file that contains definition of library functions. Header files are added into program at the time of compilation of the program. A header file is added if the function /object defined in it is to be used in the program. The preprocessor directive “include” is used to add a header file into the program. The name of file is written in angle bracket <> after “# include” directive. it can also be written in double quotes. 11

Conti…….. C++ has a large number of header files in which library functions are defined. The header file must be included in the program before calling its functions in the program. A single header file may contain a large number of built in library functions. For example,the header file iostream.h has definition of different built in input output objects and functions. 12

main function…. The “main ()” function indicates the beginning of a C++ program. The “main()” must be included in every C++ program. When a C++ program is executed, the control goes directly to the main() function. The statements within this function are the main body of the C++ program. 13

Conti…. If main() function is not included, the program is not compiled and an error message is generated. The syntax of main() function is : main () { program statement…. } 14

Basic input/output The statements that are used to get data and then assign it to variables are known as input statements The statements that are used to receive data from the computer memory and then to send it to the output devices are called output statements 15

The “cout” object-output stream The cout is pronounced as ‘see out’. The ’cout’ stand for console output. The console represents the computer display screen. The ‘cout’ is a c++ predefined object. It is used as an output statement to display output on the computer screen. It is a part of iostream header file. Flow of data from one location to another is called stream. The ‘cout’ is the standard output stream in c++. This stream sends the output to the computer screen. 16

Syntax of cout Cout<<constant/variable; where ‘cout ‘ name of output stream object. ‘<<‘ insertion operator it separate variable,constants. The string constant are given in a double quotation marks. numeric constants, variable and expression are without quotation marks. 17

A program to print a message on screen using cout object. # include main() { clrscr(); cout<<“ c++ is a powerful programming language”; } Note: clrscr() function is part of conio.h header file. 18

The “cin “ object-input stream The “cin” stands for console input. It is pronounced as “see in”. It is an input stream. It is used as input statement to get input from the keyboard during execution of the program. When an input statement is executed, the computer waits to receive an input from keyboard. When a value is typed and enter key is pressed,the value is assigned to the variable and control shifts to the next statement. The cin object is also part of iostream.h header file. 19

Syntax of cin Cin >> var1>>var2…; where cin represent the object name used as input stream. “>>” extraction operator or get from operator. It gets an input from the input device and assign it to the variable. each variable is separated by extraction.”>>”. for example. cin>>a>>b>>c; 20

Calculate sum and product get value from keyboard during program execution. #include main () { int n1,n2,s,p; clrscr(); cout<<“enter first number “; cin>>n1; cout<<“enter second value”; cin>>n2; s=n1+n2; p=n1*n2; cout<<“sum of two number”<<s<<endl; cout<<“product of two number “<<p<<endl; getch(); } 21

The endl manipulator The “endl” stands for end of line. It has same effect as the escape sequence “\n”. This is a predefined iostream manipulator. For example cout<<“c++\ n”<<“programming \n“; is equivalent to: cout<<“c++”<<endl<<“programming” <<endl; 22

Program to print a message on screen by using endl manipulator #include main() { cout <<“I am a”<<endl<<“student”; } 23

The “setw” manipulator The “setw” stand for set width. This manipulator is used to set width of the output on the output device. syntax is : setw(n) where n represent the width of the output field. It is an integer value. The setw manipulator is a part of iomanip.h header file. If the manipulator is to be used in the program,this header file must be included at the beginning of the program using include statement. 24

P rogram that uses “setw” manipulator #include main() { clrscr(); cout<<setw(5)<<63<<setw(5)<<8<<endl; cout<<setw(5)<<100<<setw(5)<<77<<endl; getch(); } 25

The escape sequence Special non-printing characters are used to control printing on the output device. These are called escape sequence. These characters are not printed. These are used inside string constants or independently. These are written in single or double quotes. It is combination of backslash ‘\’ and a code character. 26

Escape sequence and explanation \a“a” stands for alert a alarm. It cause a beep sound. \b“b” stands for backspace. After printing a string the cursor will move one space back. \t“t” stands for tab. It cause one tab forward. \n“n” stands for new line. It move control to the beginning of next line. \r“r” stands for carriage return. It move the cursor to the beginning of the current line. 27

Conti….. \\These are two backslash characters. One is used as control character and second is used to print a backslash ‘\’ character. For eg: cout<<“A:\\xyz”; out put will be A:\xyz \””This escape sequence is similar to the “\\”. It is used to print double quotation marks (“). For eg :cout<<“\”MIHE”; Output will be “MIHE 28

29