Basic Source Character Set for C++ Language:

Similar documents
Computer Science. References: 1- Borland C++ Builder By Herbert Schmidt. 3- C / C++ Programmers References By Herbert Schmidt

UNIT- 3 Introduction to C++

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

A First Program - Greeting.cpp

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

VARIABLES & ASSIGNMENTS

PART I. Part II Answer to all the questions 1. What is meant by a token? Name the token available in C++.

Unit 3. Operators. School of Science and Technology INTRODUCTION

Operators and Expressions:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

Programming in C++ 5. Integral data types

ADARSH VIDYA KENDRA NAGERCOIL COMPUTER SCIENCE. Grade: IX C++ PROGRAMMING. Department of Computer Science 1

2. Distinguish between a unary, a binary and a ternary operator. Give examples of C++ operators for each one of them.

Chapter 2: Basic Elements of C++

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Lecture 3 Tao Wang 1

Introduction. Following are the types of operators: Unary requires a single operand Binary requires two operands Ternary requires three operands

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Programming - 1. Computer Science Department 011COMP-3 لغة البرمجة 1 لطالب كلية الحاسب اآللي ونظم المعلومات 011 عال- 3

6.096 Introduction to C++ January (IAP) 2009

C++ Programming: From Problem Analysis to Program Design, Third Edition

Programming. C++ Basics

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

CAMBRIDGE SCHOOL, NOIDA ASSIGNMENT 1, TOPIC: C++ PROGRAMMING CLASS VIII, COMPUTER SCIENCE

Operators. Lecture 3 COP 3014 Spring January 16, 2018

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

DEPARTMENT OF MATHS, MJ COLLEGE

BITG 1233: Introduction to C++

Basics of Programming

LECTURE 02 INTRODUCTION TO C++

CHAPTER 3 BASIC INSTRUCTION OF C++

REVIEW. The C++ Programming Language. CS 151 Review #2

C++ is case sensitive language, meaning that the variable first_value, First_Value or FIRST_VALUE will be treated as different.

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

COMP Primitive and Class Types. Yi Hong May 14, 2015

Fundamentals of Programming

Chapter 2: Overview of C++

Operators in C. Staff Incharge: S.Sasirekha

Informatics Ingeniería en Electrónica y Automática Industrial

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CS102: Variables and Expressions

Reserved Words and Identifiers

Basics of Java Programming

The C++ Language. Arizona State University 1

Computer Programming CS F111

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

CSCE 110 PROGRAMMING FUNDAMENTALS

Introduction of C++ OOP forces us to think in terms of object and the interaction between objects.

LESSON 2 VARIABLES, OPERATORS, EXPRESSIONS, AND USER INPUT

These are reserved words of the C language. For example int, float, if, else, for, while etc.

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

CS313D: ADVANCED PROGRAMMING LANGUAGE

Prepared by: Shraddha Modi

Lecture 2 Tao Wang 1

Objectives. In this chapter, you will:

Creating a C++ Program

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

Computer System and programming in C

Sir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )

Chapter 2: Using Data

Computer Programming : C++

Introduction to C++ Introduction and History. Characteristics of C++

Topic 2: C++ Programming fundamentals

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Programming and Data Structures

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Engineering Problem Solving with C++, Etter/Ingber

UNIT 3 OPERATORS. [Marks- 12]

Fundamental of Programming (C)

UNIT-2 Introduction to C++

Chapter 3: Operators, Expressions and Type Conversion

LECTURE 3 C++ Basics Part 2

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Chapter 2 Basic Elements of C++

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

BRAIN INTERNATIONAL SCHOOL. Term-I Class XI Sub: Computer Science Revision Worksheet

Department of Computer Science

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. C++ Basics

Introduction to Programming EC-105. Lecture 2

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Variables and Operators 2/20/01 Lecture #

C/C++ Programming for Engineers: Working with Integer Variables

Chapter 7. Additional Control Structures

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

CS242 COMPUTER PROGRAMMING

Operators and Type Conversion. By Avani M. Sakhapara Assistant Professor, IT Dept, KJSCE

CHAPTER-6 GETTING STARTED WITH C++

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Work relative to other classes

Will introduce various operators supported by C language Identify supported operations Present some of terms characterizing operators

Transcription:

Lecture 4 1. Programming in C++ Language: C++ was created by Bjarne Stroustrup, beginning in 1979. The development and refinement of C++ was a major effort, spanning the 1980s and most of the 1990s. Finally, in 1998 an ANSI/ISO standard for C++ was adopted. In general terms, C++ is the object-oriented version of C. It soon expanded into being a programming language in its own right. Today, C++ is nearly twice the size of the C language. Needless to say, C++ is one of the most powerful computer languages ever devised. Basic Source Character Set for C++ Language: الا بجدية الا نجليزية الكبيرة 1. English Capital Letters الا بجدية الا نجليزية الصغيرة 2. English Small Letters الارقام العربية Numbers: 3. Arabic العبارات الخاصة (30): Symbols 4. Special 21

Lecture 4 5. Keywords: In C++ are explicitly reserved words that have a strict meaning and may not be used in any other way. They include words used for type declarations, such as int, char, and float; words used for statement syntax, such as do, for, and if; and words used for access control, such as public, protected, and private. 2. The Form of a C++ Program: A program in C++ is a collection of functions and declarations. Global Declarations statements sequence; 22

Lecture 4 The global declarations is refer to library which is the file containing the standard functions that can be used by program. These functions include all I/O operations as well as other useful routines. The keyword main with the parentheses ( ) represented beginning of program execute. The symbols is the block of main command to be execute. The statements sequence; are the instructions used to perform in the program. iostream is library file consist of all instructions of input and output. conio is library file consist of getch function and this function used for outputting result on screen. 3. Output in C++ Program: To print result from C++ program on screen, using this function cout (that means C output), and used insertion operator << to isolates the outputs from each other, ending with; UExample (1)U: write a program in C++ to print on the screen of computer the integer number 5. Ans: First program is: Second program is: Third program is: int x=5; cout<<x; int x=5; cout<<"x= "<<x; cout<<5; 23

Lecture 4 UExample (2): cout<<"my Departement "<<"is"<<" Electrical and"<<" Electronics"<<endl; Question: write a program in C++ to print on the screen of computer your name. 4. Input in C++ Program: To enter values for C++ program, using this function cin (that means C input), and used insertion operator >> to isolates the inputs from each other, ending with; UExample (3): int x; float y,z; char k; cin>>x; cin>>y>>z; cin>>k; cout<<"x= "<<x<<endl; cout<<x<<endl; cout<<y<<" "<<z<<endl; cout<<"y"<<" "<<"z"<<endl; cout<<"k"<<" "<<k<<endl; 24

Lecture 5 1. Comments: C++ language can have comments in the body of program, these comments for explain purpose of program. There are two types of comment in C++ languages: 1. /* C++ program for type my name */. 2. // C++ program for type my name. UExample (1): # include<iostream.h> # include<conio.h> /* Prints my name, my age, my department, my university */ cout<<" Ahmed.\n"; // my name cout<<" 18.\n"; // my age cout<<" Electrical.\n"; // my department cout<<" Technology.\n"; // my university 2. Constants: Constants refer to fixed values that may not be altered by the program. They can be of any data type as: const float pi=3.141; const float cop-dens = 8.9; 25

Lecture 5 3. Data Types: There are five atomic data types in the C++: character, integer, floatingpoint, double floating-point, and valueless. Values of type char are used to hold ASCII characters or any 8-bit quantity. Variables of type int are used to hold integer quantities. Variables of type float and double hold real numbers. (Real numbers have both an integer and a fractional component). 3.1 Type Modifiers: The basic data types may have various modifiers preceding them. A type modifier is used to alter the meaning of the base type to fit the needs of various situations more precisely. The list of modifiers is shown here: signed unsigned long short The modifiers signed, unsigned, long, and short can be applied to UintegerU base types. The UcharacterU base type can be modified by unsigned and signed. You can also apply long to double. Access Modifiers that is used to control the ways in which variables may be accessed or modified. This modifier is called const variable of type const may not be changed during execution by your program. 3.2 Limits of Modifiers: C++ program using sizeof() function to find the limits of modifiers, with standard function limits: 26

Lecture 5 UExample (2): # include <iostream.h> # include <conio.h> # include <limits.h> main () cout<<sizeof (int)<<endl ; cout<<sizeof (char)<<endl ; cout<<sizeof (float)<<endl ; cout<<sizeof (long double)<<endl ; cout<<size of (unsigned short int)<<endl ; getch() ; 27

Lecture 5 4. Identifier Names: The names that are used to reference variables, functions, labels, and various other user defined objects are called identifiers. Identifiers can vary from one to several characters in length. An identifier in C++ is a sequence of letters, digits, and underscores. An identifier cannot begin with a digit. Uppercase and lowercase letters are treated as distinct. It is good practice to choose meaningful names as identifiers. One- or two-letter identifiers can be used when it is obvious what the name is being used for. UExample (3):U determine the types of the words in C++ language: Float, float, 1float, test23, hit!it, Beta, βeta, 5q, Ans: Question: are there the same identifiers: Count, COUNT, and count? 4.1 Declaration of Variables: As you probably know, a variable is a named location in memory that is used to hold a value that can be modified by the program. All variables must be declared before they are used. The general form of a declaration is shown here: 28

Lecture 5 Type variable list; Variable list may consist of one or more identifier names with comma separators. Some declarations are shown here: int i,j,k; char h = 'a'; short int si; unsigned int ahmed; double balance, loss; Question: write the instruction to declaring about: i- integer x and y ii- floating point -1.233432345 iii- character g,h There are three basic places where variables can be declared: Inside functions, in the definition of function parameters, or outside all functions. These variables are called local variables, formal parameters, and global variables, respectively. 29

Lecture 6 C++ Operators: An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations. There are four general classes of operators in C++: arithmetic, relational and logical, and bitwise. In addition, there are some special operators for particular tasks. 1- Arithmetic Operators: The table lists C++ arithmetic operators. The operators +,, *, and / all work the same way in C++ as they do in most other computer languages. They can be applied to almost any built-in data type allowed by C++. When / is applied to an integer or character, any remainder is truncated; for example, 10 / 3 equals 3 in integer division. The 30

Lecture 6 modulus division operator (%) also works in C++ the way it does in other languages. Remember that the modulus division operation yields the remainder of an integer division. However, as such, % cannot be used on type float or double. The reason the last line prints a 0 and 1 is because 1 / 2 in integer division is 0 with a remainder of 1. 1 % 2 yields the remainder 1. The unary minus, in effect, multiplies its single operand by 1. That is, any number preceded by a minus sign switches its sign. UExample (1): main( ) int x,y; cout<< "Enter Two Integers:"; cin>>x>>y; cout<<"the Intergers are:" <<x<<"and"<<y<<endl; cout<<"the sum is " <<(x+y)<<endl; cout<<"the difference is " <<(x-y)<<endl; cout<<"the product is " <<(x*y)<<endl; cout<<"the division is " <<(x/y)<<endl; cout<<"the modulus is " <<(x%y)<<endl; cout<<"the equation is " <<((x+y)/3)<<endl; getch( ); 31

Lecture 6 UExample (2): main( ) int x; float a, v, y=3.14; cout<< "Enter the redial of ball: "; cin>>x; a=(x*x)*y; v=4/3*y*(x*x*x); cout<<"the area of ball is: " <<a<<endl; cout<<"the volume of ball is: " <<v<<endl; getch( ); Increment and Decrement Operator: C++ allows two very useful operators not generally found in other computer languages. These are the Increment (++) and Decrement ( ) operators. The operation ++ adds 1 to its operand, and subtracts 1.Therefore, the following are equivalent operations: x = x + 1; is the same as ++x; or x++; Also, x = x - 1; is the same as --x; or x--; 32

Lecture 6 However, there is a difference when they are used in an expression. When an increment or decrement operator precedes its operand, C++ performs the increment or decrement operation prior to obtaining the operand s value. UExample (3):U write a program in C ++ language to test the operation of arithmetic operators with printing the result appearing on the screen of computer. Ans: //test arithmetic operators: int a=13, b=5; cout<<a<<"+"<<b<<"="<<(a+b)<<endl; cout<<"-b="<<(-b)<<endl; cout<<a<<"*"<<b<<"="<<(a*b)<<endl; cout<<a<<"/"<<b<<"="<<(a/b)<<endl; cout<<a<<"%"<<b<<"="<<(a%b)<<endl; cout<<"a++="<<a++<<endl; cout<<"a++="<<a++<<endl; cout<<"++a="<<++a<<endl; cout<<"--a="<<--a<<endl; cout<<"a--="<<a--<<endl; cout<<"a="<<a<<endl; 33 The result appearing on the screen of computer is: 13+5=18 -b=-5 13*5=65 13/5=2 13%5=3 a++=13 a++=14 ++a=16 --a=15 a--=15 a=14

Lecture 6 UExample (4): #include<iostream> int m, n; cout<<"enter Two Integers:"; cin>>m>>n; cout<<"m="<<m<<",n="<<n<<endl; ++m; --n; cout<<"m="<<m<<",n="<<n<<endl; ++m; --n; cout<<"m="<<m<<",n="<<n<<endl; getch( ); Question: What is the difference between ++a and a++. Question: find the result of the following if int n=7, m=24; i: 37/(5%3) ii: m-8-n iii: m%n++ iv: ++m-n v : m*=n++ vi: m+=--n 34

Lecture 6 Type Conversion: Let data types as: Character char; Integer int; Floating point float; Double float point double. Question: what is the type of output if int x, int y, float z, float d: i- z=x/y; ii- x=z/y; iii- x=z/d; 2- Relational Operators: In the term relational operator the word relational refers to the relationships values can have with one another. The key to the concepts of relational operators is the idea of true and false. In C++, true is any value other than 0. False is 0. Expressions that use relational operators will return 0 for false and 1 for true. 35

Lecture 6 UExample (5):U write a program in C++ language to test the operation of Relational Operators with printing the result appearing on the screen of computer. Ans: // Program to test Relational Operators int A=57, B=57; char C='9'; cout<<(int(c))<<endl; cout<<"(a<57)="<<(a<57)<<endl; cout<<"(a<90)="<<(a<90)<<endl; cout<<"(a<30)="<<(a<30)<<endl; cout<<"(a<=57)="<<(a<=57)<<endl; cout<<"(a>b)="<<(a>b)<<endl; cout<<"(a>=b)="<<(a>=b)<<endl; cout<<"(a==b)="<<(a==b)<<endl; cout<<"(a!=b)="<<(a!=b)<<endl; cout<<"(a==c)="<<(a==c)<<endl; 57 (A<57)=0 (A<90)=1 (A<30)=0 (A<=57)=1 (A>B)=0 (A>=B)=1 (A==B)=1 (A!=B)=0 (A==C)=1 36

Lecture 6 Question: what is the result of following if: a=3, b=3 i- a<3 ii- a<=3 iii- a>b iv- a>=b v- a==b vi- a!=b Question: What is the difference between: a==b and a=b 37