UEE1302 (1102) F10 Introduction to Computers and Programming (I)

Size: px
Start display at page:

Download "UEE1302 (1102) F10 Introduction to Computers and Programming (I)"

Transcription

1 Computational Intelligence on Automation NCTU UEE1302 (1102) F10 Introduction to Computers and Programming (I) Programming Lecture 09 File I/O & Data Manipulation I/O Streams File I/O Learning Objectives Character I/O Tools for Stream I/O File names as input Formatting output, flag settings Stream Hierarchies Preview of inheritance Random Access to Files PRO_09 HUNG-PIN(CHARLES) WEN 2 Introduction to Streams What are streams? a transfer of information in the form of a sequence of bytes Special objects Deliver program input and output Input stream: flow into program Can come from keyboard or file Output stream: flow out of program Can go to screen or file Seen streams already!! <iostream> cin: input stream connected to keyboard cout: output stream connected to screen PRO_09 HUNG-PIN(CHARLES) WEN 3 Illustration of <iostream> Standard streams are created, connected, and disconnected automatically by OS. cin, cout, cerr, clog : behaves like a text file. buffered un-buffered PRO_09 HUNG-PIN(CHARLES) WEN 4

2 Streams Like cin & cout Given program defines stream instream that comes from some file: int number; instream >> number; Reads value from stream, assigned to variable number Program defines stream outstream that goes to some file outstream << the number is << number; Writes value to stream, which goes to file Program defines stream to come from and go to some file concurrently. PRO_09 HUNG-PIN(CHARLES) WEN 5 Illustration of File Streams input stream output stream input/output stream PRO_09 HUNG-PIN(CHARLES) WEN 6 Files File: collection of data that is stored together under common name on storage media C++ sources as text files on hard disks Reading from file When program takes input Writing to file When program sends output Start at beginning of file to end Other methods available We ll discuss this simple text file access here PRO_09 HUNG-PIN(CHARLES) WEN 7 File Names Files have two names to our programs External filename Also called physical filename Example: "input_file.txt" Sometimes considered real filename Used only once in program (to open) Stream name Also called logical filename Example: infile in "ifstream infile;" C++ program uses this name for all file activity PRO_09 HUNG-PIN(CHARLES) WEN 8

3 File Connection & File I/O Must first connect file to stream object For input: file ifstream object For output: file ofstream object Use ifstream and ofstream classes #include <fstream> using namespace std; Defined in library <fstream> Named in std namespace Alternative form #include <fstream> using std::ifstream; using std::ofstream; PRO_09 HUNG-PIN(CHARLES) WEN 9 Declaring Streams Stream must be declared like any other class variable: ifstream infile; ofstream outfile; Must then connect to file: infile.open( input_file.txt ); opening the file by member function open() can specify complete pathname filename must be c-strings Can specify filename at declaration ifstream infile( input_file.txt ); ofstream outfile( output_file.txt ); PRO_09 HUNG-PIN(CHARLES) WEN 10 File Streams Usage Once declared use normally! int onenumber, anothernumber; infile >> onenumber >> anothernumber; Output stream similar: ofstream outfile; outfile.open.open( output_file.txt ); outfile << onenumber = << onenumber << anothernumber = << anothernumber; Send items to output file flag ios::in Open File Stream w/ Flags Explanation input state; default for input file ios::out output state; default for output file ios::app Append output state. ios::ate Position file marker at the end of file ios::trunc Delete all data from an existing file when it is opened. Default for output file. ios::binary Binary file; default is text file. PRO_09 HUNG-PIN(CHARLES) WEN 11 PRO_09 HUNG-PIN(CHARLES) WEN 12

4 Closing Files Files should be closed When program completed getting input or sending output Disconnects stream from file Example: instream.close(); outstream.close(); no arguments Files automatically close when program ends Good to close opened files explicitly File Flush Output often buffered Temporarily stored before written to file Written in groups Occasionally might need to force writing: outstream.flush(); Member function flush, for all output streams All buffered output is physically written Closing file automatically calls flush() PRO_09 HUNG-PIN(CHARLES) WEN 13 PRO_09 HUNG-PIN(CHARLES) WEN 14 Appending to a File Checking File Open Success Standard open operation begins with empty file Even if file exists contents lost Open for append: ofstream outfile; outfile.open( output.txt,ios::app); If file doesn t exist creates it If file exists appends to end 2 nd argument is class ios defined constant in <iostream> library, std namespace PRO_09 HUNG-PIN(CHARLES) WEN 15 File opens could fail If input file doesn t exist No write permissions to output file Unexpected results Place call to.fail() or.is_open() to check stream operation success instream.open( stuff.txt ); if (instream.fail()) { cout << "File open failed.\n"; exit(1);.is_open() returns the opposite.fail().fail() PRO_09 HUNG-PIN(CHARLES) WEN 16

5 Checking End-of of-file w/ eof() Use loop to process file until end two ways to test for the end of file Use member function eof() instream.get(next); while (!instream.eof()) { cout << next; instream.get(next); Reads each character until file ends eof() member function returns bool Member function get() comes soon! PRO_09 HUNG-PIN(CHARLES) WEN 17 Checking End-of of-file w/ Read Second method: read operation returns bool value! a good way to read file (instream >> next) expression returns true if read successful return false if attempt to read beyond end of file In action: double next, sum = 0; while (instream >> next) sum = sum + next; cout << the sum is << sum << endl; PRO_09 HUNG-PIN(CHARLES) WEN 18 Checking File I/O Status Character I/O with Files prototype fail() eof() good() bad() description return true if the file has not been opened successfully; otherwise, return false return true if a read has been attempted past the end-of-file; otherwise, return false return true if the file is available for program use; otherwise, return false return true if a fatal error with the current stream has occurred; otherwise, false. not normally occur. All cin and cout character I/O same for files! Common character I/O functions get(), getline(): obtain characters from input file put(): put one character to output streams putback(): put back the character just read to input streams peek(): return the next character from the stream without removing it ignore(): skips over a designated number of characters PRO_09 HUNG-PIN(CHARLES) WEN 19 PRO_09 HUNG-PIN(CHARLES) WEN 20

6 get(): Read Characters from File get(): obtain characters from file and save it to the input stream. 3 forms: istream& get(char& ch); most suggested get() istream& get(char* buffer,streamsize num); istream& get(char* buffer,streamsize num, char delim); Example for Form 1: ifstream infile( input_file.dat, ios::in); char ichar; while (infile.get(ichar)) { cout << ichar; PRO_09 HUNG-PIN(CHARLES) WEN 21 getline() ():: Read a Line from File getline() (): read characters into input stream buffer until either: (num - 1) characters have been read, an EOF is encountered, or, until the character delim (normally, newline, \n ) is read. The delim character is not put into buffer. Two forms: istream& getline(char* buffer, streamsize num); istream& getline(char* buffer, streamsize num, char delim); PRO_09 HUNG-PIN(CHARLES) WEN 22 Examples of getline() put(): : Put One Character to File Example 1 (for C-String variables): int MAX_LENGTH = 100; char line[max_length]; while (infile.getline(line, MAX_LENGTH)) { cout << read line: << line << endl; Example 2 (for string variables): string line; while (getline(infile, line)) { cout << read line: << line << endl; PRO_09 HUNG-PIN(CHARLES) WEN 23 put(): put one character to the output stream and save it to the file Syntax: ostream& put(char ch); Example: ofstream outfile( output_file.dat ); string article = Today is Dec \n We still have two more lectures.\n Wish us a happy new year!\n ; for (int idx=0;idx < article.size();idx++) { outfile.put put(article[idx]); outfile.close(); PRO_09 HUNG-PIN(CHARLES) WEN 24

7 putback() ():: Put Back One Character putback() (): return the previously-read character ch to the input stream Syntax: istream& putback( char ch ); Example: // get a number or a word? ifstream infile( sample.dat ); int n = 0; char str[256]; char c = infile.get(); if ( (c >= 0 ) && (c <= 9 ) ) { infile.putback putback(c); infile >> n; // this case is a number else { infile.putback putback(c); cin >> str; //this case is a word peek(): Read/Return Next Character peek(): return the next character in the stream or EOF if the end of file is read not remove the character from the stream Example: // get a number or a word? ifstream infile( sample.dat ); int n = 0; char str[256]; char c = infile.peek peek(); if ( (c >= 0 ) && (c <= 9 ) ) { infile >> n; // this case is a number else { cin >> str; //this case is a word PRO_09 HUNG-PIN(CHARLES) WEN 25 PRO_09 HUNG-PIN(CHARLES) WEN 26 ignore(): : Skip Characters Random File Access (1/3) ignore(): read and throw away characters until num characters have been read or until the character delim is read Syntax: istream& ignore(streamsize num=1, int delim=eof); Example: char first, last; cout << Enter your first and last names: ; first = infile.get(); infile.ignore ignore(256, ); last = infile.get(); cout <<"Your name is " << first << last; PRO_09 HUNG-PIN(CHARLES) WEN 27 Sequential file organization: characters in file are stored in sequential manner Random Access: any character in an opened file can be read directly without having to read characters ahead of it File position marker: long integer that represents an offset from the beginning of each file Keep track of where next character is to be read from or written to Allow for random access of any individual character PRO_09 HUNG-PIN(CHARLES) WEN 28

8 Random File Access (2/3) Random File Access (3/3) Finding record 101 using sequential access: One file = a sequential stream of n characters ios:beg ios:cur ios:end Finding record 101 using random access: ios:beg ios:cur ios:end PRO_09 HUNG-PIN(CHARLES) WEN 29 Name seekg(offset,mode) seekp(offset,mode) tellg(void) tellp(void) description For input files, move to the offset position as indicated by the mode For output files, move to the offset position as indicated by the mode For input files, return the current value of the file position marker For output files, return the current value of the file position marker Types of modes: ios::beg: the beginning of the file ios::cur: current position of the file ios::end: the end of the file PRO_09 HUNG-PIN(CHARLES) WEN 30 Random Access Tools (1/2) Opens same as istream or ostream fstream rwstream; rwstream.open( stuff.txt,ios::in ios::out); Adds second argument Open with read and write capability Move about in file rwstream.seekp(1000); Positions put-pointer at 1000 th byte rwstream.seekg(1000); Positions get-pointer at 1000 th byte rwstream.seekp(100*sizeof(mystrcut) 1); Position put-pointer at 100th record of objects PRO_09 HUNG-PIN(CHARLES) WEN 31 Random Access Tools (2/2) seekg() and seekp() can be used with three modes: ios::beg, ios::cur and ios::end (EX 1) infile.seekg(10, ios::beg) File position marker moves to the 10 th character from the beginning of the file (EX 2) infile.seekg(-6, ios::cur) File position marker moves back 6 characters from the current position (EX 3) outfile.seekp(0, ios::end) File position marker moves to the last characters at the end of file PRO_09 HUNG-PIN(CHARLES) WEN 32

9 Parse Command Line Obtain parameters from command line by int main(int argc, char *argv[]) argc: total count of the parameters including the program name argv: indexed array of c-strings Example: >./prog dog cat tiger argc is 4 argv[0] is prog argv[1] is dog argv[2] is cat argv[3] is tiger PRO_09 HUNG-PIN(CHARLES) WEN 33 Tools: File Names as Input Stream open operation Argument to open() is c-string type Can be literal (used so far) or variable string filename; ifstream infile; cout << Enter file name: ; cin >> filename; infile.open(filename.c_str()); Provides more flexibility Open file from command line argument Ex: infile.open(argv[2]); PRO_09 HUNG-PIN(CHARLES) WEN 34 Common Programming Errors (1/2) Using file s external name in place of internal file stream object name when accessing file Opening file for output without first checking that file with given name already exists Not checking for preexisting file ensures that file will be overwritten Not understanding that end of a file is detected only after EOF sentinel has either been read or passed over Common Programming Errors (2/2) Attempting to detect end of file using character variables for EOF marker Any variable used to accept EOF must be declared as an integer variable Using integer argument with the seekg() and seekp() functions Offset must be a long integer constant or variable Any other value passed to these functions can result in unpredictable result PRO_09 HUNG-PIN(CHARLES) WEN 35 PRO_09 HUNG-PIN(CHARLES) WEN 36

10 Summary (1/2) A data file is any collection of data stored in an external storage medium under a common name A data file is connected to file stream using open() method in <fstream> connect file s external name with internal object name A file can be opened in input or output mode An opened output file stream either creates a new data file or erases data in an existing opened file PRO_09 HUNG-PIN(CHARLES) WEN 37 Summary (2/2) All file streams must be declared as objects of either the ifstream or ofstream classes Data files can be accessed randomly using the seekg(),seekp(),tellg(),and tellp() methods g versions of these functions are used to alter and query file position marker for input file streams p versions do the same for output file streams Parse command line by int main(int argc, char *argv[]) PRO_09 HUNG-PIN(CHARLES) WEN 38

Basics of I/O Streams and File I/O

Basics of I/O Streams and File I/O Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading

More information

C++ Input/Output: Streams

C++ Input/Output: Streams C++ Input/Output: Streams 1 The basic data type for I/O in C++ is the stream. C++ incorporates a complex hierarchy of stream types. The most basic stream types are the standard input/output streams: istream

More information

Member Functions of the istream Class

Member Functions of the istream Class Member Functions of the istream Class The extraction operator is of limited use because it always uses whitespace to delimit its reads of the input stream. It cannot be used to read those whitespace characters,

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 3: Input/Output C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 3: Input/Output Objectives In this chapter, you will: Learn what a stream is and examine input and output streams Explore

More information

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++) Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++) (Revised from http://msdn.microsoft.com/en-us/library/bb384842.aspx) * Keep this information to

More information

Using C++ File Streams

Using C++ File Streams Using C++ File Streams David Kieras, EECS Dept., Univ. of Michigan Revised for EECS 381, 9/20/2012 File streams are a lot like cin and cout In Standard C++, you can do I/O to and from disk files very much

More information

UEE1302 (1102) F10 Introduction to Computers and Programming

UEE1302 (1102) F10 Introduction to Computers and Programming Computational Intelligence on Automation Lab @ NCTU UEE1302 (1102) F10 Introduction to Computers and Programming Programming Lecture 03 Flow of Control (Part II): Repetition while,for & do..while Learning

More information

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers 0.. +127. char variables mostly used to store characters

More information

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1

QUIZ-II QUIZ-II. Chapter 5: Control Structures II (Repetition) Objectives. Objectives (cont d.) 20/11/2015. EEE 117 Computer Programming Fall-2015 1 QUIZ-II Write a program that mimics a calculator. The program should take as input two integers and the operation to be performed. It should then output the numbers, the operator, and the result. (For

More information

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement? 1. Distinguish & and && operators. PART-A Questions 2. How does an enumerated statement differ from a typedef statement? 3. What are the various members of a class? 4. Who can access the protected members

More information

Ubuntu. Ubuntu. C++ Overview. Ubuntu. History of C++ Major Features of C++

Ubuntu. Ubuntu. C++ Overview. Ubuntu. History of C++ Major Features of C++ Ubuntu You will develop your course projects in C++ under Ubuntu Linux. If your home computer or laptop is running under Windows, an easy and painless way of installing Ubuntu is Wubi: http://www.ubuntu.com/download/desktop/windowsinstaller

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

An Incomplete C++ Primer. University of Wyoming MA 5310

An Incomplete C++ Primer. University of Wyoming MA 5310 An Incomplete C++ Primer University of Wyoming MA 5310 Professor Craig C. Douglas http://www.mgnet.org/~douglas/classes/na-sc/notes/c++primer.pdf C++ is a legacy programming language, as is other languages

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Repetition Using the End of File Condition

Repetition Using the End of File Condition Repetition Using the End of File Condition Quick Start Compile step once always g++ -o Scan4 Scan4.cpp mkdir labs cd labs Execute step mkdir 4 Scan4 cd 4 cp /samples/csc/155/labs/4/*. Submit step emacs

More information

Appendix K Introduction to Microsoft Visual C++ 6.0

Appendix K Introduction to Microsoft Visual C++ 6.0 Appendix K Introduction to Microsoft Visual C++ 6.0 This appendix serves as a quick reference for performing the following operations using the Microsoft Visual C++ integrated development environment (IDE):

More information

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be... What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control

More information

The little endl that couldn t

The little endl that couldn t This is a pre-publication draft of the column I wrote for the November- December 1995 issue of the C++ Report. Pre-publication means this is what I sent to the Report, but it may not be exactly the same

More information

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures The C++ Language Loops Loops! Recall that a loop is another of the four basic programming language structures Repeat statements until some condition is false. Condition False True Statement1 2 1 Loops

More information

Passing 1D arrays to functions.

Passing 1D arrays to functions. Passing 1D arrays to functions. In C++ arrays can only be reference parameters. It is not possible to pass an array by value. Therefore, the ampersand (&) is omitted. What is actually passed to the function,

More information

C++ Outline. cout << "Enter two integers: "; int x, y; cin >> x >> y; cout << "The sum is: " << x + y << \n ;

C++ Outline. cout << Enter two integers: ; int x, y; cin >> x >> y; cout << The sum is:  << x + y << \n ; C++ Outline Notes taken from: - Drake, Caleb. EECS 370 Course Notes, University of Illinois Chicago, Spring 97. Chapters 9, 10, 11, 13.1 & 13.2 - Horstman, Cay S. Mastering Object-Oriented Design in C++.

More information

Compiler Construction

Compiler Construction Compiler Construction Lecture 1 - An Overview 2003 Robert M. Siegfried All rights reserved A few basic definitions Translate - v, a.to turn into one s own language or another. b. to transform or turn from

More information

System Calls Related to File Manipulation

System Calls Related to File Manipulation KING FAHD UNIVERSITY OF PETROLEUM AND MINERALS Information and Computer Science Department ICS 431 Operating Systems Lab # 12 System Calls Related to File Manipulation Objective: In this lab we will be

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

System Calls and Standard I/O

System Calls and Standard I/O System Calls and Standard I/O Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Class System calls o How a user process contacts the Operating System o For advanced services

More information

Introduction to: Computers & Programming: Input and Output (IO)

Introduction to: Computers & Programming: Input and Output (IO) Introduction to: Computers & Programming: Input and Output (IO) Adam Meyers New York University Summary What is Input and Ouput? What kinds of Input and Output have we covered so far? print (to the console)

More information

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

More information

File Handling. What is a file?

File Handling. What is a file? File Handling 1 What is a file? A named collection of data, stored in secondary storage (typically). Typical operations on files: Open Read Write Close How is a file stored? Stored as sequence of bytes,

More information

Comp151. Definitions & Declarations

Comp151. Definitions & Declarations Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

Learning Computer Programming using e-learning as a tool. A Thesis. Submitted to the Department of Computer Science and Engineering.

Learning Computer Programming using e-learning as a tool. A Thesis. Submitted to the Department of Computer Science and Engineering. Learning Computer Programming using e-learning as a tool. A Thesis Submitted to the Department of Computer Science and Engineering of BRAC University by Asharf Alam Student ID: 03101011 Md. Saddam Hossain

More information

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number

More information

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c Lecture 3 Data structures arrays structs C strings: array of chars Arrays as parameters to functions Multiple subscripted arrays Structs as parameters to functions Default arguments Inline functions Redirection

More information

Module 816. File Management in C. M. Campbell 1993 Deakin University

Module 816. File Management in C. M. Campbell 1993 Deakin University M. Campbell 1993 Deakin University Aim Learning objectives Content After working through this module you should be able to create C programs that create an use both text and binary files. After working

More information

So far we have considered only numeric processing, i.e. processing of numeric data represented

So far we have considered only numeric processing, i.e. processing of numeric data represented Chapter 4 Processing Character Data So far we have considered only numeric processing, i.e. processing of numeric data represented as integer and oating point types. Humans also use computers to manipulate

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Subject Name: Object Oriented Programming in C++ Subject Code: 2140705

Subject Name: Object Oriented Programming in C++ Subject Code: 2140705 Faculties: L.J. Institute of Engineering & Technology Semester: IV (2016) Subject Name: Object Oriented Programming in C++ Subject Code: 21405 Sr No UNIT - 1 : CONCEPTS OF OOCP Topics -Introduction OOCP,

More information

C++ Language Tutorial

C++ Language Tutorial cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

Illustration 1: Diagram of program function and data flow

Illustration 1: Diagram of program function and data flow The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline

More information

Performance Comparison of Elliptic Curve and RSA Digital Signatures

Performance Comparison of Elliptic Curve and RSA Digital Signatures Performance Comparison of Elliptic Curve and RSA Digital Signatures Nicholas Jansma [njansma@engin.umich.edu] Brandon Arrendondo [barrendo@engin.umich.edu] April 28, 2004 Abstract. This paper compares

More information

El Dorado Union High School District Educational Services

El Dorado Union High School District Educational Services El Dorado Union High School District Course of Study Information Page Course Title: ACE Computer Programming II (#495) Rationale: A continuum of courses, including advanced classes in technology is needed.

More information

Appendix M: Introduction to Microsoft Visual C++ 2010 Express Edition

Appendix M: Introduction to Microsoft Visual C++ 2010 Express Edition Appendix M: Introduction to Microsoft Visual C++ 2010 Express Edition This book may be ordered from Addison-Wesley in a value pack that includes Microsoft Visual C++ 2010 Express Edition. Visual C++ 2010

More information

13 File Output and Input

13 File Output and Input SCIENTIFIC PROGRAMMING -1 13 File Output and Input 13.1 Introduction To make programs really useful we have to be able to input and output data in large machinereadable amounts, in particular we have to

More information

Sequential Program Execution

Sequential Program Execution Sequential Program Execution Quick Start Compile step once always g++ -o Realtor1 Realtor1.cpp mkdir labs cd labs Execute step mkdir 1 Realtor1 cd 1 cp../0/realtor.cpp Realtor1.cpp Submit step cp /samples/csc/155/labs/1/*.

More information

A brief introduction to C++ and Interfacing with Excel

A brief introduction to C++ and Interfacing with Excel A brief introduction to C++ and Interfacing with Excel ANDREW L. HAZEL School of Mathematics, The University of Manchester Oxford Road, Manchester, M13 9PL, UK CONTENTS 1 Contents 1 Introduction 3 1.1

More information

Answers to Selected Exercises

Answers to Selected Exercises DalePhatANS_complete 8/18/04 10:30 AM Page 1049 Answers to Selected Exercises Chapter 1 Exam Preparation Exercises 1. a. v, b. i, c. viii, d. iii, e. iv, f. vii, g. vi, h. ii. 2. Analysis and specification,

More information

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing

CpSc212 Goddard Notes Chapter 6. Yet More on Classes. We discuss the problems of comparing, copying, passing, outputting, and destructing CpSc212 Goddard Notes Chapter 6 Yet More on Classes We discuss the problems of comparing, copying, passing, outputting, and destructing objects. 6.1 Object Storage, Allocation and Destructors Some objects

More information

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++

Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++ Question Bank UNIT 1: Introduction to C++ 1. What is Procedure-oriented Programming System? Dec 2005 2. What is Object-oriented Programming System? June 2006 3. Explain the console I/O functions supported

More information

Logging. Working with the POCO logging framework.

Logging. Working with the POCO logging framework. Logging Working with the POCO logging framework. Overview > Messages, Loggers and Channels > Formatting > Performance Considerations Logging Architecture Message Logger Channel Log File Logging Architecture

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

CS 101 Computer Programming and Utilization

CS 101 Computer Programming and Utilization CS 101 Computer Programming and Utilization Lecture 14 Functions, Procedures and Classes. primitive and objects. Files. Mar 4, 2011 Prof. R K Joshi Computer Science and Engineering IIT Bombay Email: rkj@cse.iitb.ac.in

More information

! " # $ %& %' ( ) ) *%%+, -..*/ *%%+ - 0 ) 1 2 1

!  # $ %& %' ( ) ) *%%+, -..*/ *%%+ - 0 ) 1 2 1 !" #$%&%'())*%%+,-..*/*%%+- 0 )12 1 *!" 34 5 6 * #& ) 7 8 5)# 97&)8 5)# 9 : & ; < 5 11 8 1 5)=19 7 19 : 0 5)=1 ) & & >) ) >) 1? 5)= 19 7 19 : # )! #"&@)1 # )? 1 1#& 5)=19719:# 1 5)=9 7 9 : 11 0 #) 5 A

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

COSC 6397 Big Data Analytics. Distributed File Systems (II) Edgar Gabriel Spring 2014. HDFS Basics

COSC 6397 Big Data Analytics. Distributed File Systems (II) Edgar Gabriel Spring 2014. HDFS Basics COSC 6397 Big Data Analytics Distributed File Systems (II) Edgar Gabriel Spring 2014 HDFS Basics An open-source implementation of Google File System Assume that node failure rate is high Assumes a small

More information

The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002. True or False (2 points each)

The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002. True or False (2 points each) True or False (2 points each) The University of Alabama in Huntsville Electrical and Computer Engineering CPE 112 01 Test #4 November 20, 2002 1. Using global variables is better style than using local

More information

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics

More information

Programming Languages CIS 443

Programming Languages CIS 443 Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception

More information

Package HadoopStreaming

Package HadoopStreaming Package HadoopStreaming February 19, 2015 Type Package Title Utilities for using R scripts in Hadoop streaming Version 0.2 Date 2009-09-28 Author David S. Rosenberg Maintainer

More information

An API for Reading the MySQL Binary Log

An API for Reading the MySQL Binary Log An API for Reading the MySQL Binary Log Mats Kindahl Lead Software Engineer, MySQL Replication & Utilities Lars Thalmann Development Director, MySQL Replication, Backup & Connectors

More information

Project 2: Bejeweled

Project 2: Bejeweled Project 2: Bejeweled Project Objective: Post: Tuesday March 26, 2013. Due: 11:59PM, Monday April 15, 2013 1. master the process of completing a programming project in UNIX. 2. get familiar with command

More information

Building a Multi-Threaded Web Server

Building a Multi-Threaded Web Server Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous

More information

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

PIC 10A. Lecture 7: Graphics II and intro to the if statement

PIC 10A. Lecture 7: Graphics II and intro to the if statement PIC 10A Lecture 7: Graphics II and intro to the if statement Setting up a coordinate system By default the viewing window has a coordinate system already set up for you 10-10 10-10 The origin is in the

More information

Binary storage of graphs and related data

Binary storage of graphs and related data EÖTVÖS LORÁND UNIVERSITY Faculty of Informatics Department of Algorithms and their Applications Binary storage of graphs and related data BSc thesis Author: Frantisek Csajka full-time student Informatics

More information

Storing Measurement Data

Storing Measurement Data Storing Measurement Data File I/O records or reads data in a file. A typical file I/O operation involves the following process. 1. Create or open a file. Indicate where an existing file resides or where

More information

Chapter 11: Input/Output Organisation. Lesson 06: Programmed IO

Chapter 11: Input/Output Organisation. Lesson 06: Programmed IO Chapter 11: Input/Output Organisation Lesson 06: Programmed IO Objective Understand the programmed IO mode of data transfer Learn that the program waits for the ready status by repeatedly testing the status

More information

Computer Programming C++ Classes and Objects 15 th Lecture

Computer Programming C++ Classes and Objects 15 th Lecture Computer Programming C++ Classes and Objects 15 th Lecture 엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University Copyrights 2013 Eom, Hyeonsang All Rights Reserved Outline

More information

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine 7 Objectives After completing this lab you will: know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine Introduction Branches and jumps provide ways to change

More information

Buffer Management 5. Buffer Management

Buffer Management 5. Buffer Management 5 Buffer Management Copyright 2004, Binnur Kurt A journey of a byte Buffer Management Content 156 A journey of a byte Suppose in our program we wrote: outfile

More information

Character Translation Methods

Character Translation Methods Supplement to: Irvine, Kip R. Assembly Language for Intel-Based Computers, 4th Edition. This file may be duplicated or printed for classroom use, as long as the author name, book title, and copyright notice

More information

/* File: blkcopy.c. size_t n

/* File: blkcopy.c. size_t n 13.1. BLOCK INPUT/OUTPUT 505 /* File: blkcopy.c The program uses block I/O to copy a file. */ #include main() { signed char buf[100] const void *ptr = (void *) buf FILE *input, *output size_t

More information

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print In the simplest terms, grep (global regular expression print) will search input

More information

The While Loop. Objectives. Textbook. WHILE Loops

The While Loop. Objectives. Textbook. WHILE Loops Objectives The While Loop 1E3 Topic 6 To recognise when a WHILE loop is needed. To be able to predict what a given WHILE loop will do. To be able to write a correct WHILE loop. To be able to use a WHILE

More information

ANALYSIS Egg Database Analysis Tools

ANALYSIS Egg Database Analysis Tools 1 ANALYSIS INTRODUCTION 1 1. Introduction. ANALYSIS Egg Database Analysis Tools by John Walker http://www.fourmilab.ch/ This program is in the public domain. This program implements frequently-performed

More information

CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator=

CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator= CS193D Handout 06 Winter 2004 January 26, 2004 Copy Constructor and operator= We already know that the compiler will supply a default (zero-argument) constructor if the programmer does not specify one.

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

Formatting Numbers with C++ Output Streams

Formatting Numbers with C++ Output Streams Formatting Numbers with C++ Output Streams David Kieras, EECS Dept., Univ. of Michigan Revised for EECS 381, Winter 2004. Using the output operator with C++ streams is generally easy as pie, with the only

More information

CS 103 Lab Linux and Virtual Machines

CS 103 Lab Linux and Virtual Machines 1 Introduction In this lab you will login to your Linux VM and write your first C/C++ program, compile it, and then execute it. 2 What you will learn In this lab you will learn the basic commands and navigation

More information

Answers to Review Questions Chapter 7

Answers to Review Questions Chapter 7 Answers to Review Questions Chapter 7 1. The size declarator is used in a definition of an array to indicate the number of elements the array will have. A subscript is used to access a specific element

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

Fondamenti di C++ - Cay Horstmann 1

Fondamenti di C++ - Cay Horstmann 1 Fondamenti di C++ - Cay Horstmann 1 Review Exercises R10.1 Line 2: Can't assign int to int* Line 4: Can't assign Employee* to Employee Line 6: Can't apply -> to object Line 7: Can't delete object Line

More information

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction

IS0020 Program Design and Software Tools Midterm, Feb 24, 2004. Instruction IS0020 Program Design and Software Tools Midterm, Feb 24, 2004 Name: Instruction There are two parts in this test. The first part contains 50 questions worth 80 points. The second part constitutes 20 points

More information

Operating Systems. Privileged Instructions

Operating Systems. Privileged Instructions Operating Systems Operating systems manage processes and resources Processes are executing instances of programs may be the same or different programs process 1 code data process 2 code data process 3

More information

Advanced Bash Scripting. Joshua Malone (jmalone@ubergeeks.com)

Advanced Bash Scripting. Joshua Malone (jmalone@ubergeeks.com) Advanced Bash Scripting Joshua Malone (jmalone@ubergeeks.com) Why script in bash? You re probably already using it Great at managing external programs Powerful scripting language Portable and version-stable

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

More information

ESPResSo Summer School 2012

ESPResSo Summer School 2012 ESPResSo Summer School 2012 Introduction to Tcl Pedro A. Sánchez Institute for Computational Physics Allmandring 3 D-70569 Stuttgart Germany http://www.icp.uni-stuttgart.de 2/26 Outline History, Characteristics,

More information

Chapter 9 Text Files User Defined Data Types User Defined Header Files

Chapter 9 Text Files User Defined Data Types User Defined Header Files Chapter 9 Text Files User Defined Data Types User Defined Header Files 9-1 Using Text Files in Your C++ Programs 1. A text file is a file containing data you wish to use in your program. A text file does

More information

5 Arrays and Pointers

5 Arrays and Pointers 5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of

More information

While Loop. 6. Iteration

While Loop. 6. Iteration While Loop 1 Loop - a control structure that causes a set of statements to be executed repeatedly, (reiterated). While statement - most versatile type of loop in C++ false while boolean expression true

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

Course notes Standard C++ programming

Course notes Standard C++ programming Department of Cybernetics The University of Reading SE2B2 Further Computer Systems Course notes Standard C++ programming by Dr Virginie F. Ruiz November, 03 CREATING AND USING A COPY CONSTRUCTOR... 27

More information

Running your first Linux Program

Running your first Linux Program Running your first Linux Program This document describes how edit, compile, link, and run your first linux program using: - Gnome a nice graphical user interface desktop that runs on top of X- Windows

More information

Stacks. Linear data structures

Stacks. Linear data structures Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

More information

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

More information

Class Notes for CSCI 104: Data Structures and Object-Oriented Design

Class Notes for CSCI 104: Data Structures and Object-Oriented Design Class Notes for CSCI 104: Data Structures and Object-Oriented Design David Kempe and the awesome Fall 2013 sherpas August 12, 2016 2 Preface These lecture notes grew out of class notes provided for the

More information

7.7 Case Study: Calculating Depreciation

7.7 Case Study: Calculating Depreciation 7.7 Case Study: Calculating Depreciation 1 7.7 Case Study: Calculating Depreciation PROBLEM Depreciation is a decrease in the value over time of some asset due to wear and tear, decay, declining price,

More information