VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

Chapter 3: Expressions and Interactivity. Outline cin object Mathematical expressions Type Conversion and Some coding styles.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Objective: Dealing with data in C++ Agenda: Notes Essay Help.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Hello, world! Dissect HelloWorld.java Compile it Run it.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
COMPUTER SCIENCE I C++ INTRODUCTION
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Visual C++ Programming: Concepts and Projects Chapter 6A: Methods (Concepts)
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 3A Integral Data (Concepts)
Input, Output, and Processing
Chapter 2: Using Data.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Lesson 3 – Primitive Data Types Objective: Students will investigate the definition and usage of objects and primitive data types in Java in order to practice.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
1.  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.
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
VARIABLES AND DATA TYPES Chapter2:part1 1. Objectives: By the end of this section you should: Understand what the variables are and why they are used.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Programming with Visual C++: Concepts and Projects Chapter 3A: Integral Data (Concepts)
Chapter 2 Variables.
Lecture III Start programming in Fortran Yi Lin Jan 11, 2007.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
M105 - Week 2 Chapter 3 Numerical Data 1 Prepared by: M105 Team - AOU - SAB.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Chapter 2 Variables.
BASIC ELEMENTS OF A COMPUTER PROGRAM
2.5 Another Java Application: Adding Integers
ITEC113 Algorithms and Programming Techniques
Data Types, Identifiers, and Expressions
Variables, Expressions, and IO
Type Conversion, Constants, and the String Object
Java Programming: From Problem Analysis to Program Design, 4e
C++ for Engineers and Scientists Second Edition
IDENTIFIERS CSC 111.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Variables Kingdom of Saudi Arabia
Chapter 2: Basic Elements of Java
Chapter 2 Variables.
Chapter 2: Java Fundamentals
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Primitive Types and Expressions
Chapter 2 Variables.
Variables and Constants
Presentation transcript:

VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)

Objectives Visual C++ Programming 2  Develop algorithms to solve a problems  Learn about the standard C++ data types  Declare and initialize variables  Read data using the TryParse() method  Use the standard C++ arithmetic operators

Objectives (continued) Visual C++ Programming 3  Process data using arithmetic expressions  Abbreviate lines of code using shorthand assignment operators  Use the Math::Pow() and Math::Sqrt() methods  Display output using the ToString() method

Solving Problems Visual C++ Programming 4  An algorithm is an ordered list of steps required to solve a problem  Algorithms are written in pseudocode  Algorithms are language independent  High-level algorithms provide general list of tasks  Low-level algorithms provide specific details

Solving Problems (continued) Visual C++ Programming 5

Data and Data Types Visual C++ Programming 6  Data includes everything entered into your program (numbers and characters for example)  Data is represented using binary digits called bits  A grouping of eight bits is called a byte  Different kinds of data are called data types

Visual C++ Programming 7

8

Data and Data Types (continued) Visual C++ Programming 9  Primitive data types  Boolean ( bool ) used to represent true or false  Character ( char ) represents a single character ASCII codes represent char data in one byte  Integer ( int ) includes positive and negative whole numbers and zero  Real numbers ( float and double ) includes all values that may have decimal places float – used to represent single precision numbers double – represents double-precision numbers

Data and Data Types (continued) Visual C++ Programming 10

Data and Data Types (continued) Visual C++ Programming 11  Derived data types Built on primitive types The String data type is used to represent text strings Text strings Example: “Hello world!”

Variables Visual C++ Programming 12 A variable is a named location in memory that stores data Variables are created by a process called “declaration” When a variable is declared One or more memory cells are allocated in memory The allocated space is assigned a name The allocated space is associated with a data type

Variables (continued) Visual C++ Programming 13

Variables (continued) Visual C++ Programming 14

Visual C++ Programming 15

Variables (Continued) Visual C++ Programming 16

Variables (Continued) Visual C++ Programming 17  Variable naming conventions Names must begin with a letter or an underscore (_) and can only use letters, digits or underscores in the body of the name Names are case sensitive ( height is not the same name as Height ) Spaces cannot be used as separators

Variables (continued) Visual C++ Programming 18

Variables (continued) Visual C++ Programming 19

Initializing Variables Visual C++ Programming 20  Initialization refers to the act of assigning a value to a variable before it is used  By default, Visual C++ initializes all numeric variables to 0  The programmer can initialize variables using assignment statements

Initializing Variables (continued) Visual C++ Programming 21

Initializing Variables (continued) Visual C++ Programming 22

Initializing Variables (continued) Visual C++ Programming 23

Data Input Visual C++ Programming 24  Data input refers to the process of reading data into a variable from the program interface  Data is often read in from a TextBox

Data Input (continued) Visual C++ Programming 25

The TryParse() Method Visual C++ Programming 26  Parsing is the process of extracting data from a string of text  The TryParse() method parses the Text contained in a TextBox  Every data type class has a built-in TryParse() method  Scope refers to the class or program segment to which something belongs  The scope resolution operator ( :: ) identifies the data type class that TryParse() belongs to

The TryParse() Method (continued) Visual C++ Programming 27

The TryParse() Method (continued) Visual C++ Programming 28  Parameters are items of information that a method requires  A parameter list is a groups of parameters separated by commas

The TryParse() Method (continued) Visual C++ Programming 29

Data Processing Visual C++ Programming 30  Computations often involve arithmetic expressions  An arithmetic operator is a symbol that stands for an arithmetic operation  Arithmetic operations are  Multiplication (*)  Division (/)  Mod (%)  Addition (+)  Subtraction (-)

Arithmetic Operators Visual C++ Programming 31  Operands are the variables or values that arithmetic operations are performed on  Arithmetic operators are binary (require two operands)  Arithmetic operations are performed from left to right (left to right associative)  Examples:  num = num1 + num2;  num = num + 1;

Visual C++ Programming 32

Visual C++ Programming 33

Operator Precedence in Arithmetic Expressions Visual C++ Programming 34  Complex arithmetic expressions have more than one arithmetic operator.  Operator precedence rules dictate which operations are performed first  Multiplication (*), division (/) and mod (%) have higher precedence than addition (+) and subtraction (-)  When two or more operators of the same precedence are in an expression they are performed from left to right

Operator Precedence in Arithmetic Expressions (continued) Visual C++ Programming 35  Parentheses have higher precedence than all arithmetic operators  Parentheses can be used to perform lower precedence operations before higher ones  Expression trees are used to illustrate the order in which operations are completed when a complex expression is evaluated

Visual C++ Programming 36

Visual C++ Programming 37

Visual C++ Programming 38

Visual C++ Programming 39

Arithmetic Operators and Strings Visual C++ Programming 40  The addition operator (+) is used to add numeric data  When the operator (+) is used with strings it joins them together (concatenation)  Example:  textBox3->Text = textBox1->Text + textBox2->Text;

Visual C++ Programming 41

Shorthand Assignment Visual C++ Programming 42  Shorthand operators are abbreviations for assignment statements involving arithmetic operations  Shorthand operators: +=, /=, %=, +=, -=  Example:  num1 = num1 + num2; is num1 += num2;

The Math Library Visual C++ Programming 43  The System Math Class contains methods that perform commonly-used tasks  Example:  Math::Pow(2,3)  Math::Sqrt(45)  c = Math::Sqrt(Math::Pow(a,2) + Math:Pow(b,2));  Common Math methods:  Exponentiation, Math::Pow()  Square Root, Math::Sqrt()  Cosine, Math::Cos()  Sine, Math::Sin()  Tangent, Math::Tan()

Visual C++ Programming 44

Data Output Visual C++ Programming 45  To display a value in the Text property of a TextBox it must be converted to a String  The ToString() method  Example:  textBox3->Text = sum.ToString();

Visual C++ Programming 46

Summary Visual C++ Programming 47 Solving problems requires algorithms Step-by-step lists of instructions Commonly used data types are Bool, char, int, float and double The String data type stores character strings Data is stored in variables Variable declarations allocate, name and assign a data type to memory cells Assignment statements are a common way to initialize variables

Summary (continued) Visual C++ Programming 48 Data Input Captures the contents of a TextBox and stores the result in a variable TryParse() Data Processing Common arithmetic operations (*,/,%,+,-) Precedence rules (*,/ and % before +,-) Expression trees are used to evaluate arithmetic expressions

Summary (continued) Visual C++ Programming 49  Data Output Transferring data from a variable to a TextBox Use the ToString() method