Question

And need to be writing in C++ language Programm need to start with   #include<fstream> Prepare a...

And need to be writing in C++ language

Programm need to start with   #include<fstream>

Prepare a text file data_in.txt with the following information (highlight the piece of text below with numbers and copy it to a text file):
54, 70, 75, 63, 17, 59, 87, 16, 93, 81, 60, 67, 90, 53, 88, 9, 61, 8, 96, 98, 12, 34, 66, 76, 38, 55, 58, 27, 92, 45, 41, 4, 20, 22, 69, 77, 86, 35, 19, 32, 49, 15, 29, 23, 83, 95, 25, 91, 33, 47, 24, 62, 13, 42, 73, 44, 78, 72, 7, 5, 10, 48, 71, 18, 39, 97, 64, 79, 51, 74, 31, 37, 57, 30, 94, 80, 28, 1, 56, 85, 46, 100, 82, 40, 26, 21, 68, 43, 14, 3, 65, 99, 89, 52, 84, 36, 2, 6, 11, 50
2. Write a program that:
a) Reads integers from the data_in.txt file, places them in an array, and outputs the contents of the array to the screen.
b) The text file data_out.txt outputs:
* the contents of the array in reverse order, and
* the sum of all figures.
3. Try a situation where the input file has a different name than your program, such as "datain.txt", and the program does not use the is_open () function to check the existence of the file - put the relevant lines of code in the comments.
4. Answer the questions:
a) How does the program "behave" - ​​does it display an error message?
b) What appears on the screen when the contents of an array are output? What are they about data?
c) Is the information in the file “data_out.txt” output? If so, what information?

3.The third question asks you to check what would change in the program if the name of the input file were changed. And the file is_open () function is added to the comments.

4.The fourth question is simply to answer the questions about how the program worked at the time.

Homework Answers

Answer #1

ANSWER :

Answer to (1) & (2) :-
===============
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { int num = 0, cnt, value, array_sum; string line; ifstream inFile; // input file stream object ofstream outFile;// output file stream object int num_array [200]; // array to store integers inFile.open ("data_in.txt", ios::in ); //opening input file outFile.open("data_out.txt", ios::out); // opening output file cnt = 0; while ( getline (inFile,line, ',') ) { num = stoi(line); num_array[cnt] = num; array_sum += num; cnt++; } // Output array to screen cout << "SET OF INTEGER VALUES READ FROM data_input.txt FILE :" << endl; for(int i=0; i < cnt; i++) { cout << num_array[i] << "\t"; } // Writing reversed integer to output file for(int i=cnt-1; i >= 0; i--) { outFile << num_array[i] << ", "; } outFile << endl; outFile << array_sum; inFile.close(); outFile.close(); return 0; }

OUTPUT FILE :-



CONTENT OF data_output.txt file
-------------------------------------------------
50, 11, 6, 2, 36, 84, 52, 89, 99, 65, 3, 14, 43, 68, 21, 26, 40, 82, 100, 46, 85, 56, 1, 28, 80, 94, 30, 57, 37, 31, 74, 51, 79, 64, 97, 39, 18, 71, 48, 10, 5, 7, 72, 78, 44, 73, 42, 13, 62, 24, 47, 33, 91, 25, 95, 83, 23, 29, 15, 49, 32, 19, 35, 86, 77, 69, 22, 20, 4, 41, 45, 92, 27, 58, 55, 38, 76, 66, 34, 12, 98, 96, 8, 61, 9, 88, 53, 90, 67, 60, 81, 93, 16, 87, 59, 17, 63, 75, 70, 54,
5050
----------------------------------------------------------------------------------------------------------------------------------------------------
Answer for (3) :-
==========
inFile.open ("datain.txt", ios::in ); //opening input file outFile.open("data_out.txt", ios::out); // opening output file

Answer for (4):-
==========
(a) There is no error message displayed
(b) Program does not display the array and no output on the screen
(c) Nothing written to the output file
90 SET OF INTEGER VALUES READ FROM data_input.txt FILE : 54 70 75 63 17 59 87 9 61 8 96 98 12 34 41 4 20 22 69 77 86 95 25 91 33 47 24 62 10 48 71 18 39 97 64 80 28 1 56 85 100 65 99 52 84 Process returned o (Oxo) execution time : 0.247 s 16 66 35 13 79 82 6 93 76 19 42 51 40 11 81 38 32 73 74 26 50 60 55 49 44 31 21 67 58 15 78 37 68 27 29 72 57 43 53 92 23 7 88 45 83 5 94 3 30 14 46 36 89 2

Hope it helps... please give an upvote. it's very important to me... thank you:)

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Lab 6    -   Program #2   -   Write one number to a text file. Use the write()...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write() and read() functions with binary                                                        data, where the data is not char type.              (Typecasting is required) Fill in the blanks, then enter the code and run the program. Note:   The data is int type, so typecasting is            required in the write() and read() functions. #include <iostream> #include <fstream> using namespace std; int main() {    const int SIZE = 10;   ...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat...
C++ Goals:Practicing arrays Create a program that will read whole numbers from a file called Labs4-7Mu.dat (posted on Canvas)and store it into an array. The number of values in the file is less than 300 and all the values are whole numbers. The actual number of values stored in the file should be determined. Your program should then prompt the user to enter another whole number between 2 and 20 (you may assume the user enters a valid value) and...
C++ Programming   You are to develop a program to read Baseball player statistics from an input...
C++ Programming   You are to develop a program to read Baseball player statistics from an input file. Each player should bestored in a Player object. Therefore, you need to define the Player class. Each player will have a firstname, last name, a position (strings) and a batting average (floating point number). Your class needs to provide all the methods needed to read, write, initialize the object. Your data needs to be stored in an array of player objects. The maximum...
Use MARS to write and simulate a MIPS assembly language program to swap two of the...
Use MARS to write and simulate a MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. Download the template file “P4_template.asm” provided on Blackboard. Add your code to this file. Do not modify any of the code provided in the file. The main function should: • Pass the starting address of the array in $a0....
Create a text file called “Trivia.txt” that contains the contents of a trivia game, where the...
Create a text file called “Trivia.txt” that contains the contents of a trivia game, where the questions and answers are on separate lines. Example: How many players are on a Baseball team? Nine What is the name of Batmans butler? Alfred Hg is the chemical symbol for what element? Mercury Create a program that reads the trivia questions from this text file, prints them out to netbeans and asks the user to input an answer. Compare the users answer to...
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
Given main() complete the Stack class by writing the methods push() and pop(). The stack uses...
Given main() complete the Stack class by writing the methods push() and pop(). The stack uses an array of size 5 to store elements. The command Push followed by a positive number pushes the number onto the stack. The command Pop pops the top element from the stack. Entering -1 exits the program. Ex. If the input is Push 1 Push 2 Push 3 Push 4 Push 5 Pop -1 the output is Stack contents (top to bottom): 1 Stack...
Networking questions: 1. You need to perform a basic ping scan and write the output file...
Networking questions: 1. You need to perform a basic ping scan and write the output file to a text file named 10-PingSweep.txt. You must utilize a “for loop” with the ping command in windows. It should be for the following sweep – 192.168.111.1-254. Provide the command to be placed into a cmd.exe shell. (Note – only valid Reply responses should be in the text file. Your exact command will be tested.) 2. You are working on a potential incident response...
language: JAVA the Problem Below are a series of problems you need to solve using recursive...
language: JAVA the Problem Below are a series of problems you need to solve using recursive methods. You will write a program that will read commands from an input file, with each command referring to one of the recursive problems to be executed. Each command will be followed (on the same line of input) by the respective parameters required for that problem. (15 points for main method) DescArrayCheck   Write a recursive method that checks whether an array of integers -...
*****C++ program***** Please implement the following, comments throughout code to explain, and provide screenshots of output...
*****C++ program***** Please implement the following, comments throughout code to explain, and provide screenshots of output for proof. Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Implement the following functions: Implement a function called readData int readData( int *arr) arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers from a file call data.txt into the array arr....