M. Taimoor Khan #include void main() { //This is my first C++ Program /* This program will display a string message on.

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

True or false A variable of type char can hold the value 301. ( F )
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Basic Elements of C++ Chapter 2.
CHAPTER 2 BASIC ELEMENTS OF C++. In this chapter, you will:  Become familiar with the basic components of a C++ program, including functions, special.
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)
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
Selection Statements in C++ If Statement in C++ Semantics: These statements have the same meaning as in the algorithmic language. 2- Two way selection:
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.
Practice 1 Seoul National University Graphics & Media Lab.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
C++ Programming: Basic Elements of C++.
Chapter 7 Additional Control Structures. Chapter 7 Topics l Switch Statement for Multi-Way Branching l Do-While Statement for Looping l For Statement.
CECS 121 Test 1. Functions allow you to group program statements under one name C and C++ are case-sensitive so main(), MAIN(), and Main() are all different.
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
 2000 Prentice Hall, Inc. All rights reserved. Chapter 15 - C++ As A "Better C" Outline 15.1Introduction 15.2C A Simple Program: Adding Two Integers.
Chapter 05 (Part III) Control Statements: Part II.
Chapters 1-5 Review C++ Class. Chapter 1 – the big picture Objects Class Inheritance Reusability Polymorphism and Overloading.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
CECS 130 EXAM 1. To declare a constant (read only) value: const int x = 20; const float PI = 3.14; Can we do this? const int x;
An Introduction to C++ A First Look. void Functions #include #include void main( ) { cout
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
Engineering Problem Solving with C++, Second edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 5 Parameter Passing 11/06/13.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Function User defined function is a code segment (block) that perform an specific action. Function Definition: Function Definition: Return_DT F_name (
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
1 For Loops l From Chapter 9 l A shorthand way of coding count loops.
April 11, 2005 More about Functions. 1.Is the following a function call or a function header? calcTotal(); 2.Is the following a function call or a function.
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Conditions - compare the values of variables, constants and literals using one or more relational.
C/C++ Programming Basics
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
LESSON 2 Basic of C++.
1 17/4/1435 h Monday Lecture 3 The Parts of a C++ Program.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
INPUT & OUTPUT 10/20/2016Department of Computer Science, UOM | Introduction | Fakhre Alam.
C++ Lesson 1.
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
What Actions Do We Have Part 1
Electrical Engineering Department 1st Year Programming Languages
Chapter 1.2 Introduction to C++ Programming
LESSON 2 Basic of C++.
Computing Fundamentals
Basic Elements of C++.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Basic Elements of C++ Chapter 2.
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Counting Loops.
Seoul National University
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Chapter 15 - C++ As A "Better C"
What Actions Do We Have Part 1
Fundamental Programming
C++ Programming Basics
HNDIT11034 More Operators.
Seoul National University
CS 1428 Exam I Review.
Presentation transcript:

M. Taimoor Khan

#include void main() { //This is my first C++ Program /* This program will display a string message on the screen */ cout << “Hello to C++”; } Header file Preprocessor directives Main method Console output stream Insertion operator String constant or string literal Comments White spaces Program statements

#include void main() { int var1; int var2, var3; var1 = 5; int var4 = 10; cout << var1 + var4 << endl; } Variable names Type Declaration Initialization Arithmetic's / Comparisons End line manipulator

#include int numb = 15; void main() { int var1; int var2, var3; { int var 4; int var 5; } var1 = 5; int var6 = 10; cout << var1 + var4 << endl; }

#include void main() { int var1; int var2, var3; { static int var4 = 9; } var1 = 5; int var5 = 10; const int var6 = 20; cout << var1 + var4 << endl; }

 Float  Double  Char  Bool  Short  long

#include void main() { cout << “ Things are \a getting \n better in \t c++”; } \a beep \b backspace \n new line \t tab \\ \’ \” etc

#include void main() { int score; cout << “Please enter the score value\n”; cin >> score; cout << “Score is: \t” << score; } Extraction operation / get from operator

#include void main() { int height = 7; float length = 4.5; double sum = height + length; }

#include void main() { int var1 = 5; char var2 = static_cast (var1); } Static_cast (Variable)

#include void main() { int a = 5; int b = 6; cout << a % b; } +, -, %, * /

#include void main() { int a = 5; int b = 6; b += a; cout << a % b; } =, +=, -=, *=, /=

#include void main() { int a = 5; cout << a << endl; cout << a++ << endl; cout << ++a << endl; cout << a-- << endl; cout << --a << endl; } Prefix, postfix

#include void main() { int a = 5; int b = 6; cout << (a <= b); }, ==, !=, =

 For Loop  While Loop  Do While Loop

#include void main() { for(int i = 0; i < 5; i++) cout << i*2; } Declaration and initialization expression Test expression Increment expression

#include void main() { int a; for( a =0; a<5; a++) { a = a*2; cout << a; } Blocks

#include void main() { for(int i=0; i<2;i++) { for(int j=0; j<3; j++) cout << i+j <<endl; }

#include void main() { int a = 4; while (a > 1) { cout <<a <<endl; a--; }

#include void main() { int a = 5; do{ cout <<a <<endl; a--; }while(a>2); }

#include void main() { int a = 5; int b = 6; if(a > b) cout << a % b; } if

#include void main() { int a = 5; int b = 6; if(a > b) cout << a % b; else cout << b % a; }

#include void main() { int a = 5; int b = 6; if(a < 3) if( a > b) cout << a % b; else cout << b % a; }

#include void main() { int num; cout > marks; switch(marks) { case 0: cout << “low”; break; case 1: cout << “medium”; break; case 2: cout << “high”; break; default: cout << “very high”; }

#include void main() { int var1 = 5; int var2 = 6; if(var1>3 && var1>var2) cout << “var1 is a high number” <<endl; } &&, ||, !

 Unary !, ++, --  Arithmetic *, /, %, +, -  Relational, =,==,!=  Logical&&, ||  Conditional?:  Assignment=, +=, -=, *=, /=, %=

#include void display(); void main() { cout << “main body” <<endl; display(); cout << “main body” <<endl; } void display() { cout << “Display function called” <<endl; } Declaration Definition Calling

#include int sum(int v1, int v2); void main() { int a = 5; int b = 6; cout << sum(a, b); } int sum(int v1, int v2) { int temp = v1 + v2; return temp; } By value Return statement

#include int sum(int& v1, int& v2) { return v1 + v2; } void main() { int a = 5; int b = 6; cout << a % b; } Passing objects

#include int sum(int v1, int v2) { cout << “function 1” <<endl; return v1 + v2; } int sum(int v1, int v2, int v3) { cout << “function 2” <<endl; return v1 + v2 + v3; } float sum (float v1, float v2) { cout << “function 3” <<endl; return v1 + v2; } void main() { int a = 5; int b = 6;int c = 10;float d = 4.5;float e = 6.4; cout << sum(a, b); cout << sum(a, b, c); cout << sum (d, e); }

#include Int fact(int n) { if(n > 1) return n * fact(n – 1); else return 1; } void main() { fact(3); }

#include inline int getTwice(int a) { return a*2; } void main() { cout << getTwice(4); }

 Local Variables  Global Variables  Static Local Variables

#include int a = 5; int someFunction() { return a; } void main() { int b = a; cout << a % b; }

#include int a = 5; int someFunction() { static int halfValue = a/2; return a; } void main() { int b = a + halfValue; cout << a % b; }

#include int& sum(int a, int b) { return a+b; } void main() { int a = 4; int b = 5; sum(a, b); }

#include int someFunction(const int b) { if(b < 2) cout << “B < 2” <<endl; } void main() { int b = 5; cout <<someFunction(b); }