70 likes | 107 Views
Develop a program that calls a function to order three integer values in increasing numerical order using call by reference. The program also includes a sample code for file handling.
E N D
Lab Session-IX CSIT-121 Spring 2002 • Call by Reference Exercise • File Handling Sample Code • File Handling Exercise
Call By Reference Exercise (Taken from Exam-I) • For reference arguments exercise, develop a program that calls a function to order three integer values in the increasing numerical order. • Function name sort_ascend(int&, int&, int&) • when passed values (17,2,9), it orders the same as (2,9,17) The function is void as it returns the values through reference arguments
File Handling Sample Program • #include <iostream> • #include <fstream> • #include <string> • using namespace std; • int main() • {
File Handling Sample Program • ifstream my_infile; • ofstream my_outfile; • string filename; • cout<<"Enter a file name to open: "; • cin>>filename; • my_infile.open (filename.c_str());
File Handling Sample Program • if (!my_infile) • { cerr << "*** ERROR: Cannot open " << filename << " for input." << endl; • return EXIT_FAILURE; • } • else cerr<<"success"<<endl; • return 0; • }
File Handling for Output Files • my_outfile.open (“out.dat”); • if (!my_outfile) • { • cerr << "ERROR: Cannot open " << “out.dat” • << " for output." << endl; • return EXIT_FAILURE; • }
Exercise for File Handling • Write a program that reads two text files one after another and produces an output file that combines the content of both