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

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',       ...
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...
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 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...
Show work please, this is the last problem for my homework and I cannot figure this...
Show work please, this is the last problem for my homework and I cannot figure this out for the life of me An IP4 datagram arrived with the following information in the header (in hexadecimal):                0x4A 00 00 56 00 03 58 50 18 06 58 50 7C 4E 03 02 B4 0E OF 15 2f………. Are there any options? How many bytes, if any? How many more routers can the packet travel to? Explain. What is the size...
My Java program keeps "running." I know I need to close a "loop" but I can't...
My Java program keeps "running." I know I need to close a "loop" but I can't find it. I'm learning how to code. This is confusing for me. import java.util.Scanner; import java.util.ArrayList; public class SteppingStone4_Loops {    public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String recipeName = ""; ArrayList<String> ingredientList = new ArrayList(); String newIngredient = ""; boolean addMoreIngredients = true; System.out.println("Please enter the recipe name: "); recipeName = scnr.nextLine();    do {    System.out.println("Would you...
Write a C++ program that keeps asking user to enter a positive integer number until a...
Write a C++ program that keeps asking user to enter a positive integer number until a sentinel value (999) is entered. Then for each positive number entered by the user, find out how many digits it consists. (Hint: divide a number by 10 will remove one digit from the number. You can count how many divisions it needs to bring the number to 0.) An example of executing such a program is shown below. Note that the user input is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT