Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic

Similar documents
Tutorial 5 Completing the Inventory Application Introducing Programming

Classes in C# namespace classtest { public class myclass { public myclass() { } } }

Tutorial 19 - Microwave Oven Application Building Your Own Classes and Objects

User-Defined Controls

Flag Quiz Application

This is the start of the server code

Web Services in.net (2)

Inheriting Windows Forms with Visual C#.NET

Introduction to C# Applications

Chapter 2: Using Data

Polymorphism. Polymorphism. CSC 330 Object Oriented Programming. What is Polymorphism? Why polymorphism? Class-Object to Base-Class.

CALCULATOR APPLICATION

1. Windows Forms 2. Event-Handling Model 3. Basic Event Handling 4. Control Properties and Layout 5. Labels, TextBoxes and Buttons 6.

ListBox. Class ListBoxTest. Allows users to add and remove items from ListBox Uses event handlers to add to, remove from, and clear list

CSC 330 Object-Oriented Programming. Encapsulation

LECTURE 3 C++ Basics Part 2

Visual C# Instructor s Manual Table of Contents

Introduction to Programming Using Java (98-388)

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Arrays. Arrays: Declaration and Instantiation. Array: An Array of Simple Values

Lampiran B. Program pengendali

namespace Tst_Form { private: /// <summary> /// Required designer variable. /// </summary> System::ComponentModel::Container ^components;

Convertor Binar -> Zecimal Rosu Alin, Calculatoare, An2 Mod de Functionare: Am creat un program, in Windows Form Application, care converteste un

Operators. Lecture 3 COP 3014 Spring January 16, 2018

An array can hold values of any type. The entire collection shares a single name

Lesson 02 Working with Data Types MIT 31043, Visual Programming By: S. Sabraz Nawaz

In order to create your proxy classes, we have provided a WSDL file. This can be located at the following URL:

Lesson 02 Working with Data Types. MIT 31043: VISUAL PROGRAMMING By: S. Sabraz Nawaz Senior Lecturer in MIT

Objectives. Introduce the core C# language features class Main types variables basic input and output operators arrays control constructs comments

Blank Form. Industrial Programming. Discussion. First Form Code. Lecture 8: C# GUI Development

Operatii pop si push-stiva

First start a new Windows Form Application from C# and name it Interest Calculator. We need 3 text boxes. 4 labels. 1 button

VB FUNCTIONS AND OPERATORS

Chapter 2: Using Data

.Net Technologies. Components of.net Framework

Web Services in.net (7)

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Full file at

JAVA OPERATORS GENERAL

DigiPen Institute of Technology

Sub To Srt Converter. This is the source code of this program. It is made in C# with.net 2.0.

1.3b Type Conversion

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Fundamentals of Programming

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Programming in C++ 5. Integral data types

By the end of this section you should: Understand what the variables are and why they are used. Use C++ built in data types to create program

Operators. Java operators are classified into three categories:

CIS133J. Working with Numbers in Java

You can call the project anything you like I will be calling this one project slide show.

Microsoft Visual Basic 2005: Reloaded

Visual Studio.NET.NET Framework. Web Services Web Forms Windows Forms. Data and XML classes. Framework Base Classes. Common Language Runtime

Basics of Java Programming

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Computer Programming CS F111

C# Types. Industrial Programming. Value Types. Signed and Unsigned. Lecture 3: C# Fundamentals

Industrial Programming

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

CMPT 125: Lecture 3 Data and Expressions

Web Services in.net (6) cont d

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

C++ Programming: From Problem Analysis to Program Design, Third Edition

CSIS 1624 CLASS TEST 6

C# Fundamentals. Hans-Wolfgang Loidl School of Mathematical and Computer Sciences, Heriot-Watt University, Edinburgh

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Basic Operations jgrasp debugger Writing Programs & Checkstyle

II. Programming Technologies

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Course PJL. Arithmetic Operations

Avoiding KeyStrokes in Windows Applications using C#

A flow chart is a graphical or symbolic representation of a process.

and event handlers Murach's C# 2012, C6 2013, Mike Murach & Associates, Inc. Slide 1

COMP Primitive and Class Types. Yi Hong May 14, 2015

Chapter 3 Structure of a C Program

12/14/2016. Errors. Debugging and Error Handling. Run-Time Errors. Debugging in C# Debugging in C# (continued)

Values, Variables, Types & Arithmetic Expressions. Agenda

The Payroll User Interface: MODEL VIEW PRESENTER

Chapter 3: Operators, Expressions and Type Conversion

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Introduction to Microsoft.NET

BASIC ELEMENTS OF A COMPUTER PROGRAM

Chapter 2: Introduction to C++

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

C#: framework overview and in-the-small features

CHAPTER 3 BASIC INSTRUCTION OF C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Midterms Save the Dates!

DAD Lab. 1 Introduc7on to C#

Lecture 3 Tao Wang 1

Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Unit 3. Operators. School of Science and Technology INTRODUCTION

Expressions and Casting

The Open Core Interface SDK has to be installed on your development computer. The SDK can be downloaded at:

Java Primer 1: Types, Classes and Operators

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

SOFTWARE DEVELOPMENT 1. Operators 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)

Transcription:

Tutorial 6 Enhancing the Inventory Application Introducing Variables, Memory Concepts and Arithmetic Outline 6.1 Test-Driving the Enhanced Inventory Application 6.2 Variables 6.3 Handling the TextChanged Event 6.4 Memory Concepts 6.5 Arithmetic 1

2 Objectives In this tutorial, you will learn to: Create variables. Handle the TextChanged event. Apply basic memory concepts using variables. Use the precedence rules of arithmetic operators. Set breakpoints to debug applications.

6.1 Test-Driving the Enhanced Inventory Application 3 Application Requirements The inventory manager notices a flaw in your Inventory application. Although the application calculates the correct result, that result continues to display even after new data is entered. The only time the output changes is when the inventory manager clicks the Calculate Button again. You need to alter the Inventory application to clear the result as soon as the user enters new information into either of the TextBoxes, to avoid any confusion over the accuracy of your calculated result.

6.1 Test-Driving the Enhanced Inventory Application 4 Figure 6.1 Inventory application GUI displayed when the application is executed. Running the application

6.1 Test-Driving the Enhanced Inventory Application 5 Figure 6.2 Running the Inventory application. Using the application Enter data into the TextBoxes and click the Calculate Total Button Notice the result

6.1 Test-Driving the Enhanced Inventory Application 6 Figure 6.3 Modified Inventory application clears output Label after new input. Cleared output Label Notice the new feature The output Label is cleared when new data is entered

7 6.2 Variables Adding code to the application Rearranging control declarations Declaring a variable Data types Built-in data type

6.2 Variables 8 Figure 6.4 The unarranged control declarations

6.2 Variables 9 Figure 6.5 Rearranging and commenting the control declarations

6.2 Variables 10 Figure 6.6 Declaring variables in event handler btncalculate_click Click event handler Variable declarations

11 6.2 Variables Retrieving data from the user Data is stored in the TextBox s Text property The Int32.Parse function Converts a string to an int Explicit conversion Assignment operator

6.2 Variables 12 Figure 6.7 Retrieving numerical input from TextBoxes. Assigning user input to variables

6.2 Variables 13 Built-in (primitive) data types bool char float long short byte decimal int ulong ushort sbyte double uint object string Figure 6.8 C# built-in data types.

14 6.2 Variables Perform the multiplication Displaying the result Set the Label s Text property to the multiplication result

6.2 Variables 15 Figure 6.9 Multiplication using variables in btncalculate_click. Calculating and displaying the result

16 6.2 Variables Figure 6.10 Displaying the multiplication result using variables. Result of calculation Running the application Enter data Click the Calculate Total Button Notice the result

17 6.3 Handling the TextChanged Event Create the event handler for the first TextBox Double click the TextBox TextChanged event handler is created Clearing the value Use empty string Repeat for second TextBox

6.3 Handling the TextChanged Event 18 Figure 6.11 TextChanged event handler for Cartons per shipment: TextBox. TextChanged event handler

6.3 Handling the TextChanged Event 19 Figure 6.12 TextChanged event handler for Items per carton: TextBox.

1 using System; 2 using System.Drawing; 3 using System.Collections; 4 using System.ComponentModel; 5 using System.Windows.Forms; 6 using System.Data; 7 8 namespace Inventory 9 { 10 /// <summary> 11 /// Summary description for FrmInventory. 12 /// </summary> 13 public class FrmInventory : System.Windows.Forms.Form 14 { 15 // Label and TextBox display the number of cartons per shipment 16 private System.Windows.Forms.Label lblcartons; 17 private System.Windows.Forms.TextBox txtcartons; 18 19 // Label and TextBox display the number of items per carton 20 private System.Windows.Forms.Label lblitems; 21 private System.Windows.Forms.TextBox txtitems; 22 23 // Labels display the total value 24 private System.Windows.Forms.Label lbltotal; 25 private System.Windows.Forms.Label lbltotalresult; Outline Inventory.cs (1 of 5) Rearranging and commenting the control declarations 20

26 27 // Button calculates total value 28 private System.Windows.Forms.Button btncalculate; 29 30 /// <summary> 31 /// Required designer variable. Outline Inventory.cs (2 of 5) 21 32 /// </summary> 33 private System.ComponentModel.Container components = null; 34 35 public FrmInventory() 36 { 37 // 38 // Required for Windows Form Designer support 39 // 40 InitializeComponent(); 41 42 // 43 // TODO: Add any constructor code after InitializeComponent 44 // call 45 // 46 } 47 48 /// <summary> 49 /// Clean up any resources being used. 50 /// </summary>

51 protected override void Dispose( bool disposing ) 52 { 53 if( disposing ) 54 { 55 if (components!= null) 56 { 57 components.dispose(); 58 } 59 } 60 base.dispose( disposing ); 61 } 62 63 // Windows Form Designer generated code 64 65 /// <summary> 66 /// The main entry point for the application. 67 /// </summary> 68 [STAThread] 69 static void Main() 70 { 71 Application.Run( new FrmInventory() ); 72 } 73 Outline Inventory.cs (3 of 5) 22

74 // handles Click event 75 private void btncalculate_click( 76 object sender, System.EventArgs e ) 77 { 78 // declare variables 79 int intcartons; 80 int intitems; 81 int intresult; 82 83 // retrieve numbers from TextBoxes 84 intcartons = Int32.Parse( txtcartons.text ); 85 intitems = Int32.Parse( txtitems.text ); 86 87 // multiply two numbers 88 intresult = intcartons * intitems; 89 90 // display result in Label 91 lbltotalresult.text = Convert.ToString( intresult ); 92 93 } // end method btncalculate_click 94 Outline Inventory.cs (4 of 5) Assigning a property s value to a variable Assigning a variable to a property 23

95 // handles TextChanged event for txtcartons 96 private void txtcartons_textchanged( 97 object sender, System.EventArgs e ) 98 { 99 lbltotalresult.text = ""; // clear output Label 100 101 } // end method txtcartons_textchanged 102 103 // handles TextChanged event for txtitems 104 private void txtitems_textchanged( 105 object sender, System.EventArgs e ) 106 { 107 lbltotalresult.text = ""; // clear output Label 108 109 } // end method txtitems_textchanged 110 111 } // end class FrmInventory 112 } Outline Defining a TextBox s TextChanged event Inventory.cs handler (5 of 5) Setting a TextBox s Text property to an empty string 24

25 6.4 Memory Concepts Figure 6.14 Memory location showing name and value of variable intcartons. intcartons 12 A simple variable Corresponds to actual location in the computer s memory Name Type Size Value

6.4 Memory Concepts 26 Figure 6.15 Memory locations after values for variables intcartons and intitems have been input. intcartons 12 intitems 10 Visualizing data The value of each variable is stored in a separate memory location

27 6.4 Memory Concepts Figure 6.16 Memory locations after a multiplication operation. intcartons 12 intitems 10 intresult 120 Using the variable s data Nondestructive when value is read from memory

28 Operator precedence 6.5 Arithmetic Operators in expressions contained within a pair of parentheses Unary positive and negative Multiplication and division operations Modulus (remainder) operations Addition and subtraction operations

6.5 Arithmetic 29 C# operation Arithmetic Algebraic expression C# expression operator Addition + f + 7 f + 7 Subtraction p c p c Multiplication * bm b * m Division / x / y or o x ȳ - r x y x / y Modulus (Remainder) % r modulo s r % s Unary Negative - e e Unary Positive + +g +g Figure 6.17 Arithmetic operators.