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

Similar documents
Downloaded from

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

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

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

CHAPTER-7 Data File Handling

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

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


QUESTION BANK SUB: COMPUTER SCIENCE(083)

COMPUTER SCIENCE. Time allowed : 3 hours Maximum Marks : 70

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

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

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

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

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

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

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

Downloaded from

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.

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

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:

COMPUTER SCIENCE. Time allowed : 3 hours Maximum Marks : 70

KendriyaVidyalayaSangathan Kolkata Region

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

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

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

CLASS XII GUESS PAPER COMPUTER SCENCE (083)

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

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 COMPUTER SCIENCE. Sample paper-i. Time allowed: 3 hours Maximum Marks: 70 Name : Roll No.:

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

DELHI PUBLIC SCHOOL BOKARO STEEL CITY

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

KENDRIYA VIDYALAYA IIT CAMPUS CHENNAI 36 COMPUTER SCIENCE. Half Yearly


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

KENDRIYA VIDYALAYA SANGATHAN, CHENNAI REGION COMPUTER SCIENCE (083)

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

Downloaded from

ios ifstream fstream

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

Sample Paper, Subject: Computer Science Class 12 th Time Allowed : 3 Hr. M.M.: 70

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

ARMY PUBLIC SCHOOL NO.2, JABALPUR Important Questions SUBJECT: COMPUTER SCIENCE(XII)

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.

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

KENDRIYA VIDYALAYA SANGATHAN TINSUKIA REGION PRE BOARD EXAMINATION SUBJECT COMPUTER SCIENCE

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

Study Material for Class XII. Data File Handling

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

THE INDIAN COMMUNITY SCHOOL, KUWAIT

Unit-V File operations

I Mid Semester May 2012 : Class XII : Computer Science Max Mark 50 : Time 2 Hrs. 1. a) What is macro in C++? Give example 2

ITL Public School Pre-Board( ) Computer Science (083) Time:3 hrs M. M: 70

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

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

Random File Access. 1. Random File Access


Marking Scheme Computer Science

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

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

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

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

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

Computer Science 330 Assignment

Model Sample Paper 2015

Chapter 12: Advanced File Operations

Chapter-12 DATA FILE HANDLING

C++ How to Program 14.6

COMPUTER SCIENCE. Time allowed : 3 hours Maximum Marks : 70. General Instructions: All questions are compulsory. Programming Language: C++

IS 0020 Program Design and Software Tools

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

Developed By : Ms. K. M. Sanghavi

CBSE 12th Computer Science Question Papers

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

DISK FILE PROGRAM. ios. ofstream

(i) get single character using keyboard. This function is available in stdio.h. (ii) to check whether given character is alphabet or digit or not.

AISSCE COMMON MODEL EXAMINATION Subject Computer Science [083] Time Allotted: 3 Hours Maximum Marks: 70

COMPUTER SCIENCE

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

C++ Programming Lecture 10 File Processing

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

CBSE Sample Paper 2015 Computer Science C++ Class XII Time 3hrs M.M 70

KENDRIYA VIDYALAYA SANGATHAN, COMPUTER SCIENCE (THEORY) I PRE-BOARD TIME 3 HRS CLASS XII M. Marks 70

Chapte t r r 9

Object Oriented Programming In C++

Input and Output File (Files and Stream )

INTERNATIONAL INDIAN SCHOOL, RIYADH. Ch 1 C++ Revision tour

THE INDIAN COMMUNITY SCHOOL, KUWAIT

Class XII Computer Science (083) Sample Question Paper Time allowed: 3 Hours Max. Marks: 70

SAMPLE PAPER 2015 SUB - COMPUTER SCIENCE - (Theory) CLASS XII Time allowed: 3 hours Maximum marks: 70

COMPUTER SCIENCE QUESTION PAPER CODE 91/1

CS Programming2 1 st Semester H Sheet # 8 File Processing. Princess Nora University College of Computer and Information Sciences

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

Fundamentals of Programming Session 27

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

#include<iostream.h> #include<conio.h> #include<ctype.h>

Chapter 8 File Processing

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

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Transcription:

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 1. (a) Observe the program segment given below carefully and the questions that follow: class Inventory int Ano, Qty; char Article[20]; void Input() cin>>ano; gets(article); cin>>qty; void Issue(int Q) Qty += Q; void Procure(int Q) Qty -= Q; int GetAno() return Ano; ; void ProcureArticle ( int TAno, int TQty ) fstream File; File.open( STOCK.DAT, ios::binary ios::in ios::out); Inventory I int Found=0; while(found==0 && File.read((char*)&I, sizeof(i))) if ( TAno == S.GetAno()) I.Procure(TQty); // Statement 1 // Statement 2 Found++; if( Found == 1 ) cout<< Procurement Updated <<endl; else cout<< Wrong Article No <<endl; a) Write statement 1 to position the file pointer to the appropriate place, so that the data updation is done for the required Article. b) Write statement 2 to perform the write operation so that the updation is done in the binary file. C++@12 Question Bank Page 1

b) Write a function in C++ to read the content of a text file PLACES.TXT and display all those lines on the screen, which are either starting with P or starting with S. c) Write function in C++ to search for the details (Number and Calls) of those Mobile Phones, which have more than 1000 calls from a binary file mobile.dat. Assuming that this binary file contains records/objects of class Mobile, which is defined below: class Mobile char Number[10]; int Calls; void Enter() gets(number); cin>calls; void Billing() cout<<number<< # <<Calls<<endl; int GetCalls() return Calls; ; 2. (a) Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using seekg(), seekp(), tellp(), tellg() functions for performing the required task. #include<fstream.h> class PRODUCT int Pno; char Pname[20]; int Qty; void ModifyQty(); // The function is to modify quantity of a PRODUCT ; void PRODUCT :: ModifyQty() fstream File; File.open( PRODUCT.DAT, ios::binary ios::in ios::out); int MPno; cout<< Product No to modify quanity : ; cin>>mpno; while(file.read((char*)this, sizeof(product))) if(mpno == Pno) cout<< Present Quantity: <<Qty<<endl; cout<< Changed Quantity: ; cin>>qty; int Position = ; // Statement 1 ; // Statement 2 File.write((char*)this, sizeof(product)); b) Write a function in C++ to count the no. of Me or My words present in a text file DIARY.TXT. If the file DIARY.TXT content is as follows : My first book was Me and My family. It gave me change to be known to the world. The output of the function should be Count of Me/My in file : 4 c) Write a function in C++ to search for a laptop from a binary file LAPTOP.DAT containing the objects of class LAPTOP (as defined below). The user should enter the Model No and the function should search and display the details of the laptop. C++@12 Question Bank Page 2

class LAPTOP long ModelNo; float RAM, HDD; char Details[120]; void StockEnter() cin>>modelno>>ram>>hdd; gets(details); void StockDisplay() cout<<modelno<<ram<<hdd<<details<<endl; long ReturnModelNo() return ModelNo; ; 3. (a) Observe the program segment given below carefully and blanks marked as Statement 1 and Statement 2 using tellg() and seekg() functions for performing the required task. #include<fstream.h> [1] class Client long Cno; char Name[20], Email[30]; void Enter(); // Function to allow user to enter the Cno, Name, Email void Modify(); // Function to allow user to enter (modify) email long ReturnCno() return Cno; ; void ChangeEmail() Client C; fstream F; F.open( INFO.DAT, ios::binary ios::in ios::out); long Conc; // 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 : To find the current position of file pointer int Pos = // Statement 2 : To move the file pointer to write the modified record back // onto the file for the desired Conc F.write((char*) &C, sizeof(c)); F.close(); (b) Write a function in C++ to count the words this and these present in a text file ARTICLE.TXT. (c) Write a function in C++ to search and display details of all flights, whose destination is Mumbai from a binary file FLIGHT.DAT. Assuming the binary file is containing the objects of the following class. class FLIGHT int Fno; char From[20]; char To[20]; char* GetFrom() return From; char* GetTo() return To; void Enter() cin>>fno; gets(from); gets(to); void Display() cout<<fno<< : <<From<< : <<To<<endl; ; C++@12 Question Bank Page 3

4. (a) Observe the program segment given below carefully, and fill in the blanks marked as Line 1 and Line 2 using fstream function for performing the required task. #include<fstream.h> class Stock long Ino; // Item Number char Item[20]; // Item Name int Qty; // Quantity void Get(int); // Function to enter the content void Show(); // Function to display the content void Purchase(int Tqty) Qty += Tqty; // Function to increment in Qty long KnowIno() return Ino; ; void Purchase Item (long PIno, int PQty) // PIno -> Ino of the item purchased PQty -> Number of item purchased fstream File; File.open( ITEMS.DAT,ios::binary ios::in ios::out); int Pos = -1; Stock S; while( Pos == -1 && File.read((char*)&S, sizeof(s))) If(S.KnowIno() == PIno) S.Purchase(PQty); Pos = File.tellg() sizeof (S); // Line 1: To place the file pointer to the required position ; // Line 2: To write the object S on to the binary file ; If(pos == -1) cout<< No updation done as required Ino not found ; (b) Write a function COUNT_DO () in C++ to count the presence of a word do in a text file MEMO.TXT. Example: If the content of the file MEMO.TXT is as follows: I will do it, if you Request me to do it. It would have been done which earlier. The function COUNT_DO() will display the following message: Count of do- in file : 2 Note: In the above example, do occurring as a part of word done is not considered. (c) Write a function in C++ to read and display the detail of all the users whose status is A (i.e., Active) from a binary file USER.DAT. Assuming the binary USER.DAT is containing objects of class USER, which is defined as follows: class USER int Uid; // User Id char Uname[20]; // User name; C++@12 Question Bank Page 4

; char Status; // User Type : A Active I Inactive void Register (); // Function to enter the content void Show (); // Function to display all data members char Getstatus () return Status; 5. (a) Observe the program segment given below carefully, and answer the question that follows: class Applicant long AId; // Applicant s ID char Name[20]; // Applicant s Name float Score; // Applicant s Score void Enroll (); void Disp (); void MarksScore(); // Function to change score long R_AId() return AId; ; void Score_Update(long ID) fstream File; File.open( APPLI.DAT, ios::binary ios::in ios::out); Applicant A; int Record = 0, Found = 0; while (!Found && File.read((char*) &A, sizeof(a))) if( ID == A.R_AId()) cout<< Enter new Score ; A.MarksScore(); // Statement 1 // Statement 2 Found = 1; Record++; if(found == 1) cout<< Record Updated ; ; Write the statement 1 to position the File Pointer at the beginning of the Record for which the Applicant s Id matches with argument passed, and Statement 2 to write the updated Record at that position. (b) Write a function in C++ to count number of lowercase alphabets present in a text file BOOK.TXT. (c) Given a binary file PHONE.DAT, containing records of the following: class Phonelist char Name[20], Address[30], AreaCode[5], PnoneNo[15]; void Register(); void Show(); int CheckCode (char AC[] ) return strcmp (AreaCode, AC); ; Write a function TRANSFER () in C++, that would copy all those records which are having AreaCode as DEL from PHONE.DAT to PHONBACK.DAT. C++@12 Question Bank Page 5

6. (a) Observe the program segment given below carefully, and answer the question that follows: class PracFile int Pracno; char PracName[20]; int TimeTaken, 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 () fstream File; 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 values 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. (b) Write a function in C++ to print the count of the word is as an independent word in a text file DIALOGUE.TXT. For example, if the content of the file DIALOGUE.TXT is This is his book. Is this book good? Then output of the program should be 2. (c) Given a binary file GAME.DAT, containing records of the following structure type: struct Game char GameName[20]; char Participant[10][30]; ; Write a function in C++ that would read contents from the file GAME.DAT and creates a file named BASKET.DAT copying only those records from GAME.DAT where game name is Basket Ball. C++@12 Question Bank Page 6

7. (a) Write a function to count the number of words present in a text file named PARA.TXT. Assume that each word is separated by a single blank space character and no blank spaces in the beginning and end of the file. (b) Following is the structure of each record in a data file named COLONY.DAT. struct COLONY char Colony_Code[10]; char Colony_Name[10]; int No_of_People; ; Write functions in C++ to update the file with a new value of No_of_People are read during the execution of the program. 8. (a) Observe the program segment given below carefully, and answer the question that follows: class Book int Book_no; char Book_name[20]; void enterdetails(); // Function to enter Book Details void showdetails(); // Function to display book details int RBook_No() return Book_no; // Function to return Book_no ; void Modify (Book NEW) fstream File; 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.wirte ((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 () and seekg(), whichever needed, in the above code that would write the modified record at its proper place. (b) Write a function in C++ to count and display the number of lines starting with alphabet A present in a text file LINES.TXT. Example: If the file LINES.TXT contains the following lines, A boy is playing there. There is a playground. An aero plane is in the sky. Alphabets and numbers are allowed in the password. The function should display the output as 3 C++@12 Question Bank Page 7

(c) Given a binary file STUDENT.DAT, containing records of the following class Student type [3] class Student char S_Admno[10]; char S_Name[30]; int Percentage; void EnterData() gets(s_admno); gets(s_name); cin>>percentage; void DisplayData() cout<<setw(12)<<s_admno<<setw(32)<<s_name<<setw(3)<<percentage; int ReturnPercentage() return Percentage; ; 9 (a) Write a function in C++, that would read contents of file STUDENT.DAT and display the details of those Students whose Percentage is above 75. Write a definition for function COSTLY( ) in C++ to read each record of a binary file GIFTS.DAT, find and display those items, which are priced more than 2000. Assume that the file GIFTS.DAT is created with the help of objects of class GIFTS, which is defined below : class GIFTS int CODE;char ITEM[20]; float PRICE; void Procure() cin>>code; gets (ITEM);cin>>PRICE; void View() cout<<code<< : <<ITEM<< : <<PRICE<<endl; float GetPrice()return PRICE;. ; C Find the output of the following C++ code considering that the binary file MEMBER.DAT exists on the hard disk with records of 100 members : 1 class MEMBER int Mno; char Name[20]; void In();void Out(); ; void main() fstream MF; MF.open( MEMBER.DAT,ios::binary ios::in); MEMBER M; MF.read((char*)&M, sizeof(m)); MF.read((char*)&M, sizeof(m)); MF.read((char*)&M, sizeof(m)); int POSITION= MF.tellg()/sizeof(M); cout<< PRESENT RECORD: <<POSITION<<endl; MF.close(); C++@12 Question Bank Page 8

10. Fill in the blanks marked as Statement 1 and Statement 2, in the program segment given below with appropriate functions for the required task. class Agency int ANo; //Agent Code char AName[20]; //Agent Name char Mobile[12]; //Agent Mobile void Enter(); //Function to enter details of agent void Disp(); //Function to display details of agent int RAno() return ANo; void UpdateMobile() //Function to update Mobile cout<<"updated Mobile"; gets(mobile); ; void AgentUpdate() fstream F; F.open("AGENT.DAT",ios::binary ios::in ios::out); int Updt=0; int UAno; cout<<"ano (Agent No - to update mobile):"; cin>>uano; Agency A; while(!updt && F.read((char*)&A,sizeof(A))) if(a.rano()==uano) //Statement 1 : To call the function to update Mobile No. ; //Statement 2: To reposition file pointer to re-write the updated object back in the file ; F.write((char*)&A, sizeof(a)); Updt++; if (Updt) cout<<"mobile Updated for Agent"<<UAno<<endl; else cout<<"agent not in the Agency"<<endl; F.close(); b) Write a function AECount in C++, which should read each character of a text file NOTES.TXT, should count and display the occurrence of alphabets A and E (including small cases a and e too). Example: If the file content is as follows: CBSE enhanced its CCE guideline further. The AECount() function should display the output as A:1 E:7 C++@12 Question Bank Page 9

c) TOYS.DAT and display those details of those TOYS, which are meant for childern of AgeRange "5 to 8". class TOYS int ToyCode; char ToyName[10]; char AgeRange; void Enter() cin>>toycode; gets(toyname); gets(agerange); void Display() cout<<toycode<<":"<<toyname<<endl; cout<<agerange<<endl; char* WhatAge() return AgeRange; ; C++@12 Question Bank Page 10