Opening Input/Output Files

advertisement
Opening Input/Output Files
void openFiles (ifstream& infile, ofstream& outfile)
{
char inFileName[40];
char outFileName[40];
cout<<"Enter the input file name: ";
cin>>inFileName;
infile.open(inFileName); //open input file
cout<<"Enter the output file name: ";
cin>> outFileName;
outfile.open(outFileName);//open out putfile
}
#ifndef

To avoid including your .h files more than once,
when using multiple files (gives you a redefinition
link error), add the following to all you .h files
#ifndef FILE_H
#define FILE_H
//code goes here
#endif
Three important characteristics of OOP
1. Encapsulation - see Section 2.1
 2. Inheritance - hierarchy in which descendant


class inherits data and operations from ancestor
class
Example:
furniture
chable
table
End table
ottoman
chair
dinette
Three important characteristics of OOP

3. Polymorphism - several operations with
same name
–
–
–
–
binding time - time name/symbol bound to
code/value
static binding - resolved at compiled time
dynamic binding - resolved at run time
operation overloading - static binding
Specifying Functions
Up to now Purpose/Receives/Returns
 Text Book uses Pre- and Post-conditions
 Pre-condition: describes what must be true
about the state for the function to work
correctly
 Post-condition: describes what will be true
about the state if the pre-conditions are met

Specifying Functions cont.
– discusses appropriate
values for receives parameters and
member data of object if it is a member
function we are specifying
 Post-condition – describes what the
return variables values will be and what
changes will be made to the object
 Precondition
Error Conditions
Describe what preconditions will be checked
by the function (might use try/catch)
Download