1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

Introduction to C Programming
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
1 Lab Session-6 CSIT121 Fall 2004 Selection: Operator Precedence Some Q’s and A’s Lab Exercises Additional Practice Questions.
Introduction to Computers and Programming Lecture 7:
1 Lab 2 CSIT-120 Spring 2001 Session II-A (Feb 13th) Operations on Data Lab Exercise 2-A Data Types Variables Lab Exercise 2-B Session II-B (Feb 20th)
Aalborg Media Lab 21-Jun-15 Software Design Lecture 2 “ Data and Expressions”
1 Lab Session-IV CSIT-120 Spring 2001 Lab 3 Revision and Exercises Rev: Precedence Rules Lab Exercise 4-A Machine Language Programming The “Micro” Machine.
8 November Forms and JavaScript. Types of Inputs Radio Buttons (select one of a list) Checkbox (select as many as wanted) Text inputs (user types text)
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
1 Lab Session-7 CSIT-121 Fall Revising Structured Choice 4 The While Loop variations 4 Lab Exercises.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
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
Introduction to C Programming
1 Lab Session-VI CS121 Fall 2000 l HW#2 Assigned l Multiple Choice Selectors l The While Loop l Switch-Case-Break Exercise l The Counter Controlled Loops.
1 Lab Session-III CSIT-120 Spring 2001 Revising Previous session Data input and output While loop Exercise Limits and Bounds GOTO SLIDE 13 Lab session.
1 Lab 2 CSIT-120 Fall 2000 Session II-A (September 14th) Operations on Data Lab Exercise 2-A Data Types Variables Lab Exercise 2-B Session II-B (September.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Introduction to Python
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
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?
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
CSCI 1100/1202 January 28, The switch Statement The switch statement provides another means to decide which statement to execute next The switch.
Chapter 2: Using Data.
CHAPTER 4: CONTROL STRUCTURES - SEQUENCING 10/14/2014 PROBLEM SOLVING & ALGORITHM (DCT 1123)
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
CPS120: Introduction to Computer Science Operations Lecture 9.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
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.
Computer Programming Control Structure
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Gator Engineering Copyright © 2008 W. W. Norton & Company. All rights reserved. 1 Chapter 3 Formatted Input/Output.
1 Variables and Arithmetic Operators in JavaScript.
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.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
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.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Object Oriented Programming
Multiple variables can be created in one declaration
Computing with C# and the .NET Framework
Expressions Chapter 4 Copyright © 2008 W. W. Norton & Company.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Introduction to C++ Programming
Chapter 8 JavaScript: Control Statements, Part 2
elementary programming
Primitive Types and Expressions
Presentation transcript:

1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide 15) Experiments 3.1, 3.2, 3.3 The increment operator ASCII and UNICODE and Experiment 3.5 Lab 3 DUE October 26th

2 Revising Previous Session Can we use un-initialized variables on RHS of an assignment statement? On LHS? If we are interested in the remainder value from a division, what operator should be used? Can we assign an integer value to a floating point variable?

3 Data Input and Output Using variables, we can read the data values and write out the same We should choose the data type carefully so as to match the value For example, We do a mini-exercise Mini Exercise A program that reads a character input from user and displays it.

4 Introducing Loops We have seen in the class the need for a loop structure in searching a list In algorithm development, we can use several types of loops While structure is an example of loops Format: while (condition is true) »execute the statements in loop body

5 Introducing Loops While loop keeps executing statements in the body of the loop until the condition becomes false While (condition 1 is true) do statement1 becomes check condition 1 if true do statement

6 While Conditional Loop We have already looked at the while statement in algorithm development C++ provides the while statement for implementing conditional loops Let us look at the vending machine problem in order to develop a program using while loop

7 Lab Exercise 3-A (Demo Required) A user is prompted to enter a character. The programs keep reading the characters entered and keeps counting the same. As soon as the user enters ‘q’, the program exits showing the total number of characters entered

8 Assumptions The program will accept a character input from the user It should count the characters entered It should exit on receiving a ‘q’ from the user, displaying total count Let us perform the data analysis and algorithm development for the program

9 Data Analysis How many data items are needed? SOLUTION a character variable to hold the input data a counter to count the number of inputs Determine the input and output data items. INPUT: character data OUTPUT: count of characters

10 Algorithm Development INITIAL *Initialize *Read the character and count it *exit if it matches ‘q’ DETAILED *Make count=0 *Read the character input and add 1 to count until character input is equal to ‘q’ * Display count value and exit

11 Algorithm Development FINAL –Initialize the count to zero –Read a character and increment count –While (character is not equal to ‘q’) – (Read a character and increment count) –Display the count and exit

12 Programming Data analysis gives us the declarations Algorithm gives us the statements Here while statement is most suitable because the character input is checked before exiting the program It is advisable to display messages on each action to track the program well

Limits and Bounds The numerical data can be stored in the memory as a string of 1’s and 0’s There is an upper limit on the size of the numbers that can be represented in the computer The limits are recorded in the header file limits.h

Limits and Bounds Experiments 3.1 This experiment will show most negative integer Experiment 3.2 This experiment shows the result of exceeding the limits

15 Lab 3 Session III-B Increment Operator ASCII and UNICODE Simple Information Encryption Exercise 3-C Type Casting Experiment 3.6 and 3.7 (Using for loop) Lab3 Due October 26th

Increment Operator In Experiment 3.2, we have seen the use of the unary increment operator ==> number++; i++ Similarly we have a unary decrement operator ==> number--, i-- Instead of number=number-1;

ASCII and UNICODE The alphabets and digits are represented by integer values and this mapping is called a code ASCII code was originally 7 bits (128 values) Values from 00 to 1F were reserved for special non-printable control characters

ASCII and UNICODE For example, trying to print ASCII code 7 will ring a bell on the computer Example: cout<< “\7” To print spaces cout<<“\t” Up from 20 are the uppercase, lowercase letters and digits alongwith punctuation marks

ASCII and UNICODE ASCII was not sufficient as more symbols were needed ASCII was revised to be “Latin-1”, an 8-bit code that can have 256 symbols Latin-1 can cover some European languages Computers are being used all over the world A unified coding system was needed

20 ASCII and UNICODE A consortium developed a standard code called UNICODE. This code has 16 bits, thus 65,536 code points are possible World languages have 200,000 symbols so all cannot be accommodated Values from 0 to 255 map to Latin-1 or ASCII so changes are not felt in English

21 ASCII and UNICODE UNICODE allocates code points to languages in an “official” way Number of code points given is more than the letters in each language to accommodate different forms of each letter Adding new words in English e.g. applets does not require new code points but adding new words in Japanese requires new points

22 Uncover the ASCII code Experiment 3.5 What is meant by ? What is toascii? What is toupper? What is tolower? Lab Exercise 3-B Given a character input from the user, write a program to convert it to uppercase letter

23 Simple Encryption Techniques Once you are able to process a text string, you can convert the characters to their ASCII values The ASCII values are numeric. You can modify these values so that no one can understand what is in the string Exercise 3-C Change a character to its ASCII value, modify it and print it. (DEMO)

24 Type Casting Type Casting or Coercion means forcing the changing of the type of a variable’s value For example, adding integers and floating point numbers together and assigning it to a floating point number Experiment 3.6 Experiment 3.7 (for loop will be needed) Demo

25 Mixing Arithmetic Operations When we try to perform several arithmetic operations in one expression, the expression becomes quite complex For example, consider the following Q = (A+B*C)(A+B/C) Q = ((A+B)*C)((A+B)/C)??? Q = (A+(B*C))(A+(B/C))???

26 Using Precedence Rules We can use the precedence rules to get an expression evaluated as per our needs Following are the precedence rules in C++ for arithmetic operations Highest Priority is given to () (parenthesis) Multiplication (*) and Division (/) take precedence over addition (+) and subtraction (-) Assignment (=) is done at the end We should use parenthesis to make the expression clear

27 Lab3 Given 10/5 Due 10/26 Refer to Post Lab Problem 3.4. It calls for converting any user supplied integer in the range 1 to 100 into its binary equivalent. Your program should at least convert one user supplied number. It may keep doing the conversion until the user enters a 0(BONUS 2 POINTS). Use the method covered in the class for converting into binary. For example, given 23, your program should display Please note that displaying LSB on the left i.e will not be acceptable.