File Organization and Processing CS 215 2 nd Term 2010-2011 Basic file operations Cairo University Faculty of Computers and Information.

Slides:



Advertisements
Similar presentations
Object Oriented Programming COP3330 / CGS5409.  C++ Automatics ◦ Copy constructor () ◦ Assignment operator =  Shallow copy vs. Deep copy  DMA Review.
Advertisements

CMSC 2021 C++ I/O and Other Topics. CMSC 2022 Using C++ Stream I/O Default input stream is called cin Default output stream is called cout Use the extraction.
Folk/Zoellick/Riccardi, File Structures 1 Objectives: To get familiar with Logical files vs. physical files File processing operations File processing.
1 Classes with Pointer Data Members (II) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230.
Chapter 10.
CSE 222 Systems Programming Time, Errors, and File Access Dr. Jim Holten.
CS-212 C++ I/O Dick Steflik. C++ I/O Modeled after UNIX’s concept of a “stream” –conceptionally a stream is a continuous flow of characters/bytes from.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
ASP.NET Programming with C# and SQL Server First Edition
Programming Fundamentals (750113) Ch1. Problem Solving
Principles of Procedural Programming
From C++ to C#. Web programming The course is on web programming using ASP.Net and C# The course is on web programming using ASP.Net and C# ASP.Net is.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Java ProgrammingtMyn1 Java Programming Timo Mynttinen Mikkeli University of Applied Sciences.
Final Exam Review Closed book Closed laptop One sheet of notes permitted SE-0010 Dr. Mark L. Hornick 1.
Game Programming in Java Dr. Jeyakesavan Veerasamy CS faculty, The University of Texas at Dallas Website:
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
CMSC 2021 CMSC 202 Computer Science II for Majors Fall 2002 Mr. Frey (0101 – 0104) Mr. Raouf (0201 – 0204)
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
Introduction to Programming Using C Files. 2 Contents Files Working with files Sequential files Records.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
Data Types and Operations On Data Objective To understand what data types are The need to study data types To differentiate between primitive types and.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Monday, Mar 31, 2003Kate Gregory with material from Deitel and Deitel Week 12 Labs 4 and 5 are back File IO Looking ahead to the final.
Fundamental File Processing Operations C++
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 13 File Input and.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
1 IT 252 Computer Organization and Architecture Interaction Between Systems: File Sharing R. Helps.
Salman Marvasti Sharif University of Technology Winter 2015.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
Pointers *, &, array similarities, functions, sizeof.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Today: –Review declaration, implementation, simple class structure. –Add an exception class and show.
CMSC 2021 CMSC 202 Computer Science II for Majors Spring 2003 Mr. Frey (0101 – 0104) Mr. Raouf (0201 – 0204)
Fall 2015CISC/CMPE320 - Prof. McLeod1 CISC/CMPE320 Assignment 1 due Friday, 7pm. RAD due next Friday. Presentations week 6. Today: –More details on functions,
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
1 CS Programming Languages Class 22 November 14, 2000.
Learners Support Publications Working with Files.
Lecture 14 Arguments, Classes and Files. Arguments.
Monday, Jan 27, 2003Kate Gregory with material from Deitel and Deitel Week 4 Questions from Last Week Hand in Lab 2 Classes.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Presentation By :- Nikhil R. Anande ( ) Electronic & Communication Engineering. 3 nd Year / 5 th Semester FACULTY GUIDE : RAHIUL PATEL SIR MICROCONTROLLER.
FILE I/O: Low-level 1. The Big Picture 2 Low-Level, cont. Some files are mixed format that are not readable by high- level functions such as xlsread()
Lecture 2 Fundamental File: Processing Operations
CS212: Object Oriented Analysis and Design
Chapter 2 Objects and Classes
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
7. Inheritance and Polymorphism
CS-103 COMPUTER PROGRAMMING
Agenda Warmup Finish 2.4 Assignments
Chapter 7 Text Input/Output Objectives
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
The dirty secrets of objects
I/O in C Lecture 6 Winter Quarter Engineering H192 Winter 2005
Programming Funamental slides
Programming Fundamentals (750113) Ch1. Problem Solving
files Dr. Bhargavi Goswami Department of Computer Science
Programming Funamental slides
File Input and Output.
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Operator Overloading; String and Array Objects
File I/O in C++ II.
Presentation transcript:

File Organization and Processing CS nd Term Basic file operations Cairo University Faculty of Computers and Information

CS215 – File Structures - Sherif Khattab 2 2 nd Term course objectives learn how to use files in your programs efficiently understand how database management systems (e.g., oracle, mysql, sql server) work learn fundamental problems in computing and analyze and evaluate their alternative solutions

CS215 – File Structures - Sherif Khattab 3 2 nd Term Why file structures? get data from files in as few disk accesses as possible – disk access is about 1 million times slower than RAM access increase the possibility of caching (i.e., reusing the data you fetch from disk into RAM)

CS215 – File Structures - Sherif Khattab 4 2 nd Term Book approach study the history of file structure design (since 1970) – analyze the problems faced and solutions proposed history repeats itself :) most of the file design problems that you will face are similar to old problems develop two toolkits – conceptual: the common fundamental solutions – object-oriented: a set of c++ classes to implement these solutions

CS215 – File Structures - Sherif Khattab 5 2 nd Term object-oriented design review what’s wrong in the above example? – yes, class variables should go into the private section! – the book is somehow “old” :)

CS215 – File Structures - Sherif Khattab 6 2 nd Term object-oriented design review class has a pointer, hence the big three are there (destructor, copy constructor, and assignment operator). – can you write the implementation of these functions?

CS215 – File Structures - Sherif Khattab 7 2 nd Term conversion operator we have seen operator overloading of assignment (=), arithmetic (+, -, *, etc.), and boolean (, ==, etc.) operators type conversion operators are needed to convert from the class type to other data types without a conversion operator from String to char *, the third line in the above code gives a compilation error – strcpy function expects two char * parameters

CS215 – File Structures - Sherif Khattab 8 2 nd Term conversion operator operator char * is a type conversion operator from String to char * the implementation returns a copy (using strdup function) of the string private variable in modern c++ compilers, the operator has no return – operator char *() instead of char * operator char *()

CS215 – File Structures - Sherif Khattab 9 2 nd Term physical and logical files phone sets = file handles in the program (e.g., fstream objects) the number of files that a program opens concurrently (in the same time) is limited

CS215 – File Structures - Sherif Khattab 10 2 nd Term Feedback

CS215 – File Structures - Sherif Khattab 11 2 nd Term Feedback

CS215 – File Structures - Sherif Khattab 12 2 nd Term Feedback slides code samples course is easy, we need more

CS215 – File Structures - Sherif Khattab 13 2 nd Term ways to open, read/write, and close files in c++, there are 3 ways that a program can use files: – open, read or write, and close each method provides a certain level of abstraction (hiding of details) – 1 st method: lowest-level (more details) – 2 nd method: a little less details – 3 rd method: more details are hidden

CS215 – File Structures - Sherif Khattab 14 2 nd Term st method (fcntl.h) using integer file descriptors – the integer represent the phone set number :) – reading, writing, and closing use that integer not the file name flags tell the operating system how you want your file opened

CS215 – File Structures - Sherif Khattab 15 2 nd Term st method flags can be combined by bit-wise ORING (the | operator) the protection mode tells the operating system who and how users can access your file (permissions)

CS215 – File Structures - Sherif Khattab 16 2 nd Term nd method (stdio.h) 2 nd method is called C streams the file descriptor integer is encapsulated in a sturcture named struct_iobuf or FILE the type string encapsulates flags of the 1 st method

CS215 – File Structures - Sherif Khattab 17 2 nd Term rd method (fstream.h) 3 rd method is called c++ streams file descriptor is encapsulated in fstream object mode defined in the ios class encapsulates the flags – ios::in, ios::out, ios::noreplace, ios::binary, ios::nocreate

CS215 – File Structures - Sherif Khattab 18 2 nd Term program to display file contents

CS215 – File Structures - Sherif Khattab 19 2 nd Term st method #include int main( ) { char ch; int file; // file descriptor char filename[20]; printf("Enter the name of the file: ");// Step 1 fgets(filename, 20, stdin);// Step 2 filename[strlen(filename)-1] = 0; file = open(filename, O_RDONLY);// Step 3 while (read(file, &ch, 1) != 0)// Step 4a printf("%c", ch);// Step 4b close(file);// Step 5 return 0; }

CS215 – File Structures - Sherif Khattab 20 2 nd Term nd method

CS215 – File Structures - Sherif Khattab 21 2 nd Term rd method

CS215 – File Structures - Sherif Khattab 22 2 nd Term comments gets is unsafe. why? – use fgets – safer but? the return type of the main function check that the file was opened correctly check code samples on the course web site!