Professional Documents
Culture Documents
COMPUTER SCIENCE PROGRAM Chapter 6 - II
COMPUTER SCIENCE PROGRAM Chapter 6 - II
Computer Programming
(CSC425)
by
PUAN AFIZA ISMAIL
Faculty of Computer & Mathematical Sciences
UiTM MALAYSIA
2013
1
Function II
Chapter 6
2
Contents
Calculate Grade.
This program has 3 functions :
1. main
a. get the course score
b. print the course grade
2. getScore
a. prompt the user for the input
b. get the input
c. print the course score
3. printGrade
a. calculate the course grade
b. print the course grade
October 1, 2013 CSC425 : INTRODUCTION TO COMPUTER 19
PROGRAMMING
6.2
The scope of an identifier
• the scope of variables declared within a function or
any other block of instructions can only be used by
the own function and cannot be used outside of
them.
#include <iostream.h>
int main ()
{
int z; z is local variables to the
z = addition (5,3); function addition.
cout << "The result is " << z;
return 0;
}
#include <iostream.h>
int main()
{
float number = 34.7; // a local variable named
number
cout << “The value of number is “<< number << endl;
return 0;
}
int main()
{
float number = 34.7; // a local variable named
number
cout << “The value of number is “<< ::number << endl;
return 0;
}
October 1, 2013 CSC425 : INTRODUCTION TO COMPUTER 23
PROGRAMMING