Chapter 18 – Miscellaneous Topics. Multiple File Programs u Makes possible to accommodate many programmers working on same project u More efficient to.

Slides:



Advertisements
Similar presentations
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Advertisements

Computer Organization & Assembly Language
Alford Academy Business Education and Computing1 Advanced Higher Computing Based on Heriot-Watt University Scholar Materials File Handling.
Chapter 14: Overloading and Templates C++ Programming: Program Design Including Data Structures, Fifth Edition.
Advanced Topics Object-Oriented Programming Using C++ Second Edition 13.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Sixth.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 17 - The Preprocessor Outline 17.1Introduction 17.2The #include Preprocessor Directive 17.3The.
Introduction to C Programming Overview of C Hello World program Unix environment C programming basics.
Chapter 1 Data Storage. 2 Chapter 1: Data Storage 1.1 Bits and Their Storage 1.2 Main Memory 1.3 Mass Storage 1.4 Representing Information as Bit Patterns.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction.
Chapter 2 Data Types, Declarations, and Displays
Guide To UNIX Using Linux Third Edition
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
Chapter 15: Operator Overloading
 2007 Pearson Education, Inc. All rights reserved C Preprocessor.
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 19 - The Preprocessor Outline 19.1 Introduction 19.2 The #include Preprocessor Directive 19.3.
1 Project 7: Huffman Code. 2 Extend the most recent version of the Huffman Code program to include decode information in the binary output file and use.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Seventh.
Stream Handling Streams - means flow of data to and from program variables. - We declare the variables in our C++ for holding data temporarily in the memory.
Darbas su failais Arnas Terekas IT 1gr. Vilniaus universitetas Matematikos ir informatikos fakultetas.
CSU0014 Assembly Languages Homepage: Textbook: Kip R. Irvine, Assembly Language for Intel-Based Computers,
Summer 2014 Chapter 1: Basic Concepts. Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Chapter Overview Welcome to Assembly Language.
Assembly Language for x86 Processors 7th Edition
Pengantar Teknologi Informasi dan Ilmu Komputer Information Technology and Data Representation PTIIK- UB.
STREAMS AND FILES OVERVIEW.  Many programs are "data processing" applications  Read the input data  Perform sequence of operations on this data  Write.
The Structure of a C++ Program. Outline 1. Separate Compilation 2. The # Preprocessor 3. Declarations and Definitions 4. Organizing Decls & Defs into.
Bit Manipulation when every bit counts. Questions on Bit Manipulation l what is the motivation for bit manipulation l what is the binary, hexadecimal,
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 5 – Dental Payment Application: Introducing.
An Introduction to Programming with C++ Sixth Edition Chapter 14 Sequential Access Files.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessing Lecture 12 April 7, 2005.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 13 File Input and.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Introduction to C++ Starting Out with C++ Early Objects Sixth.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 15: Overloading and Templates.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
THE PREPROCESSOR
The Preprocessor Directives Introduction Preprocessing – Occurs before program compiled Inclusion of external files Definition of symbolic constants.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 13 - The Preprocessor Outline 13.1Introduction 13.2The #include Preprocessor Directive 13.3The.
1 Object-Oriented Programming -- Using C++ Andres, Wen-Yuan Liao Department of Computer Science and Engineering De Lin Institute of Technology
Object Oriented Programming COP3330 / CGS5409.  Class Templates  Bitwise Operators.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Hello world !!! ASCII representation of hello.c.
Windows Programming Lecture 06. Data Types Classification Data types are classified in two categories that is, – those data types which stores decimal.
Chapter 1 slides1 What is C? A high-level language that is extremely useful for engineering computations. A computer language that has endured for almost.
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.
Computer Programming II Lecture 9. Files Processing - We have been using the iostream standard library, which provides cin and cout methods for reading.
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.
13 C Preprocessor.
Bitwise Operations C includes operators that permit working with the bit-level representation of a value. You can: - shift the bits of a value to the left.
CSE 220 – C Programming Expressions.
Chapter Topics The Basics of a C++ Program Data Types
The Machine Model Memory
Chapter 2: Introduction to C++
Instructor: David Ferry
Chapter 13 - The Preprocessor
C Basics.
Basic Elements of C++ Chapter 2.
Chapter 1 Data Storage.
Chapter 14 Bitwise Operators Objectives
C Preprocessor(CPP).
Embedded Programming in C
Bits and Bytes Topics Representing information as bits
Fundamentals of Python: First Programs
Presentation transcript:

Chapter 18 – Miscellaneous Topics

Multiple File Programs u Makes possible to accommodate many programmers working on same project u More efficient to manage large amount of source code u Can incorporate class libraries in separate files from independent vendors Lesson 18.1

Using Header Files u Header file is source code file u Inserted into program source code before program compiled u Can create own header files u Option of having separate files for class definitions, implementations, and main –Placed in different header files and use #include Lesson 18.1

Working With Header Files u Creating header file –Source code file with extension.h u Including header files –#include “name.h” u Header file contents –Put each class definition and each class implementation in separate files Lesson 18.1

Header File Contents u Three lines needed –Two at top and one at bottom –Messages to preprocessor and not compiled #ifndef name_h #define name_h … source code … #endif Lesson 18.1

Preprocessor Directives #ifdefTrue if identifier defined in previous preprocessor #ifTrue block executed if constant expression following is true #elseForms false block for #if #endifMarks end of conditional inclusion #ifndefTrue if identifier NOT defined previously #elifWorks similar to “else if” #undefUndefines previously defined identifier Lesson 18.1

Another Method u More efficient connecting files with IDE –Integrated Development Environment u Save correctly working files as object code u Link after all changes have been recompiled Lesson 18.1

Bitwise Manipulations u Very low-level operations u Manipulate individual bits (1s and 0s) u C++ provides bitwise operators –Six operators u Bit values –set if value is 1 –clear if value is 0 Lesson 18.2

Why Use Bitwise Operators u To control peripherals u To use as flags –Use individual bits instead of integers u File encryption u Array handling for any array that has members with only two possible states Lesson 18.2

Bitwise Operators u AND& u Inclusive OR| u Exclusive OR^ –Also called XOR u Complement~(unary operator) u Right shift>> u Left shift<< Lesson 18.2

Hexadecimal Notation Lesson 18.2 HexadecimalBinary Bit Pattern

bitwise And / inclusive OR u Work similar to counterparts && and || u 1 & 1 = 1, all others evaluate to 0 1 & 0 = 0, 0 & 1 = 0, 0 & 0 = 0 u 0 | 0 = 0, all others evaluate to 1 0 | 1 = 1, 1 | 0 = 1, 1 | 1 = 1 Lesson 18.2

Example (Hex 3 with Hex 6) Lesson 18.2 Bitwise AND Bitwise OR hex & | hex = = & &&& | | | | hex 2hex 7

Complement Operator ~ u Reverses all bits of operand ~(1010) = 0101 Lesson 18.2

Bitwise Exclusive OR ^ u Evaluate to 0 if both operands the same 0 ^ 0 = 01 ^ 1 = 0 0 ^ 1 = 11 ^ 0 = 1 Lesson 18.2

Bitwise Shift Operators u Move all bits in cell either right or left directions u Add clear bits in shift >> 1 << Lesson 18.2

Comments u Can shift more than one bit u Bitwise operators can only be used on integer data types u All systems do NOT use same bitwise representations –May get different results Lesson 18.2

Binary Files u Efficient since do not have to convert from ASCII u Saves execution time u Not “human friendly”, text files better u Cannot be used with editing software u Cannot be printed Lesson 18.3

Opening Output File for Binary ofstream out_ob (“name”, ios :: out | ios :: binary); Lesson 18.3 programmer-chosen output file object name filename

Opening Input File for Reading in Binary ifstream in_ob (“name”, ios :: in | ios :: binary); programmer-chosen input file object name filename Lesson 18.3

Writing to File in Binary out_ob.write (reinterpret_cast (address), num_bytes); Lesson 18.3 Programmer-chosen output file object nameAddress of beginning of memory cells being written to file Number of bytes to be copied from memory to file

Reading From a Binary File in.ob.read (reinterpret_cast (address), num_bytes); Lesson 18.3 Programmer-chosen input file object name Address of beginning of memory cells to which bytes are copied Number of bytes to be copied from file to memory Operator that makes C++ interpret address to represent beginning of an array of characters

Closing the File u Close file after writing u Can open later for reading again Lesson 18.3 outfile.close ( )

Summary u Benefits of multiple file organization u How to use header files u How to use bitwise operators u How to work with binary files