assn7_soln - F3<<S2<<endl F1.close F2.close...

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

View Full Document Right Arrow Icon
MIT OpenCourseWare 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: .
Background image of page 1

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

View Full DocumentRight Arrow Icon
6.096 Lab 7 Solutions #include<iostream> #include<fstream> #include<conio.h> #include<math.h> #include<string.h> using namespace std; // Part 1 void CreateTextFile() { fstream F1,F2;"FILE1.TXT",ios::out);"FILE2.TXT",ios::out); F1<<"Hello"<<endl; F1<<"I"<<endl; F1<<"C++"<<endl; F2<<"World"<<endl; F2<<"Love"<<endl; F1.close(); F2.close(); } // Part 2 void MergeFiles() { fstream F1,F2,F3;"FILE1.TXT",ios::in);"FILE2.TXT",ios::in);"FILE3.TXT",ios::out); string S1,S2; { F3<<S1<<endl; F3<<S2<<endl; } while(F1>>S1) { F3<<S1<<endl; } while(F2>>S2)
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { F3<<S2<<endl; } F1.close(); F2.close(); F3.close(); } // Part 3 void AddtoFiles() { fstream F1;"FILE3.TXT",ios::app); F1<<"I Love 6.096 too!"<<endl; char str[80]; char ch; do { cout<<"Text?";cin.getline(str,80); F1<<str<<endl; cout<<"Continue?(Y/N)";cin>>ch; }while(ch!='N'); F1.close(); } // Part 4 void CountO() { fstream F1; char ch; int CountO=0;"FILE1.TXT",ios::in); while(!F1.eof()) { ch=F1.get(); if(ch=='O' || ch=='o') CountO++; } cout<<"This has :"<<CountO<<" O's "<<endl; F1.close(); } void CountLove() { fstream F1; char str[80]; int CountL=0;"FILE1.TXT",ios::in); while( F1>>str ) { if(strcmp(str,"Love")==0) CountL++; } cout<<"This has :"<<CountL<<" Loves "<<endl; F1.close(); }...
View Full Document

This note was uploaded on 11/14/2011 for the course DDDD h0322 taught by Professor Whoknow during the Spring '11 term at Bina Nusantara University.

Page1 / 3

assn7_soln - F3<<S2<<endl F1.close F2.close...

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