NOTES: Variables & Constants (module 10)
|
|
- Hilary Booth
- 5 years ago
- Views:
Transcription
1 Computer Science 110 NAME: NOTES: Variables & Constants (module 10) Introduction to Variables A variable is like a container. Like any other container, its purpose is to temporarily hold or store something. In programming, variables are containers that temporarily hold data. Variable containers hold values in the computer's memory. They act as a placeholder in memory to store a value. The value that is stored in the variable container can change as the program runs. Your code can use one or many variables. Variables can contain words, numbers, dates, properties or object references. Variables are given short, easy-to-remember names that usually describe the piece of data that will be stored. Variables can hold: User information/data entered at run time The result of a calculation performed by the program A piece of data you wish to display on your form The applications that we have created and worked with until now are much more limited than a typical Visual Basic application because they do not allow the user to input any data. Think of the HelloWorld application that we created in the last modue. This application would be much more useful if the user could enter their own English text and then translate that text into French or Spanish at the click of a button! Declaring and Naming Variables We use text boxes and option buttons to get user input. Variables and constants are then used in the code to hold the values that are given to us through these objects. The variable becomes our way of "tracking" data. As we have seen in the last lesson, a variable is a named memory location that stores a value. A good programmer always uses variables. By using variables, the programmer allows values to be represented by meaningful names that make the program code easier to read and follow. Before you can use a variable in your Visual Basic program, you should declare the variable. This is the programmer's way of stating his/her intention to use the variable in the program. Declaring a variable tells Visual Basic about the variable. It tells Visual Basic: What the variable's name is What type of value the variable will contain How much computer memory must be set aside to hold the value that will be placed in the variable In Visual Basic, you may use: Explicit declarations Implicit declarations Explicit declarations One of the ways to create a variable is to declare it explicitly. Normally, you declare a variable explicitly before you use the variable. To make an explicit declaration, use a Dim statement and the variable name. The correct syntax for an explicit declaration is shown on the computer screen to the right. By explicitly declaring a variable, you "reserve room" for the variable in the computer's memory. The declaration statement tells Visual Basic what type of data it can expect to see and how much memory must be set aside to hold the data. You will learn more about Visual Basic data types in upcoming lessons. The following examples show variable declaration statements that apply the correct syntax: Dim inttestscore As Integer Dim strfirstname As String Dim blnbuttonclicked As Boolean
2 When a numeric variable is declared in Visual Basic, it is automatically given the value of zero (0) by default. Once you have declared a variable, you can assign information to it in your program code. To assign a value to a variable means to initialize the variable. To assign data to the variable, you use the equal sign (=) sign. The equal sign is called the assignment operator. Explicit declarations One of the ways to create a variable is to declare it explicitly. Normally, you declare a variable explicitly before you use the variable. To make an explicit declaration, use a Dim statement and the variable name. The correct syntax for an explicit declaration is shown on the computer screen to the right. By explicitly declaring a variable, you "reserve room" for the variable in the computer's memory. The declaration statement tells Visual Basic what type of data it can expect to see and how much memory must be set aside to hold the data. You will learn more about Visual Basic data types in upcoming lessons. The following examples show variable declaration statements that apply the correct syntax: Dim inttestscore As Integer Dim strfirstname As String Dim blnbuttonclicked As Boolean When a numeric variable is declared in Visual Basic, it is automatically given the value of zero (0) by default. Once you have declared a variable, you can assign information to it in your program code. To assign a value to a variable means to initialize the variable. To assign data to the variable, you use the equal sign (=) sign. The equal sign is called the assignment operator. In this course, we will declare all variables using explicit declarations. Naming Variables As a programmer, you must choose names, or identifiers, for your program variables. Variable names: Should be clearly understandable to the reader Should be descriptive of the contents of the variable Should include a three-letter prefix that describes the type of data the variable will hold Regardless of the type of variable, the following rules apply when choosing the variable identifier: Variable names must begin with a letter. Variable names can contain letters, numbers and the underscore (_) character. Variable names can be as long as 255 characters or as short as only one character. Variable names can not be Visual Basic keywords. Keywords are words that have a predefined meaning to the Visual Basic compiler. For example, Double is a Visual Basic keyword. Variable names can not contain spaces, periods and other special characters such as \, *,?, etc. Visual Basic identifiers are not case-sensitive. For example, Count and count represent the same memory location. Visual Basic will always try to maintain consistency, however. It will automatically change the case of an identifier so that it matches the case when it was first used. Therefore, if the variable Count is originally declared with an uppercase C, Visual Basic will automatically change the C to uppercase if the programmer enters it with a lowercase c, as in count. The following are examples of legal variable identifiers: intstrikeouts strthisisacrazyvariablenamebutitislegal dblaveragescore dbltotalsalary dbltaxrate_2003 intsum intx Note: It is good programming style to precede the identifier with a three-letter prefix indicating the data type. The following table shows the data types and their prefixes:
3 Data Type Prefix Single Double Integer Long Currency String sgl dbl int lng cur str Boolean Variable declaration statements reserve space in the computer's memory for a value. Variable Assignment A variable that is declared with a Dimstatement, as in Dim dblaverage As Double is given the value zero (0) by default until it is assigned another value. A variable is initialized, or assigned, a value through an assignment statement. For example: dblaverage = 90.5 Variable assignment statements must be written with the identifier, or variable name, on the left side of the equal sign and the value on the right side of the equal sign, as shown in the above example. In the assignment statement: dblaverage = 90.5 the variable called dblaverage is assigned the value What this really means is that the value 90.5 is stored in the memory location referred to by the name dblaverage. In other words, a place in the computer's memory was set aside to hold a value with the data type Double. That place in memory that is set aside is referenced by the identifier, dblaverage. The value 90.5 is temporarily placed in that location in memory. An expression may also be used on the right side of the equal sign to assign a value to the variable. For example, in the statement: intsum = The expression on the right, , is evaluated to the value of 3 and then the value 3 is assigned to the variable named intsum. Another example of an assignment statement is: dblrate = intsum * 0.15 In this statement, the expression on the right also contains a variable called intsum. A variable can be used wherever a value can be used. When working with variables, it is important to remember two things: 1. A variable can store only one value at any given time. Example #1: Dim dblsum As Double dblsum = 53.1 dblsum = 74.6 The value stored in dblsum is 74.6 because 74.6 is the last value assigned to dblsum and dblsum can only hold one value. 2. The expression on the right of an assignment statement is evaluated first and then its value is given to the variable on the left. Example #2: Dim dblsum As Double dblsum = 2 dblsum = dblsum + 3 bln
4 In the first assignment statement, dblsum is given the value 2. In the second assignment statement, the expression dblsum + 3 is evaluated as 2 + 3, which is 5. The value 5 is then assigned to dblsum, overwriting what was previously stored there (2) in the statement preceding it. Practicing With Variables Follow the instructions below to create a Money Wise! application that will use variables to calculate the total price of an item after the sales tax has been added. 1. Start the Visual Basic IDE. 2. Create a new project. 3. Add objects to the form as shown to the right. Refer to this image when placing and sizing the form and its objects. 4. Use the table to name and set the properties for the objects. Object Name Property Caption Property Form1 frmmoneywise Money Wise! Label1 lblquestion What is my cost when the sales tax is added to an item that is priced at 10 dollars? Label2 lblanswer empty Command1 cmdcalculate Calculate Cost Command2 cmddone Done Once you have named your properties, you should then: 5. Save the project. Choose File Save Project As. In the Save in box, navigate to your Practice folder. In the File name box, type frmmoneywise. Click OK. The Save Project As dialogue box appears. Practice will be showing in the Save in box. In the File name box, type Money Wise. Click OK. 6. Now we will write the program code. Double-click the Calculate object to open the Code window. To create a cmdcalculate_click event procedure, type the following using good programming style: Dim dblitemprice As Double 'declares variable Dim dbltotalprice As Double 'declares variable dblitemprice = 10 dbltotalprice = dblitemprice * dblitemprice lblanswer.caption = dbltotalprice 'Displays the price of the item after tax The code for your event procedure should look exactly like the following:
5 7. Finally, we will write the code for the cmddone_click event procedure. Type the code for the event as follows using proper indenting style: Unload Me 8. Resave your project. 9. Run the application. Click the Calculate Cost button to test the application. The price should be displayed. 10. Click the Done button to end the program. Using Constants A constant is a named memory location that stores a value that cannot be changed at run time. Its initial assignment is never changed. To use a named constant, it must first be declared in a Conststatement, as shown: The following is an example of a statement that declares a constant: Const dblpi As Double = 3.14 This statement declares a constant named dblpi that is of the Double data type and holds a value of In the next exercise, we will modify our Money Wise application and use a constant. 1. Open your Money Wise project. 2. Double click the Calculate Cost button to open the Code window. 3. Change the cmdcalculate_click procedure to match the code, as shown: Notice that two changes were made to the event procedure: A constant was declared in the first statement as follows: Const dbltax As Double = 0.15 The name of the constant (dbltax)replaced 0.15 in the statement dbltotalprice = dblitemprice * dblitemprice So that the modified statement now reads as follows: dbltotalprice = dblitemprice * dbltax + dblitemprice 4. Resave your project.
6 5. Run your application. Did You Know? Good programming style dictates that constants be declared before variable declarations, at the beginning of a procedure. Visual Basic Built-In Data Types Visual Basic 6.0 supports many built-in data types. It is important to choose the correct data type to represent each variable. Remember, a variable acts like a placeholder in the computer's memory. The type of data that a variable will hold determines the amount of memory that will be set aside for the variable. If a variable is declared as an Integer, two bytes of memory must be reserved for it. If a variable is declared as Long, four bytes of memory are reserved for it. A Long data type, therefore, takes up more memory than an Integer data type. To make the best use of your computer's resources and to allow your applications to run efficiently, it is important to choose the most appropriate data type for each variable. It is a waste of resources to declare a variable as a Double, for example, if the value it will contain will always be small enough to be accommodated by an Integer type and will never contain decimals. Visual Basic has five built-in data types. Integer and Long These data types represent both positive and negative integers (whole numbers.) The difference between Integer and Long is in the range of values that can be represented. Integer value ranges are lower Long should be reserved for values higher than or lower than If a value with a decimal portion is assigned to an Integer or Long data type, the value is rounded to a whole number, so precision is lost Single and Double These data types are used to represent positive and negative real numbers, often referred to as floating point numbers, meaning that they contain numbers after the decimal point. As with Integer and Long, the difference between Single and Double is in the range of numbers they each can represent: Single can represent numbers up to 3.4e 38 Double can represent numbers up to 1.8e 308 Currency This data type represents real numbers that are money values. Currency data types can hold numbers up to four decimal places to the right of the decimal because some currencies around the world need this much accuracy String The String data type represents a set of characters. String guidelines: A string can include the letters of the alphabet, digits and any other character such as %, $ and spaces When you assign a value to a String data type, the value must be enclosed in quotation marks (" ") as shown in these examples: Dim strmyname As String strmyname = "Ashley" Dim strmessage As String strmessage = "Sorry, try again." Boolean The Boolean data type is special in that it can only be set to one of two values either True or False. The Boolean data type is useful for representing on/off and yes/no values For example, blnopen would be set to true if open and false if closed Reminder In the lesson titled Declaring and Naming Variables, refer to the section called Naming Variables for a table of three-letter prefixes used to represent the Visual Basic built-in data types.
7 Identify the Correct Variable Declarations Throughout this lesson, you have learned the importance of good programming style. Writing a clear and concise variable declaration is key to being a good programmer. In the two examples shown below, our programmer wrote variable declarations to represent a student: First name Middle name Last name Age GPA (Grade Point Average) Look at both of the examples carefully, and then click on the one that is written correctly and includes good programming style. Check with your teacher to see if you chose correctly. More on Variable Declarations Up until now, we have used the Dim statement to declare one variable per statement. A single Dim statement can also be used to declare multiple variables. For example, the following statement declares several variables of different types with one Dim statement: Dim strcomputersciencestudent As String, intstudentid As Integer, dblavgmark As Double A comma (,) must be used to separate each declaration. Visual Basic initializes (assigns) variables to a default value when the variables are declared: Numeric variables such as Integer, Long, Single, Double and Currency are initialized to zero (0) by default. String variables are initialized to an empty string, or (""), by default. Boolean variables are initialized to False, which is equivalent to zero (0), by default. Test Your Understanding Choose variable names for the following and then write one Dim statement to declare all three variables: Name Age GPA (Grade Point Average) Once you have completed your variable names, check with the teacher. Obtaining a Value From the User An application is more useful when the user is able to input values at run time. These values are then used in the program code as the program executes. For example, in our Money Wise application, the application would be more useful to us if the user could enter the price of an item. The program could then calculate the total price including tax. One way to obtain user input in Visual Basic is to use a text box. A text box object is created, as you learned in the lesson Practicing With Text Boxes, by using the TextBox control in the Toolbox. Text box objects do not have a Caption property. For this reason, a label is usually placed near the text box to describe how it will be used. In the following exercise, we will add a text box to the Money Wise application and then add the code for a change event: 1. Open the Money Wise application and display the MoneyWise form, if it is not already displayed. 2. Change the lblquestion Caption property to display Enter the price of the item:. 3. Add a text box object beside the label and modify the interface so that it is similar to the screen capture that is shown below. 4. Set the Name property of the text box to txtprice. 5. Delete the current text box Text property value so that the Values column is blank for that property.
8 6. Now we will change the program code. Double-click the text box to display the Code window. From the Object list, select General 7. The cursor is now in the General section. Type Option Explicit, if it is not already there, and then press Enter. 8. Modify the cmdcalculate_click event procedure. 9. From the Object list, select txtprice. A txtprice_change ( ) event is added to the code. 10. Add the following lines of code to the txtprice_changeevent procedure: 'Clears price when the user clears text box to type a new price lblanswer.caption = "" 11. Resave the project and run the application.
9 Did You Know? To prevent errors, program code should include the Option Explicit statement in the General section of the Code window so that variables must be declared before they are used. The Option Explicit statement tells Visual Basic to check for an undeclared variable at run time. Option Buttons and Frames In the last lesson, we looked at the use of text boxes as a common way to obtain user input. Option buttons, sometimes called radio buttons, are another way to obtain input from the user. In this lesson, we will learn about option buttons. Option buttons are grouped together. They are designed to provide the user with a set of input choices. Only one option button in the group can be selected at a time. An option button object is created using the OptionButton control in the Toolbox. Properties are then set for this object just as we have done for other objects that we created. Option buttons are usually coded with a click event. The click event procedure is executed when the user clicks on an option button. A frame is a container object. The frame container is used to group option buttons. An example of a frame containing option buttons is shown above. In this example, the option buttons for choosing a grade were placed in a frame with the caption Grade. Frames are created using the Frame control in the Toolbox. A frame must be created first and then the option buttons are added to it. When adding option buttons to a frame, they are drawn with the OptionButton control and then dragged to the desired position within the frame. When option buttons are drawn in the frame in this way, both the frame and the option buttons will move together when the frame is dragged to a new location on the form. Hello World! Redesign In this next exercise, we are going to redesign the Hello, World! application. 1. Open the Visual Basic development environment. 2. Create a new project. 3. Design a new form that looks like the following:
10 4. Set the properties for the objects as shown in the chart: Object Name Caption Font Alignment Form1 frmhellointernational Hello From Around the World! Label1 lblmessage empty Bold, 18pt Center Frame1 fralanguage Select a language Command1 cmddone Done 10pt Option1 optenglish English 10pt Option2 optspanish Spanish 10pt Option3 optfrench French 10pt 5. Save the project in your Practice folder as follows: 1. Save the form as frmhellointernational 2. Save the project as Hello International 6. Now we will add the click event procedures for the three option buttons. 7. Double-click the English option button to display the Code window. 8. Add the following code statement to the optenglish_click procedure: lblmessage.caption = "Hello, world!" 9. Double-click the Spanish button and add the following code statement to the optspanish_click procedure: lblmessage.caption = "Hola mundo!" 10. Double-click the French button and add the following code statement to the optfrench_click procedure: lblmessage.caption = "Bonjour monde!" 11. To make English the default language when the application starts, code must be added to the Form_Load event procedure. Open the Code window. Choose Form from the object drop-down list as shown: Make sure the Load event is selected from the Event drop-down list on the right, as shown in the image above. 12. Add the following code statements to the Form_Load event procedure. optenglish.value = True lblmessage.caption = "Hello, world!" 13. Finally, double-click the Done button and we will add a cmddone_click event procedure with the following code: Unload Me 14. Your Code window, with the complete code, should look like:
11 15. Resave your project. 16. Run the application. Click each option button to see the program in operation. Click the Done button to end the program. 17. Close Visual Basic. Option Explicit The syntax rules of most major programming languages force the programmer to declare a variable before it can be used. In Visual Basic, declaring variables with the Dim statement is optional. However, it is strongly recommended that you declare all variables before using them. Using the Option Explicit statement forces you to declare all variables. To use Option Explicit, follow these steps: 1. From the Code window, click on the object box drop-down arrow and select General, as shown above. 2. A clear area in the Code window will appear. Type the following into this area and press Enter. Option Explicit Once Option Explicit has been added to your program, you must declare all variables before using them or Visual Basic will report an error at run-time with the message "Variable not defined." One advantage of using Option Explicit is that if you mistype a variable name, Visual Basic will detect it immediately. This can be very useful as this type of error is usually hard to find.
VARIABLES. 1. STRINGS Data with letters and/or characters 2. INTEGERS Numbers without decimals 3. FLOATING POINT NUMBERS Numbers with decimals
VARIABLES WHAT IS A VARIABLE? A variable is a storage location in the computer s memory, used for holding information while the program is running. The information that is stored in a variable may change,
More informationProgramming Language 2 (PL2)
Programming Language 2 (PL2) 337.1.1 - Explain rules for constructing various variable types of language 337.1.2 Identify the use of arithmetical and logical operators 337.1.3 Explain the rules of language
More informationFull file at
Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class
More informationNOTES: Procedures (module 15)
Computer Science 110 NAME: NOTES: Procedures (module 15) Introduction to Procedures When you use a top-down, structured program design, you take a problem, analyze it to determine what the outcome should
More informationIntroduction to Data Entry and Data Types
212 Chapter 4 Variables and Arithmetic Operations STEP 1 With the Toolbox visible (see Figure 4-21), click the Toolbox Close button. The Toolbox closes and the work area expands in size.to reshow the Toolbox
More informationBASIC ELEMENTS OF A COMPUTER PROGRAM
BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators
More informationVariables and Constants
87 Chapter 5 Variables and Constants 5.1 Storing Information in the Computer 5.2 Declaring Variables 5.3 Inputting Character Strings 5.4 Mistakes in Programs 5.5 Inputting Numbers 5.6 Inputting Real Numbers
More informationObjectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program
Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates
More informationChapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction
Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers
More informationprintf( Please enter another number: ); scanf( %d, &num2);
CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful
More informationVisual C# Instructor s Manual Table of Contents
Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms
More informationLESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:
LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words
More informationVISUAL BASIC 6.0 OVERVIEW
VISUAL BASIC 6.0 OVERVIEW GENERAL CONCEPTS Visual Basic is a visual programming language. You create forms and controls by drawing on the screen rather than by coding as in traditional languages. Visual
More informationData and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence
Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public
More informationChapter 2 Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion
More informationMicrosoft Visual Basic 2015: Reloaded
Microsoft Visual Basic 2015: Reloaded Sixth Edition Chapter Three Memory Locations and Calculations Objectives After studying this chapter, you should be able to: Declare variables and named constants
More informationThe C++ Language. Arizona State University 1
The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University
More information12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.
Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started
More informationC++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.
EEE-117 COMPUTER PROGRAMMING Basic Elements of C++ Objectives General Questions Become familiar with the basic components of a C++ program functions, special symbols, and identifiers Data types Arithmetic
More informationComputational Expression
Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name
More informationSKILL AREA 306: DEVELOP AND IMPLEMENT COMPUTER PROGRAMS
Add your company slogan SKILL AREA 306: DEVELOP AND IMPLEMENT COMPUTER PROGRAMS Computer Programming (YPG) LOGO 306.1 Review Selected Programming Environment 306.1.1 Explain the concept of reserve words,
More informationObjectives. In this chapter, you will:
Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about
More informationBIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic
BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines
More informationNotes on Chapter 1 Variables and String
Notes on Chapter 1 Variables and String Note 0: There are two things in Python; variables which can hold data and the data itself. The data itself consists of different kinds of data. These include numbers,
More informationComputer Science 110. NOTES: module 8
Computer Science 110 NAME: NOTES: module 8 Introducing Objects As we have seen, when a Visual Basic application runs, it displays a screen that is similar to the Windows-style screens. When we create a
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine
More informationVariables and Literals
C++ By 4 EXAMPLE Variables and Literals Garbage in, garbage out! To understand data processing with C++, you must understand how C++ creates, stores, and manipulates data. This chapter teaches you how
More informationLanguage Fundamentals
Language Fundamentals VBA Concepts Sept. 2013 CEE 3804 Faculty Language Fundamentals 1. Statements 2. Data Types 3. Variables and Constants 4. Functions 5. Subroutines Data Types 1. Numeric Integer Long
More information1.1 Introduction to C Language. Department of CSE
1.1 Introduction to C Language 1 Department of CSE Objectives To understand the structure of a C-Language Program To write a minimal C program To introduce the include preprocessor command To be able to
More informationSlide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto
CS 170 Java Programming 1 The Switch Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Menu-Style Code With ladder-style if-else else-if, you might sometimes find yourself writing menu-style
More informationC++ Programming: From Problem Analysis to Program Design, Third Edition
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine
More informationVARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.
Lesson 2 VARIABLES Aim Understanding how computer programs store values, and how they are accessed and used in computer programs. WHAT ARE VARIABLES? When you input data (i.e. information) into a computer
More informationIntroduction to Programming in Turing. Input, Output, and Variables
Introduction to Programming in Turing Input, Output, and Variables The IPO Model The most basic model for a computer system is the Input-Processing-Output (IPO) Model. In order to interact with the computer
More informationLecture 2 Tao Wang 1
Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors
More informationVisual C# Program: Resistor Sizing Calculator
C h a p t e r 4 Visual C# Program: Resistor Sizing Calculator In this chapter, you will learn how to use the following Visual C# Application functions to World Class standards: Opening Visual C# Editor
More informationMicrosoft Visual Basic 2005: Reloaded
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations Objectives After studying this chapter, you should be able to: Declare variables and named
More informationAgenda & Reading. VB.NET Programming. Data Types. COMPSCI 280 S1 Applications Programming. Programming Fundamentals
Agenda & Reading COMPSCI 80 S Applications Programming Programming Fundamentals Data s Agenda: Data s Value s Reference s Constants Literals Enumerations Conversions Implicitly Explicitly Boxing and unboxing
More informationProgram Planning, Data Comparisons, Strings
Program Planning, Data Comparisons, Strings Program Planning Data Comparisons Strings Reading for this class: Dawson, Chapter 3 (p. 80 to end) and 4 Program Planning When you write your first programs,
More informationvariables programming statements
1 VB PROGRAMMERS GUIDE LESSON 1 File: VbGuideL1.doc Date Started: May 24, 2002 Last Update: Dec 27, 2002 ISBN: 0-9730824-9-6 Version: 0.0 INTRODUCTION TO VB PROGRAMMING VB stands for Visual Basic. Visual
More informationChapter 2 Working with Data Types and Operators
JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics
More informationIntroduction to the C++ Programming Language
LESSON SET 2 Introduction to the C++ Programming Language OBJECTIVES FOR STUDENT Lesson 2A: 1. To learn the basic components of a C++ program 2. To gain a basic knowledge of how memory is used in programming
More informationFeatures of C. Portable Procedural / Modular Structured Language Statically typed Middle level language
1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC
More informationCS242 COMPUTER PROGRAMMING
CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing
More informationChapter 2.5 Writing maintainable programs
Chapter 2.5 Writing maintainable programs Good program writing techniques Maintenance is the updating of a program after it has been released. Maintenance will be helped when the programmer uses good programming
More informationLesson 2A Data. Data Types, Variables, Constants, Naming Rules, Limits. A Lesson in Java Programming
Lesson 2A Data Data Types, Variables, Constants, Naming Rules, Limits A Lesson in Java Programming Based on the O(N)CS Lesson Series License for use granted by John Owen to the University of Texas at Austin,
More informationREVIEW. The C++ Programming Language. CS 151 Review #2
REVIEW The C++ Programming Language Computer programming courses generally concentrate on program design that can be applied to any number of programming languages on the market. It is imperative, however,
More informationIT 374 C# and Applications/ IT695 C# Data Structures
IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation
More informationVariables and Constants
HOUR 3 Variables and Constants Programs need a way to store the data they use. Variables and constants offer various ways to work with numbers and other values. In this hour you learn: How to declare and
More informationCHAPTER 7 OBJECTS AND CLASSES
CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and
More informationCSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018
CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values
More informationApproximately a Final Exam CPSC 206
Approximately a Final Exam CPSC 206 Sometime in History based on Kelley & Pohl Last name, First Name Last 4 digits of ID Write your section number: All parts of this exam are required unless plainly and
More informationProgramming Logic and Design Seventh Edition Chapter 2 Elements of High-Quality Programs
Programming Logic and Design Chapter 2 Elements of High-Quality Programs Objectives In this chapter, you will learn about: Declaring and using variables and constants Assigning values to variables [assignment
More informationUniversity of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.
University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Second week Variables Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable.
More information9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C
Overview The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More informationCST112 Variables Page 1
CST112 Variables Page 1 1 3 4 5 6 7 8 Processing: Variables, Declarations and Types CST112 The Integer Types A whole positive or negative number with no decimal positions May include a sign, e.g. 10, 125,
More informationLab # 02. Basic Elements of C++ _ Part1
Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special
More informationOverview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program
Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of
More informationPerl Basics. Structure, Style, and Documentation
Perl Basics Structure, Style, and Documentation Copyright 2006 2009 Stewart Weiss Easy to read programs Your job as a programmer is to create programs that are: easy to read easy to understand, easy to
More informationIntroduction to Java Unit 1. Using BlueJ to Write Programs
Introduction to Java Unit 1. Using BlueJ to Write Programs 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save
More informationThe C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)
The C Programming Language (with material from Dr. Bin Ren, William & Mary Computer Science) 1 Overview Motivation Hello, world! Basic Data Types Variables Arithmetic Operators Relational Operators Assignments
More informationEx: If you use a program to record sales, you will want to remember data:
Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T$1.00. Customer Name:
More informationVisual C# Program: Temperature Conversion Program
C h a p t e r 4B Addendum Visual C# Program: Temperature Conversion Program In this chapter, you will learn how to use the following Visual C# Application functions to World Class standards: Writing a
More informationBasic Computation. Chapter 2
Basic Computation Chapter 2 Outline Variables and Expressions The Class String Keyboard and Screen I/O Documentation and Style Variables Variables store data such as numbers and letters. Think of them
More informationChapter-8 DATA TYPES. Introduction. Variable:
Chapter-8 DATA TYPES Introduction To understand any programming languages we need to first understand the elementary concepts which form the building block of that program. The basic building blocks include
More informationMicrosoft Word Training. IT ESSENTIALS Managing Large Documents Using Word 2013 (IS165) October 2015
Microsoft Word Training IT ESSENTIALS Managing Large Documents Using Word 0 (IS) October 0 Book online at: Royalholloway.ac.uk/it/training Self-Study packs also available th October 0 Table of Contents
More informationLanguage Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */
Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,
More informationBasics of Java Programming
Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement
More informationThe Java Language Rules And Tools 3
The Java Language Rules And Tools 3 Course Map This module presents the language and syntax rules of the Java programming language. You will learn more about the structure of the Java program, how to insert
More informationJava Notes. 10th ICSE. Saravanan Ganesh
Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses
More informationUnit-II Programming and Problem Solving (BE1/4 CSE-2)
Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite
More information5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.
Today! Build HelloWorld yourself in BlueJ and Eclipse. Look at all the Java keywords. Primitive Types. HelloWorld in BlueJ 1. Find BlueJ in the start menu, but start the Select VM program instead (you
More informationData Types and Variables in C language
Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are
More informationDiscussion 1H Notes (Week 2, 4/8) TA: Brian Choi Section Webpage:
Discussion 1H Notes (Week 2, 4/8) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 Variables You have to instruct your computer every little thing it needs to do even
More informationVariables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park
Variables in C CMSC 104, Fall 2012 John Y. Park 1 Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement 2 What Are Variables in C? Variables in C have the
More informationProgrammers should write code that is self-documenting and split into small sections.
Writing Programs What are good program writing techniques? Programmers should write code that is self-documenting and split into small sections. Specifically, the programmers should: use meaningful identifier
More information(Refer Slide Time: 00:23)
In this session, we will learn about one more fundamental data type in C. So, far we have seen ints and floats. Ints are supposed to represent integers and floats are supposed to represent real numbers.
More informationProgramming Lecture 3
Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements
More informationSoftware and Programming 1
Software and Programming 1 Lab 1: Introduction, HelloWorld Program and use of the Debugger 17 January 2019 SP1-Lab1-2018-19.pptx Tobi Brodie (tobi@dcs.bbk.ac.uk) 1 Module Information Lectures: Afternoon
More informationVariables, expressions and statements
Variables, expressions and statements 2.1. Values and data types A value is one of the fundamental things like a letter or a number that a program manipulates. The values we have seen so far are 2 (the
More informationChapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1
Chapter 2 Input, Processing, and Output Fall 2016, CSUS Designing a Program Chapter 2.1 1 Algorithms They are the logic on how to do something how to compute the value of Pi how to delete a file how to
More informationCHAPTER 7 OBJECTS AND CLASSES
CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and
More informationChapter 2 THE STRUCTURE OF C LANGUAGE
Lecture # 5 Chapter 2 THE STRUCTURE OF C LANGUAGE 1 Compiled by SIA CHEE KIONG DEPARTMENT OF MATERIAL AND DESIGN ENGINEERING FACULTY OF MECHANICAL AND MANUFACTURING ENGINEERING Contents Introduction to
More informationVariable A variable is a value that can change during the execution of a program.
Declare and use variables and constants Variable A variable is a value that can change during the execution of a program. Constant A constant is a value that is set when the program initializes and does
More informationFirst Visual Basic Lab Paycheck-V1.0
VISUAL BASIC LAB ASSIGNMENT #1 First Visual Basic Lab Paycheck-V1.0 Copyright 2013 Dan McElroy Paycheck-V1.0 The purpose of this lab assignment is to enter a Visual Basic project into Visual Studio and
More informationChapter 2: Using Data
Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time
More informationFundamentals of Programming CS-110. Lecture 2
Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout
More informationVARIABLES AND CONSTANTS
UNIT 3 Structure VARIABLES AND CONSTANTS Variables and Constants 3.0 Introduction 3.1 Objectives 3.2 Character Set 3.3 Identifiers and Keywords 3.3.1 Rules for Forming Identifiers 3.3.2 Keywords 3.4 Data
More informationExercise: Inventing Language
Memory Computers get their powerful flexibility from the ability to store and retrieve data Data is stored in main memory, also known as Random Access Memory (RAM) Exercise: Inventing Language Get a separate
More informationCSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York
CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this
More informationJava How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.
Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;
More informationStart Visual Basic. Session 1. The User Interface Form (I/II) The Visual Basic Programming Environment. The Tool Box (I/II)
Session 1 Start Visual Basic Use the Visual Basic programming environment Understand Essential Visual Basic menu commands and programming procedure Change Property setting Use Online Help and Exit Visual
More informationDecision Structures. Start. Do I have a test in morning? Study for test. Watch TV tonight. Stop
Decision Structures In the programs created thus far, Visual Basic reads and processes each of the procedure instructions in turn, one after the other. This is known as sequential processing or as the
More informationDATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)
Technology & Information Management Instructor: Michael Kremer, Ph.D. Database Program: Microsoft Access Series DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) AGENDA 3. Executing VBA
More informationAnnotation Annotation or block comments Provide high-level description and documentation of section of code More detail than simple comments
Variables, Data Types, and More Introduction In this lesson will introduce and study C annotation and comments C variables Identifiers C data types First thoughts on good coding style Declarations vs.
More information13 FORMATTING WORKSHEETS
13 FORMATTING WORKSHEETS 13.1 INTRODUCTION Excel has a number of formatting options to give your worksheets a polished look. You can change the size, colour and angle of fonts, add colour to the borders
More informationMicrosoft Office 2011 for Mac: Introductory Q&As Excel Chapter 3
Microsoft Office 2011 for Mac: Introductory Q&As Excel Chapter 3 What if Excel automatically opens a workbook when I start Excel? (EX 139) If you had a workbook open when you last quit Excel, Excel will,
More informationUnit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School
Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions Mr. Dave Clausen La Cañada High School Vocabulary Variable- A variable holds data that can change while the program
More informationUnit: Rational Number Lesson 3.1: What is a Rational Number? Objectives: Students will compare and order rational numbers.
Unit: Rational Number Lesson 3.: What is a Rational Number? Objectives: Students will compare and order rational numbers. (9N3) Procedure: This unit will introduce the concept of rational numbers. This
More informationInitial Coding Guidelines
Initial Coding Guidelines ITK 168 (Lim) This handout specifies coding guidelines for programs in ITK 168. You are expected to follow these guidelines precisely for all lecture programs, and for lab programs.
More information