I want to thank you experts for the program below. The output image is great but I'm having a problem with line 63, so I can't run the program. I am using Visual Studio 2019, C++ console for Windows 10. Could you please use the Visual Studio 2019 and help with this error. I have attached an screenshot image. Thank you very much. Modified code: #include using namespace std; //#define NCOLS 3 //constant declaration const int NCOLS=3; //function to convert 1D array to 2D array bool copy1DTo2D(int d1[], int size, int d2[][NCOLS], int nrows){ //checking the given condition if(size == NCOLS*nrows){ //copying the elements of 1D array to 2D array one by one for(int i=0; i
I want to thank you experts for the program below. The output image is great but I'm having a problem with line 63, so I can't run the program. I am using Visual Studio 2019, C++ console for Windows 10. Could you please use the Visual Studio 2019 and help with this error. I have attached an screenshot image.
Thank you very much.
Modified code:
#include <iostream>
using namespace std;
//#define NCOLS 3
//constant declaration
const int NCOLS=3;
//function to convert 1D array to 2D array
bool copy1DTo2D(int d1[], int size, int d2[][NCOLS], int nrows){
//checking the given condition
if(size == NCOLS*nrows){
//copying the elements of 1D array to 2D array one by one
for(int i=0; i<size; i++){
d2[i/NCOLS][i%NCOLS] = d1[i];
}
return true;
}
else{
return false;
}
}
//function to convert 2D array to 1D array
bool copy2DTo1D(int d2[][NCOLS], int nrows, int d1[], int size){
//checking the given condition
if(size == NCOLS*nrows){
//copying the elements of 2D array to 1D array one by one
for(int i=0; i<nrows; i++){
for(int j=0; j<NCOLS; j++){
d1[NCOLS*i+j] = d2[i][j];
}
}
return true;
}
else{
return false;
}
}
//function to display a 2D array
void dispD2(int d2[][NCOLS], int nrows){
for(int i=0; i<nrows; i++){
for(int j=0; j<NCOLS; j++)
cout<<d2[i][j]<<" ";
cout<<endl;
}
}
//function to display a 1D array
void dispD1(int d1[], int size){
for(int i=0; i<size; i++){
cout<<d1[i]<<" ";
}
}
//main code to check the functionality of the functions
int main()
{
cout<<endl<<"1DTo2D Conversion:"<<endl;
int d1[] = {7,2,3,8,5,9,7,5,9,1,6,2};
int size1 = 12;
int nrows1 = 4;
int d2[nrows1][NCOLS]; \\ error message
cout<<endl<<"1D array before 1DTo2D conversion:"<<endl;
dispD1(d1,size1);
if(copy1DTo2D(d1, size1, d2, nrows1)){
cout<<endl<<"2D array after 1DTo2D conversion:"<<endl;
dispD2(d2,nrows1);
}
else{
cout<<endl<<"Condition is not satisfied for 1DTo2D conversion."<<endl;
}
cout<<endl<<"2DTo1D Conversion:"<<endl;
int d3[][NCOLS] = {
{
2, 3, 4
},
{
1, 2, 4
},
{
3, 5, 9
},
{
5, 5, 7
},
{
1, 3, 2
}
};
int rows2 = 5;
const int size2 = 15;
int d4[size2];
cout<<endl<<"2D array before 2DTo1D conversion:"<<endl;
dispD2(d3,rows2);
if(copy2DTo1D(d3, rows2, d4, size2)){
cout<<"1D array after 2DTo1D conversion:"<<endl;
dispD1(d4,size2);
}
else{
cout<<endl<<"Condition is not satisfied for 2DTo1D conversion."<<endl;
}
cout<<endl;
return 0;
}
Step by step
Solved in 2 steps