Lab09_sample - CMPSC 101 Introduction to Algorithmic...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CMPSC 101 Introduction to Algorithmic Processes Summer 2007 LAB 9 – I/O Streams 1. Write a program that will count total number of integers in a file. The file contains nothing but numbers of type int separated by blanks or line breaks. // File name: Lab09_01.cpp // Description: count number of integers in a file // Lab 09-1 // Author: Jaehyun Lim // Date: Friday, August 3, 2007 #include <iostream> #include <cstdlib> #include <fstream> using namespace std; int main() { ifstream in_stream; in_stream.open( "input_p1.txt" ); if (in_stream.fail()) { cout << "Input file opening failed." << endl; exit(1); } // read in numbers from file input_p1.txt // and count total number of integers int counter = 0, num; while (in_stream >> num) { counter++; } // display output on the screen cout << "There are total " << counter << " number of integers " << "in the file input_p1.txt" << endl;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
in_stream.close(); return 0; } 2. Write a program that takes its input from a file of double type numbers and outputs
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Lab09_sample - CMPSC 101 Introduction to Algorithmic...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online