Colour Theme Font Size Options
 
 
 
Exercise 1

File I/O Exercise:

Your lab instructor will guide you through the steps necessary to set up this project in their desktop IDE as part of their lab seminar. Video instructions for people using our other supported Desktop IDEs can be found here:

Using the lab samples as a starting point, write a program in the file called ex1_lab4.cpp

Copy the following code and use the name ex1_lab4.cpp in your Visual Studio or other IDEs:

Your code will:

  • Read 10 float values from an input file called ex1_input.txt.
    (you have to create the ex1_input.txt file and make up 10 numbers yourself)
  • Output the sum and the average of the 10 float values to an output file ex1_output.txt tidily and with labels.
  • Use if statements to see if the input and output files opened successfully before reading or writing with them.
  • Compile and run this C++ program.

When you are done:

  • Observe the results in ex1_output.txt. Check with your lab instructor if you aren't sure if they are correct.
  • Take a screenshot of your IDE and console window after running the program - there should be no output there.
  • For this exercise, you will have: ex1_lab4.cpp, ex1_input.txt and ex1_output.txt files. Upload them in UR Courses.
  • Call your lab instructor for marking.