How to print results in a table
-
I checked when the user enters a size of 1 or 2 and it is working the way I want. The output I mailed you is different from the output you get if you run the program may be is that what make you think there is something wrong if not, I do not know what you try to tell me, once again thanks I am sorry for not explain better what the program does. First I want to say the program does what I really want. There is nothing wrong in the program, what I need from you is how can I print the results in a table. In this table will be printed the matrix data plus the five numbers enter by the user, the numbers IN and / or OUT( NOT ) and the total of numbers IN and / or OUT( NOT ) of each row analyzed depending which size was chosen ( 5 x 5 ) in the example I mailed you before. When the user is asked to input a size to analyze The user inputs 5. Does that mean that rows 0, 1, 2, 3 and 4 are analyzed ? No, what that mean is that row 0) will be analyzed with the size of the matrix chosen by the user in this example ( 5 x 5 ) in other words rows 1, 2, 3, 4 and 5. When row 0 is analyzed why are 12, 13 and 15 IN ? Is it because there is a 12 in row 5, a 13 in row 2, and a 15 in row 5 ? Yes, because those numbers are inside a matrix ( 5 x 5 ) chosen by the user. For row 0, why is 14 OUT ? Is it because there is no 14 in the rest of the matrix, outside of row 0 ? Why is 39 OUT ? There is a 39 in row 9. No, 14 and 39 are OUT because they are not inside de matrix ( 5 x 5 ) chosen by the user in this case rows 1, 2, 3, 4, and 5. I cannot find a consistent pattern of what it means to be IN or OUT. I think if you help me understand what you are trying to get, I can show you the code for it. There is a consistent pattern when the user enter the size of the matrix, that size is the one each row will be analyzed to see if the numbers of the analyzed row is IN and / or that matrix. In the matrix ( 11 x 5 ) the first row to analyze is : first: row 4) with the matrix ( 5 x 5 ) (rows 5, 6, 7, 8, and 9 ) second: row 3) with the matrix ( 5 x 5 ) (rows 4, 5, 6, 7, and 8 ) third: row 2) with the matrix ( 5 x 5 ) (rows 3, 4, 5, 6, and 7 ) forth: row 1) with the matrix ( 5 x 5 ) (rows 2, 3, 4, 5, and 6 ) fifth: row 0) with the matrix ( 5 x 5 ) (rows 1, 2, 3, 4, and 5 ) Thanks for your help in advanced How to print results in a table ******************************************************** Hi Zlatko, the following program belong to the topic " An array inside a 2D array ". In this program the user can enter five numbers once during the whole program being this a limitation but I think it could be fix it, besides this the user can choose with what size of the matrix work to check which row's numbers are inside the matrix chosen and which not. My problem here is I do not know how to print the results in a table. This is the output I want: Frecuency of the numbers of a row IN and/or OUT of a Matrix of size ( 5 x 5 ) Matrix's Numbers Total Matrix's Numbers ROWS (0) (1) (2) (3) (4) IN OUT IN OUT ------------------------------------------------------------------------------------ 0) 12 13 14 15 39 12 13 15 14 39 3 2 1) 1 23 34 35 49 1 23 34 35 49 4 1 2) 6 13 23 45 50 13 23 50 6 45 3 2 3) 5 12 34 36 51 12 34 36 51 5 4 1 4) 2 23 25 46 54 23 25 46 54 2 4 1 5) 12 15 23 27 34 6) 1 24 35 46 55 7) 3 13 35 47 50 8) 6 8 23 36 51 9) 5 12 25 39 54 To achieve this tabulation I think I should create: ? ???????????????1) A two dimensional array to store the entire data matrix ???????????????2) An array to store all the numbers within the matrix. ???????????????3) An array to store all the numbers out of it ???????????????4) An array to store the total of all the numbers within the matrix. 5) An array to store the total of all numbers outside the matrix. ?? ???????????????The problem is to determine how many arrays chose and what dimension should be used in each case. In point 1) I am clear that it is two dimensional array but others do not know. I would like to use a function to print the results because I will use it several time in my main program. I think this function should be like this: void printResults(int array[][columns], int numbersInMatrix[], int numbersOutMatrix[], int totalOfNumbersInOutMatrix[]) { for(int i=0; i but like I said before, the argument of this function it could be wrong. Could you help to do this because it is my first time to create a table this way. THANKS This is the code: const int maxRows = 20; // This is the maximum number of rows int rows=10; // this is the number of rows present const int columns=5; bool foundTheNumber = false; using namespace std; void firstPrintHeading(); void shiftDownOneRow(int theArray[][columns]); void secondPrintHeading(); bool isInArray(int number, int theArray[][columns], int startingRow, int endingRow); int main() { cout firstPrintHeading(); for(int i=0; i cout for(int j=0; j >array[0][j]; // just use 0 for the row } do { x=0; y=-1; cout >size; cout "; secondPrintHeading(); for(int i=0; i "; } else { notFoundCount++; cout "; } } cout "; } cout > choice; } while (choice == 'y'|| choice == 'Y'); cout } void firstPrintHeading() { cout cout "; cout "; } /* start at second last row, and shift it to the last then keep going backwards until the first row is shifted to the second row void shiftDownOneRow(int theArray[][columns]) { for(int shiftRow = rows-1; shiftRow >= 0; --shiftRow) { for(int col = 0; col } void secondPrintHeading() { cout "; cout "; cout "; cout "; } /* Search an array from the startingRow to the endingRow for a number. Return true if the number is found, and false otherwise bool isInArray(int number, int theArray[][columns], int startingRow, int endingRow) { for(int row = startingRow; row }
-
Answer:
Ok, if you say your program is running correctly, I believe you. However I probably broke it because I changed your analysis loop to go forwards, not backwards. I'm sure you can fix it if it is broken. To print out in a table, I used stringstream objects to hold parts of the output and then assembled the parts at the end of the analysis loop. You have to print the matrix row, and the analysis of the row, before moving on to the next row. That is the simplest way to create the table. If you want to just test the formatting, and get tired of inputting 5 numbers and the size, just uncomment the #define TESTING line. Good luck and const int maxRows = 20; // This is the maximum number of rows int rows=10; // this is the number of rows present const int columns=5; bool foundTheNumber = false; using namespace std; void firstPrintHeading(); void shiftDownOneRow(int theArray[][columns]); void secondPrintHeading(); bool isInArray(int number, int theArray[][columns], int startingRow, int endingRow); // // // uncomment this for testing your formatting //#define TESTING // // // int main() { cout firstPrintHeading(); for(int i=0; i cout for(int j=0; j >array[0][j]; // just use 0 for the row } do { x=0; y=-1; cout >size; size = 5; cout /* this is not the place to print out the row, it must be formatted in the analysis loop */ /* for(int i=0; i // really I think you dont need to go backwards here. // you decide if you want to start analysis at row 0 or row 1 // if starting at row 1, then you need to print row 0 before the analysis starts //for(int i=rows-1-size; i>=0; i--) for(int i = 0; i // // format the row // outputRow // // analyze the row // foundCount=0; notFoundCount=0; x++;// what name do think is meaningful for this variables y++; for(int j=0; j // // print out the rest of the rows // for(int i=size; i cout > choice; choice = 'n'; } while (choice == 'y'|| choice == 'Y'); cout } void firstPrintHeading() { cout } /* start at second last row, and shift it to the last then keep going backwards until the first row is shifted to the second row void shiftDownOneRow(int theArray[][columns]) { for(int shiftRow = rows-1; shiftRow >= 0; --shiftRow) { for(int col = 0; col } void secondPrintHeading() { cout } /* Search an array from the startingRow to the endingRow for a number. Return true if the number is found, and false otherwise bool isInArray(int number, int theArray[][columns], int startingRow, int endingRow) { for(int row = startingRow; row } Raul, I think you sent your question to the wrong person, and that person sent it the the question pool. It is a good thing I checked. I will work on your problem in the next day or two and I will add the answer here. In the mean time, check that your program does what you expect when the user enters a size of 1 or 2. Hello Raul. September 9 I suppose I can answer some of your questions. It seems that analysis is done row by row. Once one row is analyzed, the results can be printed out, and analysis moves on to the next row. If that is the case, then I can answer your 5 questions about array sizes. You asked about array dimensions and sizes. 1) A two dimensional array to store the entire data matrix Yes, you have that now. 2) An array to store all the numbers within the matrix. Yes, you need a one dimensional array. It seems that each row is analysed separately, and if you have 5 columns per row, then at most 5 numbers can be IN the matrix so the array should have space for 5, or whatever your column size is. 3) An array to store all the numbers out of it Yes, you need another one dimensional array for the numbers OUT of the matrix. Again, it seems that at most 5 numbers will be in this array. 4) An array to store the total of all the numbers within the matrix. I think you need just a single variable to store this because the analysis and output will be done row by row. As soon as one row is done, the variables can be reused for the next row. 5) An array to store the total of all numbers outside the matrix. Just like part 4, this can be a single integer. September 8 Before I can help you more, I need to understand a few things. For the matrix (0) (1) (2) (3) (4) 0) 12 13 14 15 39 1) 1 23 34 35 49 2) 6 13 23 45 50 3) 5 12 34 36 51 4) 2 23 25 46 54 5) 12 15 23 27 34 6) 1 24 35 46 55 7) 3 13 35 47 50 8) 6 8 23 36 51 9) 5 12 25 39 54 When the user is asked to input a size to analyze The user inputs 5. Does that mean that rows 0, 1, 2, 3 and 4 are analyzed ? When row 0 is analyzed why are 12, 13 and 15 IN ? Is it because there is a 12 in row 5, a 13 in row 2, and a 15 in row 5 ? For row 0, why is 14 OUT ? Is it because there is no 14 in the rest of the matrix, outside of row 0 ? Why is 39 OUT ? There is a 39 in row 9. I cannot find a consistent pattern of what it means to be IN or OUT. I think if you help me understand what you are trying to get, I can show you the code for it. Here is what I think you want. Given an ending row E, go through each row R from 0 to E-1. For each row R, print out which numbers in R are also in rows from 0 to E-1 but excluding row R. So if E is 5, you want to analyze rows 0 through 4. For row 0, all numbers in row 0, that are also in rows 1,2,3,4 are IN and all numbers not in rows 1,2,3,4 are OUT. For row 1, all numbers in row 1, that are also in rows 0,2,3,4 are IN and the rest are OUT. For row 2, all numbers in row 2, that are also in rows 0,1,3,4 are IN and the rest are OUT. For row 3, all numbers in row 3, that are also in rows 0,1,2,4 are IN and the rest are OUT. Finally, for row 4, all numbers in row 4, that are also in rows 0,1,2,3 are IN and the rest are OUT. Is that what you want ?
Miningco.com Visit the source
Related Q & A:
- How to Display Products in a table format?Best solution by Stack Overflow
- How to add primary key from multiple table as a foreign key in a table in sql server 2008?Best solution by stackoverflow.com
- How to print list in a jsp?Best solution by theserverside.com
- How To Print "HAPPY" In A Triangle In C++?Best solution by programiz.com
- How do I remove certain results from a Google search? Is there a way?
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.