Page 263 - DCAP404 _Object Oriented Programming
P. 263

Object-oriented Programming




                    Notes            Ios::app                             Open in append mode.
                                     Ios::ate                             Open and seek to end of file.
                                     Ios::in                              Open in input mode.
                                     Ios::nocreate                        Fail if file doesn’t already exist.
                                     Ios::noreplace                       Fail if file already exists.
                                     Ios::out                             Open in output mode.
                                     Ios::trunc                           Open and truncate to zero length.
                                     Ios::binary                          Open as a binary stream.


                                          Example:
                                   1.  Basic Program File Structure and Sample Function Call with stream I/O
                                       #include  <iostream>    //  Header  for  stream  I/O.

                                       #include  <iomanip>     //  Header  for  I/O  manipulators.
                                                        // Function declaration (prototype) with default values.
                                       float  sum(float  required_term,  float  optional_term  =  0.0);
                                                                                               //main  function
                                       int  main(void)
                                       {
                                          int  p;              //    Output  numeric  precision.
                                          float  a;            //  Units  and  description  of  a.
                                          float  b;            //  Units  and  description  of  b.

                                          cout.setf(ios::showpoint);
                                          cout  <<  “Enter  the  output  precision  (an  integer):  “;
                                          cin  >>  p;
                                          if  (!cin)
                                          {
                                                 cout  <<  “Input  error.\n”;
                                                 return  1;

                                          }
                                          cout  <<  setprecision(p);
                                          cout  <<  “Enter  two  real  numbers  to  be  summed:  “;
                                          cin  >>  a  >>  b;
                                          if  (!cin)
                                          {


                                                 cout  <<  “Input  error\n”;
                                                 return  2;




          256                               LOVELY PROFESSIONAL UNIVERSITY
   258   259   260   261   262   263   264   265   266   267   268