ANSI C Reserved Words. Abstract Data Type: complex. Arrays. Multimedia Programming Lecture 5

Similar documents
ANSI C Reserved Words

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

Tokens, Expressions and Control Structures

Introduction to Computing Lecture 01: Introduction to C

6.096 Introduction to C++ January (IAP) 2009

Procedures, Parameters, Values and Variables. Steven R. Bagley

Presented By : Gaurav Juneja

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Programming in C++ 4. The lexical basis of C++

Introduction to C++ Systems Programming

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

CMSC 104 -Lecture 5 John Y. Park, adapted by C Grasso

In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.

Character Set. The character set of C represents alphabet, digit or any symbol used to represent information. Digits 0, 1, 2, 3, 9

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

DETAILED SYLLABUS INTRODUCTION TO C LANGUAGE

C: How to Program. Week /Mar/05

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

ET156 Introduction to C Programming

Chapter 15 - C++ As A "Better C"

A Fast Review of C Essentials Part I

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

DECLARATIONS. Character Set, Keywords, Identifiers, Constants, Variables. Designed by Parul Khurana, LIECA.

Lecture 02 C FUNDAMENTALS

Variables in C. CMSC 104, Spring 2014 Christopher S. Marron. (thanks to John Park for slides) Tuesday, February 18, 14

COP 3275: Chapter 02. Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA

PROGRAMMAZIONE I A.A. 2018/2019

CMPE-013/L. Introduction to C Programming

Chapter 2 - Introduction to C Programming

Midterm Examination # 2 Wednesday, March 19, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Advanced Systems Programming

Programming. C++ Basics

CprE 288 Introduction to Embedded Systems Exam 1 Review. 1

DEPARTMENT OF MATHS, MJ COLLEGE

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

BLM2031 Structured Programming. Zeyneb KURT

INTRODUCTION 1 AND REVIEW

!"#$% &'($) *+!$ 0!'" 0+'&"$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-"!.&/+"*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

ET156 Introduction to C Programming

C Programming Review CSC 4320/6320

Data Types and Variables in C language

Midterm Examination # 2 Wednesday, March 18, Duration of examination: 75 minutes STUDENT NAME: STUDENT ID NUMBER:

Data types, variables, constants

C Fundamentals & Formatted Input/Output. adopted from KNK C Programming : A Modern Approach

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

CSCE 110 PROGRAMMING FUNDAMENTALS

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Non-numeric types, boolean types, arithmetic. operators. Comp Sci 1570 Introduction to C++ Non-numeric types. const. Reserved words.

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Basic Types, Variables, Literals, Constants

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Storage class and Scope:

Data Type Fall 2014 Jinkyu Jeong

M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH C LANGUAGE

Introduction to Programming

Fundamentals of Programming

Introduction to the C Programming Language

COMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for


A3-R3: PROGRAMMING AND PROBLEM SOLVING THROUGH 'C' LANGUAGE

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

CSCI 171 Chapter Outlines

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Chapter 2: Overview of C. Problem Solving & Program Design in C

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli

ANSI C Programming Simple Programs

Variables. Data Types.

Syntax and Variables

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

Review of the C Programming Language for Principles of Operating Systems

Computer Science & Engineering 150A Problem Solving Using Computers

Fundamental of Programming (C)

>B<82. 2Soft ware. C Language manual. Copyright COSMIC Software 1999, 2001 All rights reserved.

Chapter 1 & 2 Introduction to C Language

Review of the C Programming Language

VARIABLES AND CONSTANTS

An AnsiString class reference

Creating, Compiling and Executing

Programming and Data Structures

G52CPP C++ Programming Lecture 8. Dr Jason Atkin

Name :. Roll No. :... Invigilator s Signature : INTRODUCTION TO PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Structures, Unions Alignment, Padding, Bit Fields Access, Initialization Compound Literals Opaque Structures Summary. Structures

Appendix. Grammar. A.1 Introduction. A.2 Keywords. There is no worse danger for a teacher than to teach words instead of things.

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Transcription:

Multimedia Programming 2004 Lecture 5 Erwin M. Bakker Joachim Rijsdam ANSI C Reserved Words auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while ANSI C++: class, private, public Abstract Data Type: complex Arrays typedef struct float Real; float Imaginary; complex complex sum( complex z, complex w ) complex s; s.real = z.real + w.real; s.imaginary = z.imaginary + w.imaginary; return s; complex Sum, z1, z2;... z1 = ; z2 = ; Sum = sum(z,1,z2); int i=1; char s[10]; // s now contains the address of s[0] s is equivalent to &s[0] s + i is equivalent to &s[i] &s[i] is equivalent to &s[0] + i ( note, the compiler knows it is the address of an int => &s[0] + i means i integer locations further) int a[10]; for ( i=0; i<10; i++ ) scanf( %d, &a[i] ); // does the same as for ( i=0; i<10; i++ ) scanf( %d, a + i ); // and is equivalent to for (i=0; i<10; i++ ) scanf( %d, &a[0] + i ); 1

Arrays int minimum( int *b, int n) // also: int minimum( int b[], int n) int min, i; min = *b; min = b[0]; // means the same as previous statement for ( i=1; i<n; i++) if ( *(b+i) < min ) min = *(b+i); if ( b[i] < min ) min = b[i]; return min; int main(void) int a[10]; // a contains the address of a[0]!!! printf( Smallest value: %d\n, minimum(a,10) ); // is equivalent to previous statement Dynamic Arrays int myfunction(int b) int myfunction(int b) int c[10000], i; int *d, i; d = new int[b]; for (i=0; i<b; i++) for ( i=0; i<b; i++) scanf( %d,&c[i]); scanf( %d,&d[i]);... delete d; return 0; return 0; Multi Dimensional Arrays C++ Classes float table[100][3]; float mtable[100][3][5]; int myfunction( float a[][3] ); int myfunction( float a[][3][5] ); // Initialization int a[2][3] = 1,2,3, 3,4,5; char names[3][20] = pete, jane, bill ; // Dynamic int *list[30]; // 30 pointers to integers for (i=0; i<30; i++) scanf( %d, &length); list[i] = new int[length]; delete [30] list; Abstract Data Types: Struct + their operations C++ class is a concept to define data structures and their operations The actual implementation of the abstract data type can be hidden to the user! 2

C++ Classes: List Example Abstract Data Type List: Data: Name Address Comments Basic operations: Create: Create a list Add: Add data to list Delete: Delete data from the list Find: Find data in the list List: Make a print of the contents of the list We would like to hide the implementation to the user of our list C++ Classes: CList class CList public: CList(); ~CList(); void Add(int element); void Delete(int element); bool Find(int element); bool IsEmpty(); void List() \\ Declaration of CList \\ Mandatory constructor \\ Mandatory destructor \\ The public operations \\ Public member functions private: \\ Private declarations int element_list[max_elements]; \\ Data int number_of_elements; int FindPlace(int element); \\ Private member function ; C++ Classes: CList C++ Classes Declaration class CList void Add(int element); void Delete(int element); bool Find(int element); bool IsEmpty(); void List(); Is everything the user needs to know to use the class CList int main( void ) CList list; list.add(2); list.add(5); list.delete(2); list.list(); return 0; \\ Declaration of CList \\ Public member functions Class CMyClass CMyClass Examp; Examp.my_data = 1; public: Examp.memberfunction_this(3); CMyClass(); ~CMyClass(); void memberfunction_this(int element); void memberfunction_that(int element); int my_data; int my_array[10]; int *my_pointers; private: int my_private_memberfunctions(); int my_private_data; Public: etc. ; 3

Using Existing C++ Classes Microsoft Foundation Classes CFile CList Microsoft Foundation Class Library (MFC) Etc. Microsoft Foundation Classes Construction Constructs objects in various ways. The String as an Array GetLength Returns the number of characters in a object. For multibyte characters, counts each 8-bit character; that is, a lead and trail byte in one multibyte character are counted as two characters. IsEmpty Tests whether a object contains no characters. Empty Forces a string to have 0 length. GetAt Returns the character at a given position. operator [] Returns the character at a given position operator substitution for GetAt. SetAt Sets a character at a given position. operator LPCTSTR Directly accesses characters stored in a object as a C- style string. Assignment/Concatenation operator = Assigns a new value to a object. operator + Concatenates two strings and returns a new string. operator += Concatenates a new string to the end of an existing string. 4

Comparison operator == <, etc. Comparison operators (case sensitive). Compare Compares two strings (case sensitive). CompareNoCase Compares two strings (case insensitive). Collate Compares two strings (case sensitive, uses locale-specific information). CollateNoCase Compares two strings (case insensitive, uses locale-specific information). Extraction Mid Extracts the middle part of a string (like the Basic MID$ function). Left Extracts the left part of a string (like the Basic LEFT$ function). Right Extracts the right part of a string (like the Basic RIGHT$ function). SpanIncluding Extracts a substring that contains only the characters in a set. SpanExcluding Extracts a substring that contains only the characters not in a set. Other Conversions MakeUpper Converts all the characters in this string to uppercase characters. MakeLower Converts all the characters in this string to lowercase characters. MakeReverse Reverses the characters in this string. Replace Replaces indicated characters with other characters. Remove Removes indicated characters from a string. Insert Inserts a single character or a substring at the given index within the string. Delete Deletes a character or characters from a string. Format Format the string as sprintf does. FormatV Formats the string as vsprintf does. TrimLeft Trim leading whitespace characters from the string. TrimRight Trim trailing whitespace characters from the string. FormatMessage Formats a message string. Searching Find Finds a character or substring inside a larger string. ReverseFind Finds a character inside a larger string; starts from the end. FindOneOf Finds the first matching character from a set. Archive/Dump operator <<Inserts a object to an archive or dump context. operator >>Extracts a object from an archive. Buffer Access GetBuffer Returns a pointer to the characters in the. GetBufferSetLength Returns a pointer to the characters in the, truncating to the specified length. ReleaseBuffer Releases control of the buffer returned by GetBuffer.FreeExtra Removes any overhead of this string object by freeing any extra memory previously allocated to the string. LockBuffer Disables reference counting and protects the string in the buffer. UnlockBuffer Enables reference counting and releases the string in the buffer. Windows-Specific AllocSysString Allocates a BSTR from data. SetSysString Sets an existing BSTR object with data from a object. LoadString Loads an existing object from a Windows resource. AnsiToOem Makes an in-place conversion from the ANSI character set to the OEM character set. OemToAnsi Makes an in-place conversion from the OEM character set to the ANSI character set. 5

CList: member functions CList Construction CList Constructs a CList object. / Access Get Returns the head element of the list (cannot be empty). Get Returns the tail element of the list (cannot be empty). Operations Remove Removes the element from the head of the list. Remove Removes the element from the tail of the list. Add Adds an element (or all the elements in another list) to the head of the list (makes a new head). Add Adds an element (or all the elements in another list) to the tail of the list (makes a new tail). RemoveAll Removes all the elements from this list. Status GetCount Returns the number of elements in this list. IsEmpty Tests for the empty list condition (no elements). The CList class supports ordered lists of non-unique objects accessible sequentially or by value. CList lists behave like doubly-linked lists. Data 1 Data 2 Data 2 Data 3 Data n CList: Insert After Position CList: Deletion After Position a Position b c b New c a c Del New Element Position New 6

CList The CList class supports ordered lists of nonunique objects accessible sequentially or by value. CList lists behave like doublylinked lists. template< class TYPE, class ARG_TYPE >class CList : public CObject CList: member functions Iteration GetPosition Returns the position of the head element of the list. GetPosition Returns the position of the tail element of the list. GetNextGets the next element for iterating. GetPrev Gets the previous element for iterating. Retrieval/Modification GetAt Gets the element at a given position. SetAt Sets the element at a given position. RemoveAt Removes an element from this list, specified by position. Insertion InsertBefore Inserts a new element before a given position. InsertAfter Inserts a new element after a given position. Searching Find Gets the position of an element specified by pointer value. FindIndex Gets the position of an element specified by a zero-based index. Structured Programming Layout (your own style but consequent) Comment to clarify your code Naming: variables, functions, classes, etc. should be meaningful Appropriate control structures (if then, while, for) should be used Functions, and member functions should make the right division of tasks (careful top-down design) Data abstraction 7