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.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
1 Lecture-2 CSIT-120 Spring 2001 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
Introduction to Computers and Programming Lecture 7:
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)
1 Lab Session-3 CSIT221 Spring 2003 b Group Worksheet 3 Exercise (Demo Required) b No new lab demo will be assigned to allow you to focus on HW#1.
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)
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
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.
1 Lecture-2 CS-120 Fall 2000 Revision of Lecture-1 Introducing Computer Architecture The FOUR Main Elements Fetch-Execute Cycle A Look Under the Hood.
1 Lab Session-7 CSIT-121 Fall Revising Structured Choice 4 The While Loop variations 4 Lab Exercises.
1 Lab Session-6 CSIT-121 Spring 2005 Structured Choice The do~While Loop Lab Exercises.
Chapter 2 Data Types, Declarations, and Displays
1 Lab Session-7 CSIT-121 Fall Introducing Structured Choice 4 The do~While Loop 4 Lab Exercises.
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.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
CIS 234: Character Codes Dr. Ralph D. Westfall April, 2011.
Chapter 5 new The Do…Loop Statement
© 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.
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.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Looping Exercises Deciding Which Loop to Use At this.
Introduction to Python
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
EGR 2261 Unit 5 Control Structures II: Repetition  Read Malik, Chapter 5.  Homework #5 and Lab #5 due next week.  Quiz next week.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
CIS 115 Lecture 8. There are 3 control structures common to most computer languages that determine the flow, or path of execution, of the code:  Sequential.
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Introduction to Computer Systems and the Java Programming Language.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Chapter 2: Using Data.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 6 – Car Payment Calculator Application: Introducing.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
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.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
Computer Programming Control Structure
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
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)
2. WRITING SIMPLE PROGRAMS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Representing Characters in a Computer System Representation of Data in Computer Systems.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
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.
Selection Using IF THEN ELSE CASE Introducing Loops.
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.
Computing with C# and the .NET Framework
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Programming Funamental slides
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Presentation transcript:

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 III continues (Session III-B)

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 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

4 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

5 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 take the vending machine problem in order to develop a program using while loop

6 Vending Machine Algorithm Algorithm begins when the user inserts card Initialize the balance on card with $5 Take the item price from the user While (price of item is less than or equal to amount on card) AND (price entered is not zero) [subtract price from card balance take another item price from the user] Let us implement this algorithm in a C++ program

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

13 Lab Session III-B Limits and bounds (Demo NOT required) Increment Operator ASCII and UNICODE Experiment 3.5 Simple Information Encryption Exercise 3-B (DEMO REQUIRED) Type Casting Experiment 3.6 (Demo NOT required)

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(Step 1,2,3 ONLY) This experiment will show most negative integer Experiment 3.2 This experiment shows the result of exceeding the limits (Use unary decrement operator ‘i--’ in step 3)

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 a code that has integer values ASCII code was originally 7 bits (128 values) Values from 00 to 1F are reserved for special non-printable control characters

ASCII and UNICODE ASCII was not sufficient as more symbols were needed ASCII was revised to “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

19 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

20 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

21 Uncover the ASCII code Experiment 3.5 Why do we include ? What is toascii? What is toupper? What is tolower? (HINT: Use these functions in your program to find out)

22 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-B Change a user supplied character to its ASCII value, add 8 to it and print the new character. (DEMO REQUIRED)

23 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