Question

Write a C++ program to read a text file "input.txt" and store the data in form...

Write a C++ program to read a text file "input.txt" and store the data in form of 2d array (or any other data structure you prefer).

Input file:

a0 400 1 0 20
a1 300 2 0 30
a2 200 3 0 40
a3 100 6 0 40
a4 0 7 0 50

Homework Answers

Answer #1

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream myFile ("input.txt", ios::in);
//reading file
string arr[5][5];
{
for (int r = 0; r<5; r++)
{
for (int c = 0; c < 5; c++)
{
myFile >> arr[r][c];
}
}
myFile.close();
}
for(int r = 0;r<5;r++)
{
for(int c = 0;c<5;c++)
{
cout << arr[r][c] << " ";
}
cout << "\n";
}
}

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
● Write code to read the content of the text file input.txt using JAVA. For each...
● Write code to read the content of the text file input.txt using JAVA. For each line in input.txt, write a new line in the new text file output.txt that computes the answer to some operation on a list of numbers. ● If the input.txt has the following: Min: 1,2,3,5,6 Max: 1,2,3,5,6 Avg: 1,2,3,5,6 Your program should generate output.txt as follows: The min of [1, 2, 3, 5, 6] is 1. The max of [1, 2, 3, 5, 6] is...
Write a program for: In a text file INPUT.TXT integers separated by a space, perhaps in...
Write a program for: In a text file INPUT.TXT integers separated by a space, perhaps in a few lines. In a single file view to create a list of these numbers and find the arithmetic mean of the list elements. The resulting value is recorded in a text file OUTPUT.TXT.
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;   ...
Write a program that reads a file named input.txt and writes a file that contains the...
Write a program that reads a file named input.txt and writes a file that contains the same contents, but is named output.txt. The input file will contain more than one line when I test this. Do not use a path name when opening these files. This means the files should be located in the top level folder of the project. Do not use a copy method that is supplied by Java. Your program must read the file line by line...
Movie Structure File Write a program that will read in a CSV file with information regarding...
Movie Structure File Write a program that will read in a CSV file with information regarding movies. The file will contain a movie name, MPAA coding (G, PG, PG-13, R), number of minutes, and ratings (1-10) from the three top critics. Your program will read in the data into an array of structures (No more than 20 movies) and send the array to a function that will produce a professional report file (MovieReport.txt) which includes all of the information, an...
C++ PROGRAM 1. Open the file input called "info.txt" read it and store the data in...
C++ PROGRAM 1. Open the file input called "info.txt" read it and store the data in a vector. 2. Order the data by IP to perform the searches 3. Ask the user for the information search start and end IP's - Example of data on the info text: Jun 11 23:26:10 908.93.383.85:4940 Failed password for admin Aug 2 05:13:39 355.45.117.69:4551 Failed password for root Oct 24 02:32:14 852.37.168.72:6796 Illegal user 4. Display the records corresponding to those IPs 5. Store...
Write a C program that prompts the user to enter a line of text on the...
Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr and readLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate on NUL-terminated...
Write a Java program that reads words from a text file and displays all the words...
Write a Java program that reads words from a text file and displays all the words (duplicates allowed) in ascending alphabetical order. The words must start with a letter. 1. You must use one of following Concrete class to store data from the input.txt file. Vector, Stack, ArrayList, LinkedList 2. To sort those words, you should use one of existing interface methods available in Collection or List class.
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT