chapter 5 n.
Download
Skip this Video
Download Presentation
Chapter 5

Loading in 2 Seconds...

play fullscreen
1 / 12

Chapter 5 - PowerPoint PPT Presentation


  • 210 Views
  • Uploaded on

Chapter 5. Names Variables Scope Lifetime. Outline. Some Exercises in C++ Names Variables Scope Lifetime. Some Exercises in C++. اكتب برنامج يستطيع حساب مساحة المستطيل حيث أن الطول و العرض يقوم المستخدم بادخاله، علما بان مساحة المستطيل = الطول * العرض.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Chapter 5' - camdyn


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
chapter 5

Chapter 5

Names

Variables

Scope

Lifetime

outline
Outline
  • Some Exercises in C++
  • Names
  • Variables
  • Scope
  • Lifetime
some exercises in c
Some Exercises in C++
  • اكتب برنامج يستطيع حساب مساحة المستطيل حيث أن الطول و العرض يقوم المستخدم بادخاله، علما بان مساحة المستطيل = الطول * العرض.
  • اكتب برنامج يقوم بحساب معدل الصرف الاسبوعي لشخص ما؟
names
Names
  • Names
    • Names are associated with variable ,lables ,sub-programs , formal parameters and other program constructs such as class.
    • Design issues=
      • Are the names case-sensitive ?
names1
Names
  • Ok ? what is a name in a programming language ?
    • It’s a string of characters used to identify some entities in a program .
names2
Names

Fortran : allows space in names sum of salaries sum of salaries .

C++ : case –sensitive

Rose ≠ ROSE ≠ rose

This will take us back to How can we evaluate any language by writbility and readability .

names3
Names

اﻟﻜﻠﻤﺎت اﻟﻤﺤﺠﻮزة (Reserved words )

names4
Names

How to name in C++:

  •  names must begin with a letter of the alphabet or an underscore( _ )
  • After the first initial letter, variable names can also contain letters and numbers.  No spaces or special characters, however, are allowed.
  • Uppercase characters are distinct from lowercase characters.  Using all uppercase letters is used primarily to identify constant variables. 
  • You cannot use a C++ keyword (reserved word) as a variable name
variable
Variable
  • It  is a storage location and an associated symbolic name (an identifier) which contains some known or unknown quantity or information, a value
  • Attributes
    • Names: same conditions previously.
    • Type= int , char, float, double, …..
    • Address: the place in the memory.
    • Value: content of the memory.
scope
Scope

Scope

Every variable has a scope : So the scope of a variable is the range of statements in which the variable is visible .

  • The scope of a variable is from its declaration to the end of the method.
lifetime
Lifetime
  • The lifetime of a variable is the period of time beginning when the method is entered and ending when execution of the method terminates.
slide12

#include<iostream>

using namespace std;

int main()

{

intx = 10 ;

int grade;

Sum();

cout << “Grade” << grade ;

for (inti =0; i<5 ; i++)

{ cout << “ Test “ ; }

}

void Sum()

{

intx = 100 ;

cout <<“ X = “ <<x ;

}

ad