Computer Science

Variable Program

A variable program is a computer program that uses variables to store and manipulate data. Variables are named memory locations that can hold different values during program execution. The use of variables allows programs to be more flexible and adaptable to different situations.

Written by Perlego with AI-assistance

4 Key excerpts on "Variable Program"

  • Book cover image for: Computer Science
    eBook - PDF

    Computer Science

    A Concise Introduction

    • Ian Sinclair(Author)
    • 2014(Publication Date)
    • Newnes
      (Publisher)
    If a program deals with export billing, for example, then the conversion from local currency to foreign currency has to be done, and this conversion rate should be the rate prevailing on the day. A constant cannot be used here, because the rate is not fixed and will have to be entered by the operator each day, perhaps twice per day. If your program writes letters to clients, the name of the sender is a constant, but the name of the recipient is a variable, entered by the user or drawn from a list that is held on a disk. Simple variables are mainly number or string in nature, and, like constants, they are stored in the memory and referred to by name. The difference is that when the program starts running each day the storage places for the variable contain nothing. A name for a variable means nothing until the operator, the program, or a value read from the backing store has supplied a number, word or phrase, and the program can be designed so that the operator will be asked to supply this information, either by typing or by inserting a disk. A variable is an assigned quantity, meaning that the place where it is stored is fixed, and a name is provided, but a quantity, number or words, has to be placed in the memory and so assigned to the name. The action of assignment of a value to a variable name is therefore a very important part of any programming language. Variables can be used also for measured quantities, for graphics and for sound; all, of course, coded into number forms. If the computer is being used as part of a control system in a chemical process, the input might be a set of signals that expressed the results of an analysis. These signals would be coded and stored as a variable to be used by the program. When a new set of signals became available, the variable value would be accordingly changed, and the program would now use this new value.
  • Book cover image for: Programming Logic and Design, Introductory
    Copyright 2016 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. 75 Chapter Summary Chapter Summary • Programs contain data in three different forms: literals (or unnamed constants), vari- ables, and named constants. Each of these types of data can be numeric or string. Variables are named memory locations, the contents of which can vary. A variable dec- laration includes a data type and an identifier; optionally, it can include an initialization. Every computer programming language has its own set of rules for naming variables; however, all variable names must be written as one word without embedded spaces and should have appropriate meaning. A named constant is similar to a variable, except it can be assigned a value only once. • Most programming languages use 1, 2, *, and / as the four standard arithmetic opera- tors. Every operator follows rules of precedence that dictate the order in which opera- tions in the same statement are carried out; multiplication and division always take precedence over addition and subtraction. The rules of precedence can be overridden using parentheses. • Programmers break down programming problems into smaller, cohesive units called modules, subroutines, procedures, functions, or methods. To execute a module, you call it from another program or module. Any program can contain an unlimited number of modules, and each module can be called an unlimited number of times. Modularization provides abstraction, allows multiple programmers to work on a problem, and makes it easier for you to reuse work. The false statement is #1. A program comment is a written explanation that is not part of the program logic but that serves as documentation for those reading the program. A prompt is a message that is displayed on a monitor to ask the user for a response and perhaps explain how that response should be formatted. TWO TRUTHS & A LIE Features of Good Program Design 1.
  • Book cover image for: Programming in Visual Basic 2010
    eBook - PDF

    Programming in Visual Basic 2010

    The Very Beginner's Guide

    A variable is a storage container for your data. Many types of variables exist, each with a specific use, or what programmers call a data type . That is, each type is designed to store a particular type of data. Some store whole numbers, integers. Some store numbers with decimals. Some are for dates; some store text, in what programmers call strings . There are a few other types as well, but, for now, we’ll stick with a few basic data types. To make use of these containers, you first have to create them. In programming this is called declaration . You write a statement that creates a variable. To change the value in a variable, use an assignment . This is where the rules of programming take over, in what’s called syntax . Nearly every statement you write in your code has to follow very strict rules. Often the hardest part of programming is getting your commands written in a way the computer understands. For the most part, we’ll try very hard to keep it simple. First, let’s look at declarations. 40 Programming in Visual Basic 2010 shoTest Ø Figure 2.2 Initialized Storage Container To create a variable, let’s say, one to store your last test score, use a statement something like this: Dim shoTest as Short There are other ways to do it, but this is about as simple as it gets. You write a statement that creates a variable, gives the variable a name, and tells the computer what type of data can be stored in it. In this statement, “Dim,” short for dimension, tells the computer to set aside some memory. shoTest is the name of the variable. You’ll use this name every time you work with it. Think of it in the same way you think of n in a math equation. As Short tells the computer what type of data will be stored in the variable, in this case a Short (see Table 2.3 for more on this). When you run the program, this line creates a container called shoTest. It will store Short variables, which simply means it will store whole numbers from –32,768 to 32,767.
  • Book cover image for: Beginning Programming All-in-One For Dummies
    • Wallace Wang(Author)
    • 2022(Publication Date)
    • For Dummies
      (Publisher)
    Every program needs to use variables, but not every program needs to use constants. After you understand how to store data temporarily in variables, your program can start manipulating that data to do something useful. Defining the Scope of a Variable The scope of a variable defines which part of your program can store and retrieve data in a variable. Because variables store data that your program needs to work correctly, your program must make sure that no other part of the program acci- dentally modifies that data. If your program stores a person’s credit card number in a variable, you don’t want another part of your program to accidentally retrieve that data and change the numbers around or send a hundred copies of each credit card number to custom- ers outside the company. So, when creating variables, limit the variables’ scope. The scope simply defines which parts of your program can access a variable. When you declare a variable, you also define one of three possible scope levels for that variable: » Global » Module » Subprogram 136 BOOK 2 Programming Basics Handling global variables with care In a global variable, any part of your program can access that variable, including storing new data in that variable (and wiping out any existing data already stored in that variable), changing the data in a variable, or wiping out the data in a vari- able altogether, as shown in Figure 2-5. Use global variables sparingly. If you create a global variable and some part of your program keeps modifying that variable’s data by mistake, you have to search through your entire program to find which command is messing up that variable. If you have a million-line program, guess what? You have to examine a million lines of code to find the one line that’s changing that variable by mistake. If that’s your idea of fun, go ahead and use global variables.
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.