Programming In C++ Spring Semester 2013 Lecture 8 Programming In C++, Lecture 8 By Umer Rana.

Slides:



Advertisements
Similar presentations
Character Arrays (Single-Dimensional Arrays) A char data type is needed to hold a single character. To store a string we have to use a single-dimensional.
Advertisements

Programming In C++ Spring Semester 2013 Practice 1-3 Lectures Programming In C++, Lecture 3 By Umer Rana.
Programming In C++ Spring Semester 2013 Lecture 11 Programming In C++, Lecture 11 By Umer Rana.
Lecture 9: Character and String
DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
Lecture 2 Introduction to C Programming
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Chapter 7 Programming with DOS and BIOS Function Calls Objectives: The use of DOS and BIOS function call How to read the PC’s keyboard How to send text.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 6P. 1Winter Quarter I/O in C Lecture 6.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
 2007 Pearson Education, Inc. All rights reserved C Formatted Input/Output.
Graphical Tree-Based Scientific Calculator: CalcuWiz Will Ryan Christian Braunlich.
Word Processing basics
TOPIC: KEYBOARD PRESENTED BY: MS. AMBER AMAR. DEFINITON OF KEYBOARD Keyboard is an input device which resembles with a type writer like keys that enables.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
Review Questions for Chapter 1 Test
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Chapter 5: Data Input and Output Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
TERMS TO KNOW. Desktop This does not mean a computer desktop vs. a laptop. You probably keep a number of commonly used items on your desk at home such.
 Pearson Education, Inc. All rights reserved Formatted Output.
 2005 Pearson Education, Inc. All rights reserved Formatted Output.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Information Technology Word Processing. Word Processing is the preparation of documents such as letters, reports, memos, books, or any other type of correspondences.
1 The EDIT Program The Edit program is a full screen text editor that allows you to: Create text files Create text files Edit an existing text files Edit.
Basic Computer and Word Functions, part 1 Read the information and use to answer the questions in the Basic Computer and Word Functions Study Guide.
1 Screen and Keyboard Operations Suthida Chaichomchuen
Microsoft Word ITE115 Trisha Cummings. MsWord - Word Processing Program Allows you to create Letters, Envelopes, Mailing Labels, Memo’s , Fax’s.
Chapter 2: Java Fundamentals
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Computer Science Binary. Binary Code Remember the power supply that is inside your computer and how it sends electricity to all of the components? That.
Chapter Three The UNIX Editors.
Chapter-4 Managing input and Output operation.  Reading, processing and writing of data are three essential functions of a computer program.  Most programs.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
Chapter -7 Basic function of Input/output system basics and file processing Stream classes : I/O Streams. A stream is a source or destination for collection.
Hosted by Mrs. Krewson
{ General Layout of a Keyboard Laptop or Desktop.
Command Prompt Chapter 9 Pipes, Filters, and Redirection ©Richard Goldman 11/30/2000 Revised 10/16/2001.
ROM BIOS Chapter 9. The ROM BIOS PC computer come with a set od built in routines collectively called the ROM BIOS. These routines are permanent part.
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
Lesson No : 8 Intro. to Word 2000,File mgmt, Editing, Formatting & print. Doc. CHBT-01 Basic Micro process & Computer Operation.
CSC Programming for Science Lecture 18: More Data Files.
Project Assignment Snake Game/Car Acceleration Meter Min 10 Pages 10 min Presentation Max 5 group members Submitting Date: lab 2:Dec 27, 2014 Lab 3: Dec.
CCSA 221 Programming in C INPUT AND OUTPUT OPERATIONS IN C – PART 1 1.
09/06/ Data Representation ASCII, Binary Denary Conversion, Integer & Boolean data types.
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.
28 Formatted Output.
Binary Representation in Text
Binary Representation in Text
C Formatted Input/Output
Basic Computer Vocabulary
Chapter 22 – part a Stream refer to any source of input or any destination for output. Many small programs, obtain all their input from one stream usually.
TMF1414 Introduction to Programming
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
C Programming Getting started Variables Basic C operators Conditionals
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
ASCII and Unicode.
Presentation transcript:

Programming In C++ Spring Semester 2013 Lecture 8 Programming In C++, Lecture 8 By Umer Rana

Extended Keyboard Codes Programming In C++, Lecture 8 By Umer Rana As we know that keyboard usually generates the ASCII codes for letters, numbers and punctuation. Such keys all generate one-byte ASCII codes. However, there are a great many keys and key combinations not represented by this one-byte character set. For instance, the function keys, F1 to F10, are not represented by a single byte. That keys consists of two bytes; the first byte is 0 and the second byte is a number indicating the particular key(Extended Code). Extended keyboard codes use two characters, the first of which has an ASCII value of 0.

Programming In C++, Lecture 8 By Umer Rana Normal v/s Extended Codes Normal code 1 byte letter ‘a’ Extended code 2 bytes function key F1

Programming In C++, Lecture 8 By Umer Rana Normal v/s Extended Codes { unsigned char key, key2; while ( ( key=getch( ) )!= '\r' ) if (key==0) { key2=getch(); printf("%3d %3d\n", key, key2); } else printf("%3d\n", key); getche(); }

Programming In C++, Lecture 8 By Umer Rana Cursor Control with ANSI.SYS Cursor control is achieved with ANSI.SYS using escape sequences (a string of several special characters). Void main (void) { while ( getche ( ) != ‘\r’)// Printer Character printf(“\x1B[B”);// Cursor Down } ALL ANSI.SYS commands begin with the escape sequence, “\x1B[“

Programming In C++, Lecture 8 By Umer Rana Cursor Control with ANSI.SYS CodeEffect “[2j”Erase Screen & home Cursor “[K”Erase to end of line “[A”Cursor Up one row “[B”Cursor Down one row Have many more codes see the Book Page 284

Programming In C++, Lecture 8 By Umer Rana Cursor Control with Keyboard As we know about extended character codes and cursor control, we can put both ideas together to control the cursor with the arrow keys. #define CLEAR “\x1B[2J” #define C_LEFT “\x1B[D” #define C_RITE “\x1B[C” #define C_UP “\x1B[A” #define C_DOWN “\x1B[B” #define L_ARRO 75 #define R-ARRO 77 #define U-ARRO 72 #define D-ARRO 80 #define ACROSS 205 #define UPDOWN 186

Programming In C++, Lecture 8 By Umer Rana Cursor Control with Keyboard Void main (void) { Int key; Printf(CLEAR); While ( (key=getch() ) ==0) { Key=getch(); Switch (key) { case L_ARRO:printf(C_LEFT); putch(ACROSS); break; case R_ARRO:printf(C_RITE); putch(ACROSS); break; case U_ARRO:printf(C_UP); putch(UPDOWN); break; case D_ARRO:printf(C_DOWN); putch(UPDOWN); break; } Printf(C_LEFT); }

Programming In C++, Lecture 8 By Umer Rana Cursor Control with Keyboard putch(): This function is analogous to the getch() function, except that it prints a character on the screen, rather than reading a character from the keyboard.

Programming In C++, Lecture 8 By Umer Rana Moving the Cursor to an Arbitrary Position #define CLEAR “\x1B[2j” #define ERASE“\x1B[K” void main () { int row=1,col=1; while(row !=0) { printf(“\x1B[23;1f”); printf(ERASE); printf(“Type row & column number (from 10,40):”); scanf(“%d,%d”,&row,&col); printf(“\x1B[%d;%df”,row,col); printf(“*(%d,%d)”,row,col); }

Programming In C++, Lecture 8 By Umer Rana Character Attributes The “Attribute” of a Character describes its apperance: e.g.Print in Bold,Nomal, blinking, UnderLine or in Reverse Every character displayed on the screen is stored in the computer’s memory as two bytes. One byte contains the normal code for the character, while the other bytes contains the character’s attribute. Attribute of Character or String using to set ANSI.sys escape sequence following the bracket, consists of a number, followed by the letter ‘m’. e.g. “\x1B[0m”

Programming In C++, Lecture 8 By Umer Rana Character Attributes 0 Turn off Attribute, “\x1B[0m” Normal White on Black 1 Bold “\x1B[1m” 4 Underline “\x1B[4m” 5Blinking “\x1B[5m” 7Reverse “\x1B[7m” 8 Invisible “\x1B[8m”

Programming In C++, Lecture 8 By Umer Rana Command-Line Arguments When we invoke the program from the operating system, we can type not only the name of the program, but various other items as well, such as the name of a file the application is to work on. C>wordproc letter.txt “letter.txt” is used as a command line argument an argument that appears on the command line.

Programming In C++, Lecture 8 By Umer Rana Redirection The MS-DOS operating system incorporates a powerful feature that allows a program to read and write files even when this capability has not been build into the program. This is done through a process called Redirection. Redirection provides an easy way to save the results of a program; its use vaguely similar to that of the [Ctrl][PrtSc] key combination to save program output to the printer, except that the results can be sent to a disk file. Similarly, Redirection can be used to read information from a disk file directly into a program. Output can be Redirected to go to a file instead of the screen; input can be Redirected to come from a file instead of the keyboard.

Programming In C++, Lecture 8 By Umer Rana Redirection Redirection Output The Redirection output operator which is the greater than symbol(>), causes any output intended for the screen to be written to the file whose name follows the operator. C:> programName > file.txt The data to be redirected to a file does not need to be typed by user, the program itself can generate it. Any output normally send to the screen can be redirected to a disk file.

Programming In C++, Lecture 8 By Umer Rana Redirection Redirection Input The Redirection input operator which is the Less than symbol(<), causes redirect the input to a program so, instead of reading characters from the keyboard the program reads them from the file. C:> programName < file.txt