reading_and_writing_to_files - t numStudents++ } ofstream...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 // reading_and_writing_files.cpp #include <iostream> #include <fstream> using namespace std int main() { // *********** declaration statements ************* int weight = 0 int height = 0 int totalWeight = 0 int totalHeight = 0 int numStudents = 0 ifstream infile("C:/Documents and Settings/*****/Desktop/data.txt") // ************ input statements ****************** while (!infile.eof()) { infile >> weight totalWeight += weight t infile >> height totalHeight += height
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: t numStudents++ } ofstream outfile;C:/Documents and Settings/*****/Desktop/output.txt&quot;) // or ofstream outfile(&quot;C:/Documents and Settings/*****/Desktop/output.txt&quot;) outfile &lt;&lt; &quot;ave weight: &quot; &lt;&lt; double (totalWeight)/numStudents &lt;&lt; endl outfile &lt;&lt; &quot;ave height: &quot; &lt;&lt; double (totalHeight)/numStudents &lt;&lt; endl infile.close() outfile.close() return 0 }// end of main Sheet1 Page 2 // fill in the asterisks with your PSU username...
View Full Document

Page1 / 2

reading_and_writing_to_files - t numStudents++ } ofstream...

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

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