DATA PROCESSING Gary Sham 15/1/2011. Data Processing  Data Processing ≠ Algorithm  Data Processing:  Get the input so that we can use it in our program.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 16P. 1Winter Quarter Strings Lecture 16.
Programming and Data Structure
C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
Character String Manipulation. Overview Character string functions sscanf() function sprintf() function.
Character String Manipulation. Overview Character string functions sscanf() function snprintf() function.
What is a pointer? First of all, it is a variable, just like other variables you studied So it has type, storage etc. Difference: it can only store the.
 2000 Prentice Hall, Inc. All rights reserved Fundamentals of Strings and Characters String declarations –Declare as a character array or a variable.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
CS31: Introduction to Computer Science I Discussion 1A 5/7/2010 Sungwon Yang
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 8 - Characters and Strings Outline 8.1Introduction.
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
Introduction to Computers and Programming Class 22 Character Arrays (Strings) Professor Avi Rosenfeld.
Declarations/Data Types/Statements. Assignments Due – Homework 1 Reading – Chapter 2 – Lab 1 – due Monday.
Chapter 8 Arrays and Strings
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
Week 7 – String. Outline Passing Array to Function Print the Array How Arrays are passed in a function call Introduction to Strings String Type Character.
C-Strings Joe Meehean. C-style Strings String literals (e.g., “foo”) in C++ are stored as const char[] C-style strings characters (e.g., ‘f’) are stored.
EPSII 59:006 Spring Introduction Fundamentals of Strings and Characters Character Handling Library String Conversion Functions Standard Input/Output.
Strlen() implementation /* strlen : return length of string s */ int strlen(char *s) { int n; for (n = 0 ; s[n] != ‘\0’ ; n++) ; return n; } /* strlen.
C Tokens Identifiers Keywords Constants Operators Special symbols.
CHAPTER 07 Arrays and Vectors (part I). OBJECTIVES 2 In this part you will learn:  To use the array data structure to represent a set of related data.
 200 Total Points ◦ 74 Points Writing Programs ◦ 60 Points Tracing Algorithms and determining results ◦ 36 Points Short Answer ◦ 30 Points Multiple Choice.
Chapter 8 Arrays and Strings
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.
CPT: Strings/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to discuss strings and their relationship.
UniMAP Sem1-07/08EKT120: Computer Programming1 Week2.
Windows Programming, C.-S. Shieh, KUAS EC, Chapter 3 Operators and Expressions.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Character Arrays Based on the original work by Dr. Roger deBry Version 1.0.
HKOI 2004 Team Training Data Processing 1 & String Functions (Intermediate Level)
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
C# C1 CSC 298 Elements of C# code (part 1). C# C2 Style for identifiers  Identifier: class, method, property (defined shortly) or variable names  class,
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI C-Style Strings Strings and String Functions Dale Roberts, Lecturer.
 140 Total Points ◦ 100 Points Writing Programs ◦ 24 Points Tracing Algorithms and determining results ◦ 16 Points Short Answer  Similar to quizzes.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
Strings Programming Applications. Strings in C C stores a string in a block of memory. The string is terminated by the \0 character:
Matlab Data types, input and output. Data types Char: >> a = ‘ Jim ’ Char: >> a = ‘ Jim ’ Numeric: uint8, uint16, uint32, uint64 int8, int16, int32, int64.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
Modularity using Functions Chapter 4. Modularity In programming blocks of code often can be "called up" and reused whenever necessary, for example code.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Agenda  Take up homework  Loops - Continued –For loops Structure / Example involving a for loop  Storing Characters in variables  Introduction to Functions.
UniMAP SEM I - 09/10EKT 120 Computer Programming1 Lecture 8 – Arrays (2) & Strings.
Chapter 8 Characters and Strings. Objectives In this chapter, you will learn: –To be able to use the functions of the character handling library ( ctype).
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI N305 Characters and Strings Functions.
Characters and Strings
UniMAP Sem I-09/10EKT150: Computer Programming1 Week 2 – Introduction to Computer and Algorithm.
Chapter 16 Pointers and Arrays Pointers and Arrays We've seen examples of both of these in our LC-3 programs; now we'll see them in C. Pointer Address.
UNIMAP Sem2-07/08EKT120: Computer Programming1 Week 2 – Introduction to Programming.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Characters and Strings Dale Roberts, Lecturer Computer Science,
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
CSCI206 - Computer Organization & Programming
INC 161 , CPE 100 Computer Programming
Pointers & Arrays 1-d arrays & pointers 2-d arrays & pointers.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Strings A string is a sequence of characters treated as a group
CSCI206 - Computer Organization & Programming
Arrays in C.
Chapter 8 - Characters and Strings
Chapter 16 Pointers and Arrays
Session 1 – Introduction to Computer and Algorithm (Part 2)‏
Characters and Strings Functions
C Characters and Strings
Presentation transcript:

DATA PROCESSING Gary Sham 15/1/2011

Data Processing  Data Processing ≠ Algorithm  Data Processing:  Get the input so that we can use it in our program.  Save the input by some method to make it easier to code.  How to prevent WA.  Our Goal: A general method to do Data Processing.  Practice makes perfect.  It is always useful in all programming problems. InputProcessingOutput

Data Types CategoryPascalC/C++ OrdinalInteger, Char, Boolean,...int, char, bool,... Floating PointReal, Double, Extended,...float, double,... ArrayArray[Range] of TypeType[Range] StringPChar, String, ANSIStringchar[Range], string Packed Data TypeRecordstruct OthersPtr, Set,...*Type, enum,... The table is by no means complete and the correspondence is not exact.

Floating Point  Floating Point Representation leads to Precision Error  1/3   0.15   Always try to use ordinal types instead, e.g. Integer.  More accurate; and  Operate faster generally.  Use most accurate floating type if possible.  Use some special operation to handle it.

Conversion to integer  How to handle floating point data?  Convert them to integers if possible  Integers are easy to manipulate  E.g. Given numbers to 2 decimal places   10  a := round(d*100);  a = (int)(d* )  Scanf is useful…  scanf(“%d.%d”, &a,&b);

Special operations  Output :  writeln((a+1e-10):0:2)  printf( “ %.2lf\n ”,a+1e-10);  Compare:  a==b abs(a-b) < 1e-8  a < b a < b – 1e-8  a <= b a < b + 1e-8  ……

String  Pascal:  1 byte storing length and 255 bytes storing array of characters.  Total size is 256 bytes by default.  C/C++  Null-terminating array of characters. Last byte (Null- character) denotes the end.

String processing  Pascal: normal assignment  s := ’abcde’;  t := s;  s[2] := ’9’;  C: by char *strcpy(char *dest, const char *src);  strcpy(s, "abcde");  strcpy(t, s);  s[1] = ’9’;  C++: normal assignment  s = "abcde";  t = s;  s[1] = ’9’;  Google it……

Hints  Do not use C function strlen in a loop……  e.g. for (int i=0;i<strlen(s);++i) {…}  C string is Null-terminating.  Also be careful on all string operations(strcpy, etc.)  int n = strlen(s); for (int i=0;i<n;++i) {…}

Packed Data Types  Record/struct  It increase the readability.  It is important when debugging.  Operator overloading(C++)

Mapping  Swapping the data may be slow  Records in Pascal  Strings/Struct in C/C++  Arrays  Use a pointer to represent the data.

 Hard-coding is important technique in tackling data processing problems  2067 – Tappy Game  Blocks MUST be hard-coded  What should we hard-code?  Number of blocks occupied for each column of each Tappy  4 rotations of each Tappy Hard-coding is much easier than writing codes for rotation! Hard-coding

 When you are doing some searching in a maze.  DFS/BFS?  Yes, but HOW?  if (x+1>0) && (x+1 0) && (y<n){…}  if (x-1>0) && (x-1 0) && (y<n){…}  if (x>0) && (x 0) && (y+1<n){…}  if (x>0) && (x 0) && (y-1<n){…}  ……………………

Hard-coding  How about 8 directions?!  int dy[8]={1,1,-1,-1,0,0,0,0};  int dx[8]={0,0,0,0,1,1,-1,-1};  We can use for loop now! :D  Shorter code

Exercise  1012 Allocating School Places  2042 Reversi  2030 Be Jewelled!  2080 Simple Calculator  2067 Tappy Game