Question: The program must take a file name from the user If the file name is wrong the program will say Error, bad file name. If

    1. The program must take a file name from the user
      1. If the file name is wrong the program will say Error, bad file name.
      2. If the file name is correct, but theres nothing in the file, the program will say Error, File is empty.
    2. The program will read all the values from the file and store them. It will count how many values are in the file.
    3. The program will print the number of values with the statement there are x values in the file.
    4. The program will loop to make testing easier.

  1. Include io library, file stream library, string library, and asser.h
  2. Define a constant variable size to 20
  3. Create a void function called readIntFile that accepts an incoming filestream x, integer array called intArray, an int name size and an int named length that is passed by reference.
    1. Declare an int called count and set its value to 0
    2. Open a while loop whose condition is the filestream x not reaching the end of the file.
      1. Open an if statement whose condition is the count variable exceeding 20
        1. Print The file has more than 20 values
        2. Insert a break statement
      2. Create an else statement to the previous if.
        1. Read the filestream x into the tempArray at index count
        2. Increment count
        3. Make the value of length equal to the value of count.
      3. Open a for loop that loops the until the control variable reachs the same value as count
        1. Set the intArray to the value of the tempArray at each index of the control variable.
  4. Create a void function name printValues that takes an integer array name intArray and an int named length (that is passed by reference) as parameters.
    1. Use the assert function to make sure length has a positive, non-zero value.
    2. Print to the command window There are values in the file
    3. Print They are
    4. Open a for loop that loops until the control variable reachs the same value as length
      1. Print intArray at each index using the control variable.
      2. Add a space and comma in between each value.
  5. In the main:
    1. Open an input file stream named inputStream
    2. Declare a constant integer named size and set its value to SIZE defined in the compiler directives.
    3. Create an int named length and set its value to zero
    4. Create Boolean named isEmpty and set its value to false
    5. Create an integer array name intArray and set its size to size
    6. Create a character caller sentinel and set its value to y
    7. Open a while loop controlled by sentinel being set to y or Y
      1. Create a string named fileName and set its value to
      2. Print Please enter the name of the file
      3. Take the input from the command screen and store it in fileName.
      4. Open the isteam inputStream with the filename fileName
      5. If inputStream failed, print the message Error, Bad File Name.
      6. Open an if statement. It should pass is inputStream has not failed and isEmpty is false
        1. Pass inputStream, intArray, size, and length to the function readIntFile
        2. Pass intArray and length to the function print values
      7. Close inputStream
      8. Set sentinel to the value return by function sentinelCheck
  6. Return 0

(Include all the above in the code)

Question: Create a program that reads a given file and stores its contents. The program will then print the files contents and how many numbers it contained.

C++ please!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!