Programming Fundamentals. Floating Point Numbers Scientific notation 98 = 0.98 x 10 2 204.5 = 0.2045 x 10 3 -0.082167 = -0.82167 x10 -1 Sign bit; Fraction.

Slides:



Advertisements
Similar presentations
Programming Fundamentals Chapter 4. Floating Point Numbers  Scientific notation 98 = 0.98 x = x = x10 -1 
Advertisements

Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
1 C++ Syntax and Semantics The Development Process.
1 C Fundamentals - I Math 130 Lecture # 2 B Smith: Sp05: With discussion on labs, this took 53 minutes. Score 3. Many caveats. B Smith: Sp05: With discussion.
Types and Arithmetic Operators
CSE202: Lecture 2The Ohio State University1 Variables and C++ Data Types.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Variables and Constants
Cosc175/data1 Data comprised of constants and variables information stored in memory Each memory location has an address Address - number identifying a.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 2 Introduction to C++
Numeric Types, Expressions, and Output ROBERT REAVES.
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
CSE1222: Lecture 2The Ohio State University1. mathExample2.cpp // math example #include using namespace std; int main() { cout
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Chapter 3 P. 1 Data - Variables and Constants Definition A variable is a value which can change during program execution. A constant is a value which can.
CONSTANTS Constants are also known as literals in C. Constants are quantities whose values do not change during program execution. There are two types.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
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.
Data Types Declarations Expressions Data storage C++ Basics.
Chapter 2 Variables.
Copyright © – Curt Hill Types What they do.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Arithmetic Expressions Addition (+) Subtraction (-) Multiplication (*) Division (/) –Integer –Real Number Mod Operator (%) Same as regular Depends on the.
Variables Symbol representing a place to store information
C++ for Engineers and Scientists Second Edition
Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
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.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
A variable is a name for a value stored in memory.
Chapter 2 Variables.
Data Types, Variables & Arithmetic
BASIC ELEMENTS OF A COMPUTER PROGRAM
Tokens in C Keywords Identifiers Constants
ITEC113 Algorithms and Programming Techniques
Data Structures Mohammed Thajeel To the second year students
C++ for Engineers and Scientists Second Edition
IDENTIFIERS CSC 111.
Numbers.
CS111 Computer Programming
Chapter 2 Variables.
C++ Data Types Data Type
Lectures on Numerical Methods
CHAPTER FOUR VARIABLES AND CONSTANTS
VB Variables and Data
Chapter 2: Introduction to C++.
Primitive Types and Expressions
Chapter 2 Variables.
Variables and Constants
Presentation transcript:

Programming Fundamentals

Floating Point Numbers Scientific notation 98 = 0.98 x = x = x10 -1 Sign bit; Fraction (Mantissa); Exponent SExponentFraction

Floating point arithmetic Addition & Subtraction 0.45x x10 -1 = -0.45x x10 -1 = Multiplication & Division 0.45x10 2 ÷ 0.32x10 -1 = 0.45x10 2 * 0.32x10 -1 =

Data Types Type of quantities Integer Long Integer Single Double String Byte Boolean Currency Date

Integer & Long Integer Integer –Uses 2 bytes ( 2x8=16 bits ) of memory  range –No commas, like 20,400 –No decimals or fractions, like 2.45 or 4.00 Long Integer –Uses 4 bytes  range

Single & Double Single –Use 4 bytes (32 bits) –Can have 7 significant digits -3.4 E 38  3.4 E 38 range Double –Uses 8 bytes (64 bits) –Can have 15 significant digits -1.8 D 308  1.8 D 308 range

Byte & Currency Byte –Unsigned numbers 0  255 Currency –8 Bytes -922,337,203,685,  +922,337,203,685, –No truncation & rounding

String Strings are non-numeric quantities, written within quotes –Examples ‘Islam is the solution to world problems’ ‘CS101’ ‘ ’ ‘Rs. 32,400.55’ ‘Osama bin Zaid’ ‘TB stands for Tooni’s Blare & a notorious disease’

Constants & Variables Each data type can be a constant or a variable Constant –The contents of the memory remain fixed –Numeric or String pi  Speed Of Light  2.998e8 k  1.38e-23 Name Of My Hero  “Muhammad (pbuh)” e  “-1.6e-19”

Constants & Variables Variables –The contents of a memory associated with a variable is allowed to change –A & B determine the contents of Sum and Product Read A Read B Sum = A + B Product = A*B

Declarations Variables are declared at the beginning of a program using Dim –Reserve appropriate memory Examples –Dim MidtermScore As Integer –Dim h As single, Frequency As Single –Dim Energy As Double –Dim StudentName As String –Dim CourseTitle As String*40

Memory Allocation A_Integer A_Single

Variable Name Rules A variable name must begin with an alphabet. It should not be longer than 255 characters. Special words, such as, Dim, If, Else, Case, etc. are not permitted.

Variable Name Rules Some special characters are allowed within a variable name. A period (full stop), %, # and & are not allowed. –Avoid special characters in a variable name.

Variable Name Rules Visual Basic does not distinguish between upper and lower case letters. –AVARIABLE, AVariable, aVariable, avariable, etc. refer to the same memory location.

The Longest Variable Name EvenThoughItIsHardToWriteOrReadAndM anyOfUsMayNeverSeeOrWriteSuchLongV ariableNameYetVisualBasicAllowsTheUse OfTwoHundredFiftyFiveCharactersForThe VariableName characters

Suffix Notation VariableData Type Index%Integer Counter&Long Integer TaxRate!Single Ratio#Double Name$String

Constants Constants can be named like variables –Or remain un-named Const Name As String=“Muhammad (pbuh)” Const c As Single = 2.998E8 Const e As Double = -1.6D /7 –An effort to change the contents of a named constant will result in an error Assignment to constants not permitted

Operators + (plus)AdditionShift + = - (minus)Subtraction- * (asterisk)MultiplicationShift + 8 / (slash)Division/ ^ (caret)ExponentiationShift + 6 \ (back slash) Integer division\ ModInteger remainder

Operations 2^3 = 8 10/8 = \8 = 1 8.6\2.7 = 3 10 Mod 8 = Mod 2.1 = 0 2.3/1.2^2 = 2.3/1.44 =

Hierarchy of Operations 1.(^) Exponentiation 2.(* or /)Multiplication & Division 3.(\)Integer Division 4.(Mod)Integer Remainder 5.(+ or -)Addition & Subtraction Parentheses are used to change the order of operation.

Expressions  (2*(a+b)^2 + 3*c^2)^(3/2) (2*(a+b)^2 + 3*c^2)^3/2   -x + y^2 -2^4 = -(2^4) = -16 (-2)^4 = 16

String Expressions Amount = “Ten” Denomination = “Thousand” Amount & “ “ & Denomination & “ Rupees”  Ten Thousand Rupees Amount + “ “ & Denomination + “ Rupees”  Ten Thousand Rupees

Expressions How u n = u^n is computed when n≠0? Is n an integer? n > 0 Compute a=u |n| by multiplying u, n times Ans=1/a Ans=a Compute ans=n*log(u) Yes No Yes No Logarithm of –ive numbers is not defined Is u > 0? Error Message Yes No u can be +ive or -ive

Assignment Salary = Tax = 4/100*Salary HouseRent = 1200 NetSalary = Salary - Tax - HouseRent

Library Functions Abs Y=Abs(-2)  Y = 2 Chr Y=Chr(65)  Y = “A” Exp Y=Exp(2)  Y = e^2 Int Y=Int(-2.9)  Y = -2

Library Functions Rnd Y=Rnd  Y gets a random number 0≤Y<1 Sgn Y=Sgn(x)  Str Y=Str(4.2)  Y = “4.2” Val Y=Val(“-3”)+Val(“2”)  Y = =-1.1 »The string within the Val must appear like a number

Library Functions Sin, Cos, Tan –Trigonometric functions Arguments must be in RADIANS –Sin(x), Cos(u), Tan(w) Date Y=Date  Current date mo/dy/Year Sqr Y=Sqr(4)  Y = 2 =

Library Functions Lcase Y=Lcase(“MyName”)  Y=“myname” Ucase Y=Ucase(“MyName”)  Y = “MYNAME” Len Y=Len(“MyName”)  Y=6

Library Functions Left Y=Left(“MyName”,3)  Y=“MyN” Right Y=Right(“MyName”,3)  Y=“ame” Mid Y=Mid(“MyName”,2,3)  Y=“yNa” Log Y=Log(72.4)  Y=log e (72.4)

User-Defined Data Type User can define new data types by using standard data types Example Type Member Name As String ID As String DateOfBirth As Date Dues As Single End Type

User-Defined Data Type Then we could declare & use variables of type Customer as follows Dim OldMember As Member Dim NewMember As Member OldMember.Name  Name of the Old Member NewMember.DateOfBirth NewMamber.Name NewMember.Dues