So when I excute the program it's not showing anything. On the right is the file states.txt.
Is it my for loops thats giving me problems?
![0 1-1 -1 -1 1 2-1 #includeci ostream> #include<fstream> #include-string> #includeionamp> using namespace std; write readTrans here to read in states.txt into the matrix // use generic argument names //AKA make this function here void readTransCint ar[10]05]) ifstream fin; fin.openC states.txt 1-0; for(int 1 10; i++) for(int j = 0; j < 5; i++) fin ar[i]lj]: fin.closeO; write displayTrans here to display what is in the matrix //make sure it is easy to read and understand // make this function below void displayTrans (int ar 10][5]) for(int i = 0; 1 10; i++) for Cint j 0; j < 5; j++) cout << endl // The driver to read and display the matrix int mainO int myTrns[10]05]; readTrans myTrns); displayTrans(myTrns); matrix of state transitions](http://img.homeworklib.com/questions/b0e77d60-4eaf-11eb-8508-65889542e8c4.png?x-oss-process=image/resize,w_560)
#include <iostream>
#include <string>
#include<fstream>
#include<iomanip>
using namespace std;
void readTrans(int a[10][4])//size of data in file is 10x4
{
ifstream fin;
fin.open("states.txt");
for(int i=0;i<10;i++)
for(int j=0;j<4;j++)
fin >> a[i][j];
fin.close();
}
void displayTrans(int a[10][4])
{
for(int i=0;i<10;i++)
{
for(int j = 0; j < 4; j++)
{
cout << setw(2) << a[i][j] << " ";//setw(2) used
to properly align the data
}
cout << endl;
}
}
int main()
{
int a[10][4];
readTrans(a);
displayTrans(a);
}
You have declared the size of array wrongly. The dimensions should be 10x4 instead of 10x5 because there are only 4 columns hence dimension will be 10 x 4. Since you declares the dimensions more than the amount of data in the file, the program was still waiting for more data and that's why it wasn't showing any output. Use the above corrected code
Output on running the above code:

Please give this solution a thumbs up if you find it helpful and comment if you have any doubts in it.
So when I excute the program it's not showing anything. On the right is the file...
Directions: Develop a C++ program that can solve any matrix, up to 15 equations with 15 unknowns. Put the result on the screen as well as write the results to a text file This is what we were given as a hint: /* how to read matrix data file in rows and colloms written by tom tucker 03/26/2018 it uses a string array to read in the first line and then a nested for statement to read in the matrix...
How do I complete my code using an external file? External file: data.txt //the number 6 is in the external file Incomplete code: #include <iostream> #include <fstream> using namespace std; class example { int data[1]; public: example(); void read(ifstream &); }; example::example() { ifstream infile; infile.open("data.txt"); } void example::read(ifstream &infile) { infile >> data[1]; cout << data[1] << endl; } int main() { example example, read; //system("pause"); return 0;...
Debug the following matrix program in C: // Program to read integers into a 3X3 matrix and display them #include <stdio.h> void display(int Matrix[3][3],int size); int main(void) { char size; double Matrix[size][size+1]; printf("Enter 9 elements of the matrix:\n"); int i; for (i = 0: i <= size: i++) { int j = 0; for (; j <= size++; j++){ scanf("%d", matrix[i--][4]) } } Display(Matrix,9); return 0; void...
In c++ please How do I get my printVector function to actually print the vector out? I was able to fill the vector with the text file of names, but I can't get it to print it out. Please help #include <iostream> #include <string> #include <fstream> #include <algorithm> #include <vector> using namespace std; void openifile(string filename, ifstream &ifile){ ifile.open(filename.c_str(), ios::in); if (!ifile){ cerr<<"Error opening input file " << filename << "... Exiting Program."<<endl; exit(1); } } void...
Trying to debug a C program given to me. This is what I was given... // Program to read numeric elements (including decimals) into a 3X3 matrix and display them #include<stdio.h> int main(void) { int size = 3, Matrix[size][size]; printf("Enter 9 elements of the matrix:\n") for (int i = 0, i <=size, i++} for (int j = 0, j <= size, i++) scan("%c", Matrix1[2][2]); diplay(Matrix) float display(int Matrix1[][], int size) ( ...
I need only one C++ function . It's C++ don't write any other language. Hello I need unzip function here is my zip function below. So I need the opposite function unzip. Instructions: The next tools you will build come in a pair, because one (zip) is a file compression tool, and the other (unzip) is a file decompression tool. The type of compression used here is a simple form of compression called run-length encoding (RLE). RLE is quite simple: when...
(Print distinct numbers) C++ Write a program that reads in 10 numbers and displays distinct numbers (i.e., if a number appears multiple times, it is displayed only once). The numbers are displayed in the order of their input and separated by exactly one space. (Hint: Read a number and store it to an array if it is new. If the number is already in the array, discard it. After the input, the array contains the distinct numbers.) Sample Run Enter...
//This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...
//This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...
//This program is your final practice exam. //Please fill in the functions at the bottom of the file. (sum and removeItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream>...