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;   ...
Please I need this to be done in PERL language only Write a program that prompts...
Please I need this to be done in PERL language only Write a program that prompts the user for a filename, then reads that file in and displays the contents backwards, line by line, and character-by character on each line. You can do this with scalars, but an array is much easier to work with. If the original file is: abcdef ghijkl the output will be: lkjihg fedcba AND Modify the previous script to use a die message if the...
Please provide commenting of code so I can understand how to solve this problem. Please provide...
Please provide commenting of code so I can understand how to solve this problem. Please provide text files. Using C++ Write a program that reads a given file, and then outputs the contents of it to another file. It should also print out the number of lines and the number of times each alphabetic character appears (regardless of case) in the input file at the end of the output file. It should prompt the user for the input and output...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding...
In PYTHON please: Write a function named word_stats that accepts as its parameter a string holding a file name, opens that file and reads its contents as a sequence of words, and produces a particular group of statistics about the input. You should report the total number of words (as an integer) and the average word length (as an un-rounded number). For example, suppose the file tobe.txt contains the following text: To be or not to be, that is the...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
Write a Java program that reads employee information from the file “employee.txt” then the program will...
Write a Java program that reads employee information from the file “employee.txt” then the program will display his/her information on the screen. The file contains the Employee’s Name, age,join date, quit date, and salary. • For each year the employee is in the company,10 days of sick leave are allowed. So, if an employee is in the company for two years, 20 days of sick leave are allowed. • For each year the employee is in the company, one-month salary...
Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...
Questions: 1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should (1) Prompt a message (using Console.WriteLine) to ask the user to input three integers. (2) Call the built-in function Console.ReadLine() three times to get the user’s input. (3) Convert the user’s input from...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an...
Consider the following file arrest.dat containing information of a suspect that the police is looking for:...
Consider the following file arrest.dat containing information of a suspect that the police is looking for: arrest.dat: The police is looking for Robert Whiteshead, also known as Whity, ID number 4607091111027, from address 4 Azalea Court, 219 Belmont Street, Germiston, 2065, in connection with a bank robbery at UNITED BANK in January 2016. An amount of about R45,000,000 was stolen on this day. Apparently he had a helper that goes by the name of JOINT13. Mr Whiteshead was also an...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT