COS120-Ch3-ClassLevel - COS120 Chapter 3 Class-level...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COS120 Chapter 3 Class-level Variables A variable’s scope refers to the blocks of code that can access (use) it and is determined by where it is declared. A variable’s lifetime is the time during which it exists in memory. A variable is created (allocated memory), used, and destroyed (memory returned to the operating system). Typically, a variable is declared within the subroutine that uses it. Its scope is restricted to statements within the subroutine. Its lifetime is the time during which the subroutine executes. This type of variable is called a local variable . Consider the program below which could be used by a clerk to enter a salesperson’s name and amount of sales. The program computes the commission as 5% of sales and displays the information in a list box. The user is able to repeatedly click the button to enter data for a group of salespeople. Sample Output on three salespeople: 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
What this program lacks is the ability to compute statistics for the entire data set. It might be useful to report how many salespeople were processed or sums/averages on the numerical results. The calculations will require use of class-level variables. These variables have scope
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 6

COS120-Ch3-ClassLevel - COS120 Chapter 3 Class-level...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online