Hi there,
I would like to receive some help and directions on how to start writing code for this particular project. I am completely new and would really want to learn how I go about doing this.
Write a complete C++ program that stores integer elements in a 2D array, multiplies the elements by a given number, and displays the contents of the 2D array on the screen in a tabular format. The 2D array should be of size 3 x 3. Declare the 2D array within main using const values for the ROWS and COLS.
Write a function called multiplyArray, which accepts a 2D array of integers, its size, and the number you are multiplying the elements by as arguments. The function should not return anything. The function will multiply the elements of the 2D array and store them in the same array.
In main you will prompt the user to enter the initial elements of the array. You will call the multiplyArray function within main and print the new elements of the array in main.
You must use nested loops to store the integers in the array and to print the contents of the array in main.
The output looks something like this:
*********** 2D Arrays ************
********* By: Name **************
Enter values for your array, one row at a time.
1 2 3
4 5 6
7 8 9
Enter a number to multiply your 2D array by: 2
The 2D array multiplied by 2 is:
2 4 6
8 10 12
14 16 18
Press any key to continue . . .
EDIT:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>
using namespace std;
int main()
{
int ar[3][3];
int n;
cout << "Enter values for your array, one row at a time" << endl;
cin >> n;
int *ar = new int[n];
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 3; col++)
{
ar[row][col] = row + col;
}
cout << endl;
}
return 0;
}
void multiplyArray(int ar[][3], int size)
{
}
|
EDIT: I do not know how to prompt the user to enter the initial elements of the array. After typing in 1 2 3, it stops and won't let me type the rest i.e 4, 5, 6, 7, 8, 9.