know yourselves. information, computer, 7 wonders, various.

Monday, November 6, 2017

C++ programming language part- 64 File Input and Output with abstract data types


File Input and Output with abstract data types

The following programs deal with file input and output using user-define classes. A class called bill is being used for this purpose.

Writing Objects

Program 46_5
            //file input/output
            #include
            class bill
            {  public:
                int bill_no;
                float bill_amt;
            };
            void main()
            { ofstream  bfil_1("bilfile.txt");     //object would be any name
               bill obj1;
               obj1.bill_no=1;
               obj1.bill_amt=125.56;
               bfil_1<







Reading Object

Program 46_6
//file input/output
            #include
            class bill
            {  public:
                int bill_no;
                float bill_amt;
    char bill_str[30];
            };   
            void main()
            {  ifstream bfil_2("bilfile.txt");
               bill obj2;
               bfil_2>>obj2.bill_no>>obj2.bill_amt>>obj2.bill_str;
               cout<<"number= "<
               cout<<"amount= "<
   cout<<" Name= "<


Writing and Reading object together


Program 46_7
{ ofstream  bfil_1("bilfile2.txt");     //object would be any name
               bill obj1;
               obj1.bill_no=1;
               obj1.bill_amt=125.56;
               bfil_1<
           
ifstream bfil_2("bilfile2.txt");
            bill obj2;
            bfil_2>>obj2.bill_no>>obj2.bill_amt;
            cout<<"number= "<
            cout<<"amount= "<

cout<<"Name = "<





জ্ঞানকোষ প্রকাশনী
৩৮/২-ক, বাংলাবাজার (২য় তলা), ঢাকা।
       ফোনঃ ৭১১৮৪৪৩, ৮১১২৪৪১, ৮৬২৩২৫১.         
                                                     
কলকাতায় পরিবেশক/প্রাপ্তিস্থান
রিতা ইন্টারন্যাশনাল
৩৬, পি.এন. ব্যানার্জি রোড, কলকাতা
ফোনঃ ২৫১৩৮৩৫৯, ৯৮৩০৪৩৯৬৭৯, +৯১৯৮৩০৪৩৯৬৭৯

C++ programming language part- 65 Writing and Reading character using binary functions


Writing and Reading character using binary functions

In C++ there are some binary I/O functions such as get(), getline() and read() can be used when the programmer wishes to read white space characters also. The enter file input and output are text- or character-based. Usually , white space cheracter are omitted.




The put() function

The put() and get() functions, which are members of ostream and istream, are used to output and input a single character at a time. The following program writes one character at a time to a file.

Program 46_8
            //inherit.demo
            #include
            #include
            #include // for strlen()

            char cstr[]="Careless Whisper";
            void main()
            {
            ofstream ofil("careless.txt");
            int p;
              for(p=0;p
              {
               ofil.put(cstr[p]);     // put is a member of ofstream
              }
              ofil.put('\0');

            }

            // open this text file and watch information using notepad




জ্ঞানকোষ প্রকাশনী
৩৮/২-ক, বাংলাবাজার (২য় তলা), ঢাকা।
       ফোনঃ ৭১১৮৪৪৩, ৮১১২৪৪১, ৮৬২৩২৫১.         
                                                     
কলকাতায় পরিবেশক/প্রাপ্তিস্থান
রিতা ইন্টারন্যাশনাল
৩৬, পি.এন. ব্যানার্জি রোড, কলকাতা
ফোনঃ ২৫১৩৮৩৫৯, ৯৮৩০৪৩৯৬৭৯, +৯১৯৮৩০৪৩৯৬৭৯