Tuesday, October 20, 2015

ASSIGNMENT -- DATA FILE HANDLING

ASSIGNMENT – FILE HANDLING  CLASS XII A
Q1 Write a function count in C++ to count the no. of spaces in a text file “ memo.txt”.

Q2 Write a function count in C++ to count the no. of vowels  in a text file “ memo.txt”.

Q 3 Write a function count in C++ to count the presence of a word ‘do’ in a text file “ memo.txt”.

Q4 Write a function count in C++ to count and display  the no. of   lines start with ‘A’ in a file   “ school.txt”.

Q 5 Given a binary file game.dat which has following  structure type data
Struct game
{           int gcode; 
char gname[20];
char no_of_participant;
  }
(1) write a function that would copy those structures from game.dat to cricket.dat where gname is ‘cricket’.
(2) write a function that would update the value of no_of_participant in the file game.dat.

Q 6 Given a binary file phone.dat which has following  class type data
Class phonelist
{        char name[20];
char address[30];
char acode[5];
char pno[15];
public:
void register();
void show();
int checkcode(char ac[])
{
            return strcmp(areacode,ac);
}    
};
write a function that would copy those objects from phone.dat to phoneback.dat where acode is “del”.

Q 7 void main()
{       char ch=’A’;
       fstream file(data.dat”,ios::app);
        file<
        int p=file.tellg();
       cout<
}
what will be the output if the file content before the execution of the program is the string “ABC” (Note that “”are not the part of the file)


Q8 Given the binary file ITEM.DAT, containing the records of the following structure:  
struct item
{
int item_no;
char item_name[20];
int stock;
};
Implement the function AddStock( item x, int n), which updates a record by adding the existing stock for the item x in the file.


 Q 9 Write a function in c++ to read and display the records of computers that cost more than Rs. 20000 from the binary file “COMP.DAT”, assuming that the binary file is containing the objects of the following class :                                           
                                    class COMPUTER
                                                { int srno;
                                                char model[25];
                                                float price;
                                                public:
                                                            float Retpr( ) { return price; }
                                                            void Enter( ){ cin>>srno>>price; gets(model); }
                                                            void Display( ){ cout<

      Q 10  Write a function RevText() to read a text file “ Input.txt “ and Print each word in reverse   order .                                                                                                                   
               Example                    If value in text file is : INDIA IS MY COUNTRY
                                                    Output will be : AIDNI SI YM YRTNUOC

Q 11 Write a function in C++ to search for BookNo from a binary file “BOOK.DAT”, assuming the binary file is contained the objects of the following class:             
class BOOK
            {
                        int Bno; char Title [20];
                        public :
                        int Rbno ( ) { return Bno; }
                        void Enter ( ) { cin >> Bno; gets (Title); }
                        void Display ( ) { cout << Bno <<p class="MsoNormal">             };</p> <p class="MsoNormal"> <o:p> </o:p></p> <p class="MsoNormal" style="text-align:justify"> Q 12    Following is the structure of each record in a data file named “Colony.dat”                                                </p> <p class="MsoNormal" style="margin-left:1.0in;text-align:justify"> struct Colony</p> <p class="MsoNormal" style="margin-left:1.0in;text-align:justify"> {</p> <p class="MsoNormal" style="margin-left:1.0in;text-align:justify">             char colony_code[10];</p> <p class="MsoNormal" style="margin-left:1.0in;text-align:justify">             char colony_name[10];</p> <p class="MsoNormal" style="margin-left:1.0in;text-align:justify">             int no_of_people;</p> <p class="MsoNormal" style="margin-left:1.0in;text-align:justify"> };</p> <p class="MsoNormal" style="text-align:justify">             Wite a function to update the file with a new value of No_of_people. The value of colony_code and no_of_people  are read during the execution of the program.</p> <p class="MsoNormal"> <o:p> </o:p></p> <p class="MsoNormal"> Q 13     Assuming the class ZOO given below, write functions in C++ to perform following: </p> <p class="MsoNormal" style="margin-left:1.25in;text-indent:-.5in;mso-list:l0 level2 lfo1; tab-stops:list 1.25in"> <!--[if !supportLists]-->i.<span style="font-stretch: normal; font-size: 7pt;">                    </span><!--[endif]-->Write the objects of ZOO to a binary file.</p> <p class="MsoNormal" style="margin-left:1.25in;text-indent:-.5in;mso-list:l0 level2 lfo1; tab-stops:list 1.25in"> <!--[if !supportLists]-->ii.<span style="font-stretch: normal; font-size: 7pt;">                  </span><!--[endif]-->Read the objects of ZOO from binary file and display them on screen.</p> <p class="MsoNormal">             class ZOO</p> <p class="MsoNormal">             {</p> <p class="MsoNormal">                         char location[20];</p> <p class="MsoNormal">                         int no_of_animals[10];</p> <p class="MsoNormal">                         public:</p> <p class="MsoNormal">                                     void readdata()</p> <p class="MsoNormal">                                     {</p> <p class="MsoNormal">                                                 cin>>location;</p> <p class="MsoNormal">                                                 gets(no_of_animals);</p> <p class="MsoNormal">                                     }</p> <p class="MsoNormal">                                     void writedata()</p> <p class="MsoNormal">                                     {</p> <p class="MsoNormal">                                                 cout<<location<<” ”<<no_of_animals<<endl;</p> <p class="MsoNormal">                                     }</p> <p class="MsoNormal"> </p> <p class="MsoNormal">             };                                                                     </p> </div>

No comments:

Post a Comment

ASSIGNMENT INHERITANCE

ASSIGNMENT INHERITANCE