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
-
- 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 the file name is correct, but theres nothing in the file, the program will say Error, File is empty.
- The program will read all the values from the file and store them. It will count how many values are in the file.
- The program will print the number of values with the statement there are x values in the file.
- The program will loop to make testing easier.
- The program must take a file name from the user
- Include io library, file stream library, string library, and asser.h
- Define a constant variable size to 20
- 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.
- Declare an int called count and set its value to 0
- Open a while loop whose condition is the filestream x not reaching the end of the file.
- Open an if statement whose condition is the count variable exceeding 20
- Print The file has more than 20 values
- Insert a break statement
- Create an else statement to the previous if.
- Read the filestream x into the tempArray at index count
- Increment count
- Make the value of length equal to the value of count.
- Open a for loop that loops the until the control variable reachs the same value as count
- Set the intArray to the value of the tempArray at each index of the control variable.
- Open an if statement whose condition is the count variable exceeding 20
- 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.
- Use the assert function to make sure length has a positive, non-zero value.
- Print to the command window There are values in the file
- Print They are
- Open a for loop that loops until the control variable reachs the same value as length
- Print intArray at each index using the control variable.
- Add a space and comma in between each value.
- In the main:
- Open an input file stream named inputStream
- Declare a constant integer named size and set its value to SIZE defined in the compiler directives.
- Create an int named length and set its value to zero
- Create Boolean named isEmpty and set its value to false
- Create an integer array name intArray and set its size to size
- Create a character caller sentinel and set its value to y
- Open a while loop controlled by sentinel being set to y or Y
- Create a string named fileName and set its value to
- Print Please enter the name of the file
- Take the input from the command screen and store it in fileName.
- Open the isteam inputStream with the filename fileName
- If inputStream failed, print the message Error, Bad File Name.
- Open an if statement. It should pass is inputStream has not failed and isEmpty is false
- Pass inputStream, intArray, size, and length to the function readIntFile
- Pass intArray and length to the function print values
- Close inputStream
- Set sentinel to the value return by function sentinelCheck
- 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
Get step-by-step solutions from verified subject matter experts
