COP 3014 Recitation - Week 7
File operations.
Part 1
a) Create a new project
b) Go to your documents folder / Visual Studio / project name / project
name
c) Type this
program in your project and execute it.
d) Does the file appear in your project folder?
Part 2
a) Modify the code to print "Hello world" to the file 100 times instead of
just once
Part 3
Why do we need to close the file?
Part 4
Modify this
file to write to a file instead of writing to the screen. Use the code
from Part 1 as a guide if necessary.
Part 5
This program shows how
we can print the values of variables to a file. Modify your code from Part
4 to also write the value of speed to the file. For example, if I'm
going 35mph, instead of writing "Too slow!", it should say "35 is too
slow!".
Program examples