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

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

CHAPTER-7 Data File Handling

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

Downloaded from

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

Downloaded from

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

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

QUESTION BANK SUB: COMPUTER SCIENCE(083)

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

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

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


ASSIGNMENTS FOR CLASS XII :

SAMPLE PAPER-2015 CLASS-XII COMPUTER SCIENCE. Sample paper-i. Time allowed: 3 hours Maximum Marks: 70 Name : Roll No.:

Unit-V File operations

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

Series SHC COMPUTER SCIENCE. Code No. 91. Roll No.

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

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

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

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

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

KENDRIYA VIDYALAYA SANGATHAN (CHANDIGARH REGION) MARKING SCHEME (Ist Pre Board )

COMPUTER SCIENCE QUESTION PAPER CODE 91/1

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

[Time allowed : 3hours] [Maximum Marks: 70] Instructions (i) All questions are compulsory (ii) Programming Language: C++

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

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

Chapte t r r 9

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

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

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


DELHI PUBLIC SCHOOL BOKARO STEEL CITY

C++ How to Program 14.6

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

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:

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

C++ does not, as a part of the language, define how data are sent out and read into the program

Downloaded from Computer Science 083

Week 3: File I/O and Formatting 3.7 Formatting Output

Page 1

C++ Programming Lecture 10 File Processing

Chapter-12 DATA FILE HANDLING

DISK FILE PROGRAM. ios. ofstream

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

Chapter 12: Advanced File Operations

Writing a Good Program. 7. Stream I/O

Chapter 14 Sequential Access Files

Object Oriented Programming In C++

File I/O Christian Schumacher, Info1 D-MAVT 2013

void display(){ cout << trainno.<< :>>Description<<endl; }; void main() {TRAIN T; Entry.(); Display.(); d) 410 e) i) south:east:south f) temttoe

ios ifstream fstream

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

KENDRIYA VIDYALAYA SANGATHAN, VARANASI REGION

Downloaded from

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

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

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

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

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

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

AAA //Members of AAA }; class BBB: public AAA //intermediate class. BBB { //Members of BBB };

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

Time : 3 Hours Maximum Marks : 70. Section A. S. No. Global Variable Local Variable

Study Material for Class XII. Data File Handling

CLASS XII GUESS PAPER COMPUTER SCENCE (083)

Given the C++ declaration statement below, which of the following represents the value of exforsys? e) None of the above. 1K

C++ files and streams. Lec 28-31

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

More File IO. CIS 15 : Spring 2007

Input and Output File (Files and Stream )

Developed By : Ms. K. M. Sanghavi

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

COMPUTER SCIENCE(083) SAMPLE QUESTION PAPER CLASS XII

IS 0020 Program Design and Software Tools

PIC 10A. Lecture 21: File I/O

Random File Access. 1. Random File Access

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

KENDRIYA VIDYALAYA SANGATHAN, CHENNAI REGION COMPUTER SCIENCE (083)

Streams contd. Text: Chapter12, Big C++

Fundamentals of Programming Session 27

(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.

C++ Structures Programming Workshop 2 (CSCI 1061U)

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

Fundamental File Processing Operations 2. Fundamental File Processing Operations

More About File Reading.

CSc Introduc/on to Compu/ng. Lecture 19 Edgardo Molina Fall 2011 City College of New York

EAS 230 Fall 2002 Section B

BITG 1113: Files and Stream LECTURE 10

File handling Basics. Lecture 7

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

SECTION A (15 MARKS) Answer ALL Questions. Each Question carries ONE Mark. 1 (a) Choose the correct answer: (10 Marks)

Advanced I/O Concepts

Fundamentals of Programming Session 25

KendriyaVidyalayaSangathan Kolkata Region

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

KENDRIYA VIDYALAYA SANGATHAN DEHRADUN REGION 1 st Pre-Board Examination, Class XII Computer Science(083) Time: 3 Hours Max.

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

Transcription:

Data File Handling FILL IN THE BLANKS EACH QUESTION CARRY 1 MARK 1.. Observe the program segment given below carefully, and answer the question that follows: class Labrecord int Expno; char Expriment[20]; char Checked; int Marks; //function to enter Expriment details void EnterExp(); //function to display Expriment details void ShowExp(); //fuction to retur Expno char RChecked() return Checked; //fuction to assign Marks void Assignmarks(int M) Marks=M; ; ; void ModifyMarks() fstream File; File.open("Marks.DAT",ios::binary ios::in ios::out); Labrecord L; int Rec=0; while(file.read((char*)&l,sizeof(l))) if(l.rchecked()== N ) L.Assignmarks(0); else L.Assignmarks(10); //statement 1 //statement 2 Rec++; File.close(); If the function ModifyMarks() is supposed to modify Marks for the records in file MARKS.DAT based on their status of the member Checked (containing value either Y or N ). 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 statement 2 is to perform the write operation with the modified record. Ans. Statement 1: File.seekp(-1*sizeof(L),ios::cur); Statement 2: File.write((char*)&L,sizeof(L)); 2.. Observe the program segment given below carefully and fill the blanks marked as statement 1 and Statement 2 using tellg() and seekp() functions for performing the required task. #include<fstream.h> class Customer long Cno; char Name[20],Mobile[12]; //function to allow user to enter the Cno, Name, Mobile void Enter(); //function to allow user to enter (modify) mobile number void Modify(); 1

//function to return value of Cno long GetCno() return Cno; ; void ChangeMobile() Customer C; fstream F; F.open( CONTACT.DAT,ios::binary ios::in ios::out); long Cnoc; //customer no. whose mobile number needs to be changed cin>>cnoc; while(f.read((char*)&c,sizeof(c))) If(Cnoc==C.GetCno()) 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 the record back on to the file //for the desired Cnoc F.write((char*)&C,sizeof(c)); File.close(); Ans. Statement 1: F.tellg() ; Statement 2: F.seekp(Pos-sizeof(C)); OR F.seekp(-l*sizeof(C),ios::cur); 3.. 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 void Enter(); void Display(); void MarksChange(); //Funcion to change marks long R_CId() return CId; ; void MarksUpdate(log 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++; if(found==1) cout<<"recoed 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, ad statement 2 to write the updated Recode at that position. 2

Ans. Statement 1: File.seekg(-1*sizeof(C),ios::cur); Statement 2: File.write((char*)&C,sizeof(C)); 4. Find the output of the following C++ code considering that the binary file CLIENTS.DAT exists on the hard disk with records of 100 members. class CLIENTS int Cno;char Name[20]; public : void In(); void Out(); ; void main) fstream CF; CF.open("CLIENTS.DAT",ios:: binary ios::in) ; CLIENTS C; CF.read((char*)&C,sizeof(C)); CF.read((char*)&C,sizeof(C)); CF.read((char*)&C,sizeof(C)); int POS=CF.tellg()/sizeof(C); cout<<"present RECORD:"<<POS<<endl; CF.close() ; Ans: PRESENT RECORD: 3 5. Find the output of the following C++ code considering that the binary file MEM.DAT exists on the hard disk with a data of 1000 members : (1) class MEMBER int Mcode;char MName[20]; void Register();void Display(); ; void main() fstream MFile; MFile.open( MEM.DAT, ios::binary ios::in); MEMBER M; MFile.read((char*)&M, sizeof(m)); cout<< Rec: <<MFile.tellg()/sizeof(M)<<endl; MFile.read((char*)&M, sizeof(m)); MFile.read((char*)&M, sizeof(m)); cout<< Rec: <<MFile.tellg()/sizeof(M)<<endl; MFile.close(); Ans: Rec:1 Rec:3 3

FILE HANDLING FUNCTIONS EACH QUESTION CARRY 2 MARKS OR 3 MARKS 1. Write a user defined function in C++ to read the content from a text file NOTES.TXT, count and display the number of blank spaces present in it. Ans. (i)void countspace() ifstream fins; fins.open("notes.txt", ios::in); char ch; int count=0; while(!fins.eof()) fin.get(ch); if(ch==' ') count++; cout<<"number of blank spaces"<<count; 2. Write a function in C++ to count the words to and the present in a text file POEM.TXT. [Note. that the words to and the are complete words.] Ans. void COUNT() ifstream File; File.open( POEM.TXT, ios::in); char Word[80] ; int Cl = 0, C2 = 0; while(!file.eof()) File>>Word; if (strcmp (Word, to )== 0) Cl++; else if (strcmp (Word, the )== 0) C2++; cout<< Count of -to- in file:" <<Cl; cout<< Count of -the- in file: <<C2; File.close(); 3.. Write a function in C++ to count the number of uppercase alphabets present in a text file ARTICLE.TXT. Ans. int countupcase() ifstream fin("article.txt", ios::in); int count=0; char ch; fin.get(ch); if(isupper(ch)) count++; return count; 4.. Write a function in C++ to count the number of digits present in a text file PARA.TXT. Ans. void countdigit() ifstream fil("para.txt,ios::in); int count=0; char ch; while(!fil.eof()) fil.get(ch); 4

if(isdigit(ch)) count++; fil.close(); cout<<"no of digit: "<<count<<endl; 5. Write a user-defined function named Count() that will read the contents of text file named Report.txt Report.txt and display the count of the number of lines that start with either I or M. E.g. In the following paragraph, there are 3 lines starting with I or M : India is the fastest growing economy. India is looking for more investments around the globe. The whole world is looking at India as a great market. Most of the Indians can foresee the heights that India is capable of reaching. Ans. (½ Mark for opening opinion.txt correctly) (½ Mark for fetching each line from the file correctly) (½ Mark for counting each word) (½ Mark for correct displaying the no. of lines which starts with M or I ) 6. Write a function RevText() to read a text file Input.txt and Print only word starting with I in reverse order. Example: If value in text file is: INDIA IS MY COUNTRY Output will be: AIDNI SI MY COUNTRY Ans: void RevText() ifstream fin ( Input.txt,ios::in); char word[25]; fin>>word; if (word[0]== I ) cout<<strrev(word); else cout<<word; 7. Write function definition for WORD4CHAR() in C++ to read the content of a text file FUN.TXT, and display all those words, which has four characters in it. Example: If the content of the file FUN.TXT is as follows: When I was a small child, I used to play in the garden with my grand mom. Those days were amazingly funful and I remember all the moments of that time The function WORD4CHAR() should display the following : When used play with days were that time 5

Ans: void WORD4CHAR() ifstream fin( FUN.TXT,ios::in); char word[25]; fin>>word; if(strlen(word)==4) cout<<word; 8. Given a binary file SPORTS.DAT, containing records of the following structure type: struct Sports char Event[20]; char Participant[10][30]; ; Write a function in C++ that would read contents from the file SPORTS.DAT and creates a file named ATHLETIC.DAT copying only those records from SPORTS.DAT where the event name is Athletics. Ans. void copyfile() ifstream fin; ofstream fout; fin.open("sports.dat",ios::in ios::binary); fout.open("atheletic.dat",ios::out ios::binary); Sports s1; fin.read((char*)&s1,sizeof(s1)); if(strcmp(s1.event,"athletics")==0) fout.write((char*)&s1,sizeof(s1)); fout.close(); 9. Write a function in C++ to search and display details of all trains, whose destination is Delhi from a binary file TRAIN.DAT. Assuming the binary file is containing the objects of the following class. class TRAIN int Tno; // Train Number char From[20]; // Train Starting Point char To[20]; // Train Destination char* GetFrom ()return From; char* GetTo ()return To; void Input () cin>>tno;gets(from);gets(to); void Show () cout<<tno<<:<<from<<:<<to<<endl; ; Ans. void Read ( ) TRAIN T; ifstream fin; fin.open (TRAIN.DAT, ios::in ios::binary); fin.read((char*)&t, sizeof(t)) if(strcmp(t.getto(), Delhi )==O) T.Show() ; 6

10. Given a binary file TELEPHON.DAT, containing records of the following class Directory: class Directory char Name[20]; char Address[30]; char AreaCode[5]; char Phone_No[15]; void Register(); void Show(); int CheckCode(char AC[]) return strcmp(areacode,ac); ; Write a function COPYABC() in C++, that would copy all those records having AreaCode as 123 from TELEPHONE.DAT to TELEBACK.DAT. Ans. void COPYABC() ifstream fin("telephon.dat",ios::in ios::binary); ofstream fout("teleback.dat",ios::out ios::binary); Directory ph; fin.read((char*)&ph,sizeof(ph)); if(ph.checkcode("123")==0) fout.write((char*)&ph,sizeof(ph)); fout.close(); 11.. 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 file USER.DAT is containing objects of class USER, which is defined as follows: class USER int Uid; // User Id char Uname[20]; // User Name 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; ; Ans. void DisplayActive( ) USER U; ifstream fin; fin.open( USER.DAT, ios::in ios::binary); fin.read(( char*) &U, sizeof(u)); if(u.getstatus() = = A ) U.show( ); fin.close( ); 12. Write a function in C++ to search and display details,whose destination is Chandigarh from binary file Flight.Dat. Assuming the binary file is containing the objects of the following class: 7

class FLIGHT int Fno; // Flight Number char From[20]; // Flight Starting Point char To[20]; // Flight Destination char * GetFrom ( ); return from; char * GetTo( ); return To; void input() cin>>fno>>; gets(from); get(to); void show( ) cout<<fno<< : <<From << : <<To<<endl; ; Ans : void Dispdetails() ifstream fin( Flight.Dat,ios::in ios::binary); Flight F; while (!fin.eof()) fin.read((char*)&f,sizeof(f)); if(strcmp(f.getto(), Chandigarh )==0) F.show(); 13. Consider the following class Item:- Write a function named Change_Item(int Id, float Pr) to modify the price of the item whose Itemid & new price are passed as an argument. Ans: (½ Mark for opening ITEM.DAT correctly) (1 Mark for reading all records from the file) (1 Mark for comparing value of Id from file & calling Set_Price() function) (½ Mark for writing new value of price in file) 8