Downloaded from

Similar documents
Q4. Based on File Handling 6-8 Marks File Pointers tellg() tellp() seekp()seekg() 1-2 Marks Binary File 4 Marks Text file 2 Marks

DATA FILE HANDLING FILES. characters (ASCII Code) sequence of bytes, i.e. 0 s & 1 s

(1)Given a binary file PHONE.DAT, containing records of the following structure type class Phonlist { char Name[20]; char Address[30]; char

Computer programs are associated to work with files as it helps in storing data & information permanently. File - itself a bunch of bytes stored on

BRAIN INTERNATIONAL SCHOOL. Computer Science Assignment CLASS XII OCTOBER 2018 Chapter-7. Data File Handling in C++ Text Files

QUESTION BANK SUB: COMPUTER SCIENCE(083)


File.seekp(File.tellp( )-sizeof(c)); //Statement 1 //File.seekp(Record*sizeof(C));

KENDRIYA VIDYALAYA SANGATHAN, CHENNAI REGION COMPUTER SCIENCE (083)

(a) Differentiate between a call by value and call by reference method.

Data File Handling FILL IN THE BLANKS EACH QUESTION CARRY 1 MARK

CHAPTER-7 Data File Handling

Computer Science, Class XII, Chapter No.7 (Data File Handling)

Sample Paper 2013 SUB: COMPUTER SCIENCE GRADE XII TIME: 3 Hrs Marks: 70

KENDRIYA VIDYALAYA SANGATHAN ERNAKULAM REGION FIRST PRE-BOARD EXAMINATION COMPUTER SCIENCE

COMPUTER SCIENCE Time allowed : 3hours] [Maximum Marks :70

Sample Paper, 2015 Subject: Computer Science Class 12 th

DATA FILE HANDLING. The function should create another file OUT.TXT with the text

KENDRIYA VIDYALAYA SANGATHAN- ERNAKULAM REGION MODEL PAPER - CLASS XII COMPUTER SCIENCE (083)

KENDRIYA VIDYALAYA SANGATHAN TINSUKIA REGION PRE BOARD EXAMINATION SUBJECT COMPUTER SCIENCE

Model Sample Paper 2015

Mock Test Paper-3. Computer Science. Duration : 3hrs Max Marks : 70

91/1 COMPUTER SCIENCE. Series SHC/1. dksm ua- jksy ua- Code No. Roll No. Candidates must write the Code on the title page of the answer-book.

DELHI PUBLIC SCHOOL, RUBY PARK, KOLKATA CLASS XII SUBJECT: COMPUTER SCIENCE QUESTION BANK FILE HANDLING:-

After going through this lesson, you would be able to: store data in a file. access data record by record from the file. move pointer within the file

SAMPLE PAPER-2015 Class-XII SUB:-COMPUTER SCIENCE

Downloaded from

KENDRIYA VIDYALAYA IIT CAMPUS CHENNAI 36 COMPUTER SCIENCE. Half Yearly

COMPUTER SCIENCE(083) SAMPLE QUESTION PAPER CLASS XII

KendriyaVidyalayaSangathan Kolkata Region

CLASS XII COMPUTER SCIENCE(083) TimeAllowed : 3 HrsMax Marks : 70

CLASS XII GUESS PAPER COMPUTER SCENCE (083)

C++ Binary File I/O. C++ file input and output are typically achieved by using an object of one of the following classes:

void main() { int global=7 ; func( ::global,global) ; cout<<global<<, <<::global<< \n ; func(global,::global) ; cout<<global<<, <<::global<< \n ; }

Unit-V File operations


JB Academy, Faizabad Half Yearly Examination Subject: Computer Science (083) Class XII

1. a) Find the correct identifiers out of the following, which can be 2 used for naming Variable, Constants or Functions in a C++ program:

BHARATIYA VIDYA BHAVAN S V.M.PUBLIC SCHOOL, VADODARA. Class : XII SAMPLE PAPER Max Marks : 70

KE DRIYA VIDYALAYA SA GATHA,CHE AI REGIO. COMMO PRE-BOARD EXAMI ATIO COMPUTER SCIE CE CLASS- XII Time allowed : 3 hours Maximum Marks : 70

Convenient way to deal large quantities of data. Store data permanently (until file is deleted).

Sample Paper COMPUTER SCIENCE (Theory) Class-XII Time Allowed: 3hours Maximum Marks: 70

(d) Rewrite the following program after removing all the syntax error(s), if any. [2] include <iostream.h> void main ( )

Study Material for Class XII. Data File Handling

Code No. 083 Time allowed: 3 hours Maximum Marks: 70 Instructions: (i) All questions are compulsory. (ii) Programming language: C++

void Add() { cin >> trainnumber; gets(trainname); } void display() { cout<<trainnumber <<":"<<TrainName<<end;

DELHI PUBLIC SCHOOL BOKARO STEEL CITY

ios ifstream fstream

Chapte t r r 9

CLASS XII SECOND TERM EXAMINATION SUBJECT : COMPUTER SCIENCE SET A2 (SOLUTIONS)

CBSE GUESS PAPER. Roll No. Computer Sc. XII(083)/

C++ How to Program 14.6


Advanced File Operations. Review of Files. Declaration Opening Using Closing. CS SJAllan Chapter 12 2

Random File Access. 1. Random File Access

Developed By : Ms. K. M. Sanghavi

C++ Programming Lecture 10 File Processing

CLASS XII SECOND TERM EXAMINATION SUBJECT : COMPUTER SCIENCE SET A1(SOLUTIONS)

Disadvantages: Not suitable for long distance due to high attenuation. Low bandwidth support. Low Speed

Object Oriented Programming Using C++ UNIT-3 I/O Streams

KENDRIYA VIDYALAYA SANGATHAN BHUBANESWAR REGION SECOND PREBOARD EXAMINATION FOR CLASS XII SUBJECT: COMPUTER SCIENCE

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Ch - 7. Data File Handling

Chapter-12 DATA FILE HANDLING

This chapter introduces the notion of namespace. We also describe how to manage input and output with C++ commands via the terminal or files.

KENDRIYA VIDYALAYA SANGATHAN ERNAKULAM REGION FIRST COMMON PRE BOARD EXAMINATION CLASS:XII - (COMPUTER SCIENCE )

91/1 COMPUTER SCIENCE. Series SHC/1. dksm ua- jksy ua- Code No. Roll No. Candidates must write the Code on the title page of the answer-book.

IS 0020 Program Design and Software Tools

DISK FILE PROGRAM. ios. ofstream

C++ files and streams. Lec 28-31

Guru Harkrishan Public School, Karol Bagh Pre Mock Class XII Sub: COMPUTER SCIENCE Allowed :3 hrs

CBSE 12th Computer Science Question Papers

Physical Files and Logical Files. Opening Files. Chap 2. Fundamental File Processing Operations. File Structures. Physical file.

Computer Science 330 Assignment

KUWAIT SAHODAYA EXAMINATION FIRST TERM SUBJECT : COMPUTER SCIENCE (083) : CLASS - XII SET - 3 Time : 3 Hours

JB ACADEMY HALF-YEARLY EXAMINATION 2016 CLASS XII COMPUTER SCIENCE. Time: 3:00 Hrs. M.M.: 70

KENDRIYA VIDYALAYA SANGATHAN (KOLKATA REGION) Second Pre Board Examination ( ) COMPUTER SCIENCE (Theory) Class-XII Marking Scheme

Fundamentals of Programming Session 27

Object Oriented Programming In C++

File handling Basics. Lecture 7

Object Oriented Programming CS250

SUBMITTED AS A PART OF C.B.S.E. CURRICULUM FOR THE YEAR

Downloaded from

Chapter 12: Advanced File Operations

Input/output. Remember std::ostream? std::istream std::ostream. std::ostream cin std::istream. namespace std { class ostream { /*...

A stream is infinite. File access methods. File I/O in C++ 4. File input/output David Keil CS II 2/03. The extractor and inserter form expressions

Consider the following example where a base class has been derived by other two classes:

Chapter 14 Sequential Access Files

THE ASIAN SCHOOL, DEHRADUN HOLIDAY HOMEWORK FOR SUMMER VACATION 2013 FOR CLASS XII

More File IO. CIS 15 : Spring 2007

COMPUTER SCIENCE (Theory) Class XII - Code : 083 Blue Print

Lecture 9. Introduction

VuZs Team's Work. CS201 Spring Solved by vuzs Team with Reference Written by Administrator Wednesday, 19 May :52

ASSIGNMENT CLASS : XII ( ) COMPUTER SCIENCE

Please check that this question paper contains 11 printed pages. Please write down the serial number of the question before attempting it.

LAB 4.1 Relational Operators and the if Statement

Chapter 8 File Processing

CSC 138 Structured Programming CHAPTER 4: TEXT FILE [PART 1]

Introduction to Computer and Program Design. Lesson 6. File I/O. James C.C. Cheng Department of Computer Science National Chiao Tung University

CS201 Latest Solved MCQs

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Transcription:

ASSIGNMENT 1 TOPIC : File Handling TYPE 1 QUESTION : ( Statement write type questions ) Q1. Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using seekp() and seekg() functions for performing the required task. #include <fstream.h> class Item int Ino;char Item[20]; //Function to search and display the content from a particular record number void Search(int ); //Function to modify the content of a particular record number void Modify(int); ; void Item::Search(int RecNo) File.open("STOCK.DAT",ios::binary ios::in); //Statement 1 File.read((char*)this,sizeof(Item)); cout<<ino<<"==>"<<item<<endl; void Item::Modify(int RecNo) File.open("STOCK.DAT",ios::binary ios::in ios::out); cout>>ino;cin.getline(item,20); //Statement 2 File.write((char*)this,sizeof(Item)); Q2. Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using seekg() and tellg() functions for performing the required task. #include <fstream.h>

class Employee int Eno;char Ename[20]; //Function to count the total number of records int Countrec(); ; int Item::Countrec() File.open( EMP.DAT,ios::binary ios::in); //Statement 1 int Bytes = //Statement 2 int Count = Bytes / sizeof(item); return Count; Q3. Write the command to place the file pointer at the 10th and 4th record starting position using seekp() or seekg() command. File object is file and record name is STUDENT. Q4. Observe the program segment given below carefully and fill in the blanks marked as Statement 1 and Statement 2 using tellg ( ) and skeep ( ) functions for performing the required task. #include <fstream. h> class c1ient long Cno ; char Name [20], Email [30] ; public : //Function to allow user to enter the cno,nme, Email void Enter ( ) ; // Function to allow user to enter (modify) Email void modify ( ) ; long ReturnCno( ) return Cno ; ; void changeemail ( ) Client C ; fstream F ; F. open ( INFO.DAT, ios :: binary ios :: in ios :: out) ;

long Cnoc ; //Client s no. whose Email needs to be changed cin >> Cnoc ; while (F. read (( char*) &C, sizeof (C))) if (Cnoc = = C.Returncno( )) C.Modify( ) ; //Statement 1 int Pos = //To find the current position of //file pointer //statement 2 //To move the file pointer to write //the modified record back into the //file for the desired cnoc F.write ((char*) &C, sizeof(c)); F.close( ) ; Q5. Observe the program segment given below carefully, and answer the question that follows: class PracFile intpracno; char PracName[20]; int TimeTaken; int Marks; // function to enter PracFile details void EnterPrac( ); // function to display PracFile details void ShowPrac( ): // function to return TimeTaken int RTime() return TimeTaken; // function to assign Marks void Assignmarks (int M) Marks = M; ; void AllocateMarks( ) File.open( MARKS.DAT,ios::binary ios::in ios::out); PracFile P; int Record = 0; while (File.read(( char*) &P, sizeof(p))) if(p.rtime()>50) P.Assignmarks(0) else

P.Assignmarks(10) //statement 1 //statement 2 Record + + ; If the function AllocateMarks () is supposed to Allocate Marks for the records in the file MARKS.DAT based on their value of the member TimeTaken. Write C++ statements for the statement 1 and statement 2, where, statement 1 is required to position the file write pointer to an appropriate place in the file and statement 2 is to perform the write operation with the modified record. Q6. Observe the program segment given below carefully, and answer the question that follows: class Book int Book no; char Book_name[20]; //function to enter Book details void enterdetails(); // function to display Book details void showdetails(); //function to return Book_no int Rbook_no ()return Book_no; ; void Modify(Book NEW) File.open( BOOK.DAT,ios::binary ios::in ios::out); Book OB; int Recordsread = 0, Found = 0; while (!Found && File.read((char*)&OB, sizeof (OB))) Recordsread ++ ; if (NEW.RBook_no() = = OB.RBook_no)) //Missing Statement File.write((char*)&NEW, sizeof (NEW)); Found = 1; else File.write((char*)&OB, sizeof(ob)); if (! Found) cout<<" Record for modification does not exist ;

If the function Modify( ) is supposed to modify a record in file BOOK.DAT with the values of Book NEW passed to its argument, write the appropriate statement for Missing Statement using seekp( ) or seekg( ), whichever needed, in the above code that would write the modified record at its proper place. Q7. Observer the program segment carefully and fill in the blanks marked as statement 1&2 #include<fstream.h> class MATERIAL int Mno;char Mname[25]; int qty; : void ModifyQty(); ; void MATERAIL::ModifyQty() Fstream File; Fil.open("MATERIAL.DAT",ios::binary ios::in ios::out); int Mpno; cout<<"materail no to modify Qty :"; cin>>mpno; while(fil.read((char*)this,sizeof(material))) if(mpno==mno) cout<<"present Qty :" <<qty<,endl; cout<"changed Qty :"; cin>>qty; int Position= ; //(Statement 1) : //(Statement 2) Fil.write((char * this,sizeof (MATERIAL)); // Re-writing the record Fil.close(); Q8. Observe the program segment given below carefully, and answer the question that follows class Candidate long CId ; //Candidate s Id char CName[20]; // Candidate s Name float Marks; //Candidate s Marks public : void Enter( ) ; void Display( ) ; void MarksChange ( ); // Function to change marks long R_CId( ) return CId ;

; void MarksUpdate ( long ID) fstream File ; File.open ( CANDIDATE.DAT, ios : : binary ios : : in ios : : out ) ; Candidate C ; int Record = 0, Found = 0; while (! Found && File. read ( ( char *) & C, sizeof ( C) ) ) if ( Id == C.R_CId ( ) ) cout << Enter new marks ; C. MarkChange ( ); // Statement 1 // Statement 2 Found = 1 ; Record ++ ; i f ( found == 1 ) cout << Record Updated ; File. close ( ); Write the Statement 1 to position the File pointer at the beginning of the Record for which the candidate s Id matches with the argument passed, and Statement 2 to write the updated Record at that position. Q9. Observe the program segment given below carefully and fill the blanks marked in statement 1 using seekg( ) or seekp( ) functions for performing the required task. #include<fstream.h> class FILE int Num; char Name[30]; void GO_Record(int); ; //function to read Nth record from the file void FILE::GO_Record(int N) FILE Rec; Fstream File; File.open( STOCK,ios::binary ios::in); //statement 1 File.read((char*)&Rec,sizeof(Rec)); cout<<rec.num<<rec.name<<endl; File.close( ); Q10. Observe the program segment carefully and answer the question that follows: class stock int Ino, Qty; Char Item[20]; void Enter() cin>>ino; gets(item); cin>>qty;

void issue(int Q) Qty+=0; void Purchase(int Q) Qty-=Q; int GetIno() return Ino; ; void PurchaseItem(int Pino, int PQty) File.open( stock.dat, ios::binary ios::in ios::out); Stock s; int success=0; while(success= = 0 && File.read((char *)&s,sizeof(s))) If(Pino= = ss.getino()) s.purchase(pqty); // statement 1 // statement 2 Success++; if (success = =1) cout<< Purchase Updated <<endl; else cout<< Wrong Item No <<endl; File.close() ;