Question

In: Computer Science

Cannot figure out why my c++ program keeps crashing, I am attempting to have the user...

Cannot figure out why my c++ program keeps crashing, I am attempting to have the user decide the size of a 2d array then fill said array.

#include <iostream>

using namespace std;

typedef int* IntArrayPtr;

int main(void)

{

int column, row, i, j;

IntArrayPtr *arr_num = new IntArrayPtr[row];

cout << " " << endl

<< " This program creates a 2D array of dynamic memory, fills it with user entered numbers, " << endl

<< " Then prints the array to the screen. " << endl

<< " " << endl

<< " Enter the column dimensions of the array. " << endl

<< " " << endl;

cin >> column;

cout << " " << endl

<< " Enter the row dimensions of the array. " << endl

<< " " << endl;

cin >> row;

// This loop allocates dynamic memory for a 2D array of intigers.

// arr_num is now a 2dD array of dynamic memory and is of the size entered by the user.

for (i = 0; i < column; i++)

{

arr_num[i] = new int[column];

}

cout << " " << endl

<< " Enter " << column << " sets of " << row << " whole numbers. " << endl

<< " " << endl;

for (i = 0; i < column; i++)

{

for (j = 0; j < row; j++)

{

cin >> arr_num[i][j];

}

}

cout << " " << endl

<< " Now to display the 2D array of numbers entered. " << endl

<< " " << endl;

for (i = 0; i < column; i++)

{

for (j = 0; j < row; j++)

{

cout << arr_num[i][j] << " ";

cout << endl;

}

}

for (i = 0; i < column; i++)

{

delete[] arr_num[i];

}

delete[] arr_num;

return 0;

}

Solutions

Expert Solution

Its working properly I have tested it properly

#include <iostream>

using namespace std;

typedef int* IntArrayPtr;

int main(void)

{

int column, row, i, j;

IntArrayPtr *arr_num = new IntArrayPtr[row];

cout << " " << endl

<< " This program creates a 2D array of dynamic memory, fills it with user entered numbers, " << endl

<< " Then prints the array to the screen. " << endl

<< " " << endl

<< " Enter the column dimensions of the array. " << endl

<< " " << endl;

cin >> column;

cout << " " << endl

<< " Enter the row dimensions of the array. " << endl

<< " " << endl;

cin >> row;

// This loop allocates dynamic memory for a 2D array of intigers.

// arr_num is now a 2dD array of dynamic memory and is of the size entered by the user.

for (i = 0; i < column; i++)

{

arr_num[i] = new int[column];

}

cout << " " << endl

<< " Enter " << column << " sets of " << row << " whole numbers. " << endl

<< " " << endl;

for (i = 0; i < column; i++)

{

for (j = 0; j < row; j++)

{

cin >> arr_num[i][j];

}

}

cout << " " << endl

<< " Now to display the 2D array of numbers entered. " << endl

<< " " << endl;

for (i = 0; i < column; i++)

{

for (j = 0; j < row; j++)

{

cout << arr_num[i][j] << " ";

}
cout << endl;
}

for (i = 0; i < column; i++)

{

delete[] arr_num[i];

}

delete[] arr_num;

return 0;

}

Please comment below if you have any issues


Related Solutions

For Python, I cannot figure out why "and" is printing at the beginning of my list....
For Python, I cannot figure out why "and" is printing at the beginning of my list. Can someone help? listToPrint = [] while True: newWord = input("Enter a word to add to the list (prest return to stop adding words) > ") newWord == "": break else: listToPrint.append(newWord) for item in listToPrint[:-1]: print(item, end=', ') print('and', listToPrint[-1]) If I enter m, n, b to the list, it executes to and m, n, b
I am attempting to calculate the annual net cash flow for this problem and cannot figure...
I am attempting to calculate the annual net cash flow for this problem and cannot figure out how to solve it. Case Study: Alexander & Sons Alexander & Sons Company is currently considering the purchase of equipment that produces mugs. The equipment needed would cost $3 million, with a disposal value of $400,000. The equipment would be able to produce 55 million mugs over its 5-year life. The company has estimated that approximately 11 million mugs would be sold for...
I cannot figure out why my random name generator isn't producing the letter u or z....
I cannot figure out why my random name generator isn't producing the letter u or z. Can someone help me out? The language is java. import java.util.Random; public class BrandName {    public static void main(String[] args) {        Random random = new Random();        System.out.println("Brand Name Generator - Michael Wikstrom\n");        char odd[] = { 'b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'v', 'w', 'x', 'y',       ...
in java: In my code at have my last two methods that I cannot exactly figure...
in java: In my code at have my last two methods that I cannot exactly figure out how to execute. I have too convert a Roman number to its decimal form for the case 3 switch. The two methods I cannot figure out are the public static int valueOf(int numeral) and public static int convertRomanNumber(int total, int length, String numeral). This is what my code looks like so far: public static void main(String[] args) { // TODO Auto-generated method stub...
I am attempting to write a script using bash on Linux. My program must save the...
I am attempting to write a script using bash on Linux. My program must save the long list format of the parent directory to a text file. Then, it must print how many items are in this parent directory. Then, it must sort the file in reverse order and save it to a different text file. I understand that the parent directory is accessed using cd .., and I understand that a file can be written to by echoing and...
Whenever I am attempting to write a simple program on C++ I get an error message...
Whenever I am attempting to write a simple program on C++ I get an error message that reads "cout was not declared in this scope". Literally every time. This has become frustrating because I have even written my code the exact same way as some of my classmates who got theirs to compile and run with no sign of this error at all, and yet min gives this answer. I will leave an example of a code where this error...
I am trying to figure out which test analysis to use for my research questions. I...
I am trying to figure out which test analysis to use for my research questions. I was thinking about think about multivariate because of the number of variable being addressed in the study but there is also the possibility to use univariate to address each question. What are the current levels of police satisfaction in CMPD jurisdictions? What is the public’s perception of crime in CMPD jurisdictions? Does “hot spot” policing reduce crime in CMPD jurisdictions? How does broken windows...
I have done the first part of this problem, but I cannot figure out the second...
I have done the first part of this problem, but I cannot figure out the second part. I know there are several different answers already posted on Chegg for this particular problem with different acceleration and time, but I need this one specifically, with a step by step solution. Again...just PART B....the answer to Part A is 201.72 A helicopter carrying Dr. Evil takes off with a constant upward acceleration of 4.20 m/s2. Secret agent Austin Powers jumps on just...
I am working on a C++ program, where a user puts in a notation a playing...
I am working on a C++ program, where a user puts in a notation a playing card and the output is the full name of the card.(ex: KH = King of Hearts) I have most of it working but I want to have an error come up when the user puts in the wrong info and then loop back to the original question. Am I setting it up wrong? Pasted below is my code #include<iostream> #include<string> using namespace std; int...
I am Writing a C-Program to read and write files. but none of my code is...
I am Writing a C-Program to read and write files. but none of my code is working like it should be. Please fix all code and supply output response. Please try to use existing code and code in comments. But if needed change any code that needs to be changed. Thank you in advance //agelink.c //maintains list of agents //uses linked list #include <stdio.h> #include <stdlib.h> #define TRUE 1 void listall(void); void newname(void); void rfile(void); void wfile(void); struct personnel {...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT