onsider the following function main int main Int inStock 1
onsider the following function main: int main () { Int inStock [10] [4]; Int alpha [20]; Int beta [20]; Int gamma [4] = {11, 13, 15, 17}; Int delta [10] = {3, 5, 2, 6, 10, 9, 7, 11, 1, 8}; . . . } Write the definition of the function setZero that initializes any one-dimensional array of type int to 0. Write the definition of the function inputArray that prompts the user to input 20 numbers and stores the numbers into alpha. Write the definition of the function doubleArray that initializes the elements of beta to two times the corresponding elements in alpha. Make sure that you prevent the function from modifying the elements of alpha. Write the definition of the function copyGamma that sets the elements of the first row if inStock to gamma and the remaining rows of inStock to three times the previous row of inStock. Make sure that you prevent the function from modifying the elements of gamma. Write the definities of the function copyAlphaBeta that stores alpha into the first five rows of inStock and beta into the last five rows of inStock. Make sure that you prevent the function from modifying the elements of alpha and beta. Write the definition of the function printArray that prints any one-dimensional array of type int. Print 15 elements per line. Write the definition of the function setInStock that prompts the user to input the elements for the first column of inStock. The function should then set the elements in the remaining columns to two times the corresponding element in the previous column, minus the corresponding element in delta. Write C++ statements that call each of the functions in parts a through g Write a C++ program that tests the function main and the function discussed in parts a through g. (Add additional functions, such as print a two-dimensional array, as needed.) Please make sure to test your program before posting!! This is for C++ using visual studio. Example main() that you should use as your base: int main() { int inStock[10][4]; // Rows=10, Cols=4 int alpha[20]; int beta[20]; int gamma[4] = {11,13,15,17}; int delta[10] = {3,5,2,6,10,9,7,11,1,8}; setZero(alpha,20); setZero(beta,20); inputArray(alpha); printArray(alpha,20); doubleArray(beta,alpha); printArray(beta,20); copyGamma(inStock,gamma); printArray(inStock); copyAlphaBeta(inStock,alpha,beta); printArray(inStock); setInStock(inStock,delta); printArray(inStock); cin.get(); cin.get(); return 0; }
Solution
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include \"stdafx.h\"
#include <iostream>
using namespace std;
void setZero(int * arr, int n) {
int i;
for (i = 0;i < n;i++) {
arr[i] = 0;
}
}
void inputArray(int * arr) {
int i;
cout << \"Enter 20 numbers:\";
for (i = 0;i < 20;i++) {
cin >> arr[i];
}
}
void doubleArray(int * beta, int * alpha) {
int i;
for (i = 0;i < 20;i++) {
beta[i] = 2 * alpha[i];
}
}
void copyGamma(int inStock[][4], int * gamma) {
for (int i = 0;i < 10;i++) {
for (int j = 0;j < 4;j++) {
if (i == 0) {
inStock[i][j] = gamma[j];
}
else {
inStock[i][j] = 3 * inStock[i - 1][j];
}
}
}
}
void copyAlphaBeta(int instock[][4], int * alpha, int * beta) {
for (int i = 0;i < 10;i++) {
for (int j = 0;j < 4;j++) {
if (i < 5) {
instock[i][j] = alpha[j];
}
else {
instock[i][j] = beta[j];
}
}
}
}
void printArray(int * a, int n) {
cout << \"\ ------------------\";
for (int i = 0;i < n;i++) {
cout << a[i] << \" \";
if (i % 15 == 0) {
cout << \"\ \";
}
}
cout << \"------------------\ \";
}
void printArray(int inStock[][4]) {
cout << \"\ ------------------\";
for (int i = 0;i < 10;i++) {
for (int j = 0;j < 4;j++) {
cout << inStock[i][j]<<\" \";
}
cout << \"\ \";
}
cout << \"------------------\ \";
}
void setInStock(int inStock[][4],int * delta) {
for (int i = 0;i < 4;i++) {
for (int j = 0;j < 10;j++) {
if (i == 0) {
cout << \"Enter value of inStock[\" << j << \"][\" << i << \"]\";
cin >> inStock[j][i];
}
else {
inStock[j][i] = inStock[j][i - 1] - delta[i];
}
}
}
}
int main()
{
int inStock[10][4]; // Rows=10, Cols=4
int alpha[20]; int beta[20];
int gamma[4] = {11,13,15,17};
int delta[10] = {3,5,2,6,10,9,7,11,1,8};
setZero(alpha,20);
setZero(beta,20);
inputArray(alpha);
printArray(alpha,20);
doubleArray(beta,alpha);
printArray(beta,20);
copyGamma(inStock,gamma);
printArray(inStock);
copyAlphaBeta(inStock,alpha,beta);
printArray(inStock);
setInStock(inStock,delta);
printArray(inStock);
cin.get();
cin.get();
return 0;
}
![onsider the following function main: int main () { Int inStock [10] [4]; Int alpha [20]; Int beta [20]; Int gamma [4] = {11, 13, 15, 17}; Int delta [10] = {3, 5 onsider the following function main: int main () { Int inStock [10] [4]; Int alpha [20]; Int beta [20]; Int gamma [4] = {11, 13, 15, 17}; Int delta [10] = {3, 5](/WebImages/7/onsider-the-following-function-main-int-main-int-instock-1-990842-1761509494-0.webp)
![onsider the following function main: int main () { Int inStock [10] [4]; Int alpha [20]; Int beta [20]; Int gamma [4] = {11, 13, 15, 17}; Int delta [10] = {3, 5 onsider the following function main: int main () { Int inStock [10] [4]; Int alpha [20]; Int beta [20]; Int gamma [4] = {11, 13, 15, 17}; Int delta [10] = {3, 5](/WebImages/7/onsider-the-following-function-main-int-main-int-instock-1-990842-1761509494-1.webp)
![onsider the following function main: int main () { Int inStock [10] [4]; Int alpha [20]; Int beta [20]; Int gamma [4] = {11, 13, 15, 17}; Int delta [10] = {3, 5 onsider the following function main: int main () { Int inStock [10] [4]; Int alpha [20]; Int beta [20]; Int gamma [4] = {11, 13, 15, 17}; Int delta [10] = {3, 5](/WebImages/7/onsider-the-following-function-main-int-main-int-instock-1-990842-1761509494-2.webp)