1 / 7

Lab Session-IX CSIT-121 Spring 2002

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.

Download Presentation

Lab Session-IX CSIT-121 Spring 2002

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab Session-IX CSIT-121 Spring 2002 • Call by Reference Exercise • File Handling Sample Code • File Handling Exercise

  2. 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

  3. File Handling Sample Program • #include <iostream> • #include <fstream> • #include <string> • using namespace std; • int main() • {

  4. 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());

  5. File Handling Sample Program • if (!my_infile) • { cerr << "*** ERROR: Cannot open " << filename << " for input." << endl; • return EXIT_FAILURE; • } • else cerr<<"success"<<endl; • return 0; • }

  6. 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; • }

  7. 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

More Related