Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)

Slides:



Advertisements
Similar presentations
C++ Introduction.
Advertisements

 2005 Pearson Education, Inc. All rights reserved Introduction.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
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.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 1 – Introduction to Computers and C++ Programming Outline 1.6 Machine Languages, Assembly Languages,
Introduction Kingdom of Saudi Arabia Shaqra University
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline History of C and C++ C++ Standard Library Object Technology Basics.
COSC 120 Computer Programming
Three types of computer languages
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Guide To UNIX Using Linux Third Edition
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
C++ fundamentals.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
COMPUTER PROGRAMMING. Introduction to C++ History Merges notions from Smalltalk and notions from C The class concept was borrowed from Simular67 Developed.
Exposure C++ Chapter IV Introduction to C++ Programs.
COMPUTER SCIENCE I C++ INTRODUCTION
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
 2008 Pearson Education, Inc. All rights reserved Introduction to Computers, the Internet and World Wide Web.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
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++
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
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:
INTRODUCTION Kingdom of Saudi Arabia Princess Nora bint Abdul Rahman University College of Computer Since and Information System CS240.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
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.
Learners Support Publications Introduction to C++
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 2 C++ Basics.
 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:
INTRODUCTION TO PROGRAMING System Development Mansoura October 2015.
Chapter 4 Strings and Screen I/O. Objectives Define strings and literals. Explain classes and objects. Use the string class to store strings. Perform.
INPUT & OUTPUT 10/20/2016Department of Computer Science, UOM | Introduction | Fakhre Alam.
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Computer Terms Review from what language did C++ originate?
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
Completing the Problem-Solving Process
Computing Fundamentals
Chapter 2 part #1 C++ Program Structure
Chapter 2 part #3 C++ Input / Output
Introduction to C++ Programming
1.13 The Key Software Trend: Object Technology
Chapter 3: Input/Output
Programs written in C and C++ can run on many different computers
Capitolo 1 – Introduction C++ Programming
Chapter 2 part #3 C++ Input / Output
Computer Terms Review from what language did C++ originate?
Chapter 1 c++ structure C++ Input / Output
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)

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

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.

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.

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.

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

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.

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.

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

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.

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.

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 has definition of different built in input output objects and functions.

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.

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…. }

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

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.

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.

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.

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 header file.

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;

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(); }

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;

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

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.

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(); }

The escape sequence