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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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;
}

File
View Project
Buld Debug
Search (Col-
Test
Analyon Tools Eatensions Window Help
Consolehpplicatio
O 3-
Debug
- Local Windows Debugger- :?
e Live Share
nsoleAppliction.cpp"
SConseleApplicatien
- Gubal Scepel
O maino
47
tunction te display 10 array
Bvedd dispos(int di1. int size)(
for (int i-e iesie i)
cout e difi) ce
49
se
Emor List - Cument Pjea (Consolelpplication
51
O 1 Emer A OWenings 0 O Messages
52
Cunent Project
Search Erer List
53
Cede Descrigtien
Project
File
Line
54
E EO02 epresion must have a constant value
Consolehppication
Consoleipplicationt.epp
55
nain code to check the functionality of the funct
Lnt nain)
58
cout ee endi ce "ADTo0 Converston e endi
Int di[] - (7,2,,8,5,,7,5,,1,6,
59
61
int sieel- 12
62
int nrowsi4
Int da[aceni1(NCOLS)
63
64
• tocal variable) int nrowst
65
cout e en
dispo(4, Search Online
if (copya0
cout
disgt
67
espression must have a constant value
the value of variable "owst" (declared at lin 62) cannet be used
constant
Search Online
else (
cout ce endi ce "Condition is not satisfied for s0To20 converston." « endis
73
74
75
cout e endi ce "20Toto Conversion" « endla
int d[(NCOLS]-
2, 3, 4
100%
L 9 ON7 S CRF
O Ready
+ Add to Seurce Control
810 PM
P Type here to search
221
Team Esploer
Transcribed Image Text:File View Project Buld Debug Search (Col- Test Analyon Tools Eatensions Window Help Consolehpplicatio O 3- Debug - Local Windows Debugger- :? e Live Share nsoleAppliction.cpp" SConseleApplicatien - Gubal Scepel O maino 47 tunction te display 10 array Bvedd dispos(int di1. int size)( for (int i-e iesie i) cout e difi) ce 49 se Emor List - Cument Pjea (Consolelpplication 51 O 1 Emer A OWenings 0 O Messages 52 Cunent Project Search Erer List 53 Cede Descrigtien Project File Line 54 E EO02 epresion must have a constant value Consolehppication Consoleipplicationt.epp 55 nain code to check the functionality of the funct Lnt nain) 58 cout ee endi ce "ADTo0 Converston e endi Int di[] - (7,2,,8,5,,7,5,,1,6, 59 61 int sieel- 12 62 int nrowsi4 Int da[aceni1(NCOLS) 63 64 • tocal variable) int nrowst 65 cout e en dispo(4, Search Online if (copya0 cout disgt 67 espression must have a constant value the value of variable "owst" (declared at lin 62) cannet be used constant Search Online else ( cout ce endi ce "Condition is not satisfied for s0To20 converston." « endis 73 74 75 cout e endi ce "20Toto Conversion" « endla int d[(NCOLS]- 2, 3, 4 100% L 9 ON7 S CRF O Ready + Add to Seurce Control 810 PM P Type here to search 221 Team Esploer
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Pixels
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education