COP 3014 Recitation - Week 6

Part 1 - File Input

  1. This file reads in a number from a file named data.txt. Copy data.txt into your Project Folder.
  2. Modify your program to allow the user to specify the name of the file instead
    • You may use the is_open() function of ifstream, which returns true if the file is open, and false if it is not
  3. Modify your program to read and display ALL of the numbers in the file instead
    • You may use the eof() function of ifstream, which returns true if the file cursor is at the end of the file, and false otherwise

Part 2 - Working with C++ classes

  1. Start a new Project
  2. Right click on Header Files > Add > New Item > Choose Header File (.h) > Enter "car.h" as the file name
  3. Copy this file into your car.h file
  4. Right click on Source Files > Add > New Item > Choose C++ File (.cpp) > Enter "car.cpp" as the file name
  5. Copy this file into your car.cpp file. Don't concern yourself about what the contents of this file right now. Only look at the contents of the car.h file
  6. car.h shows you the functions of my idea of a car. Now add a new cpp file to your Source Files folder named "main.cpp". Add code to main.cpp which instantiates a Car object, uses the car in some manner, then prints the status of the car

Part 3 - Looking at the car.cpp file

  • How would you change the way the functions of my car operates?
  • What additional functions would you include as part of the operation of a car?