File Edit View Project Build Debug Test Analyoe Tools Extensions Window Help Search (Chl-Q ConsoleApplication O 3- -- Debug x86 - Local Windows Debugger- II A Live Share ConsoleApplications.cpp" X ConsoleApplicationa (Global Scope) O maino 63 64 65 66 67 68 69 70 71 72 73 int d2[orousi][NCOLS]; cout e endl c« "10 array before 10To20 conversion:" « endl; dispo1(d1, sizel); If (copy10Te20(41, sizei, d2, nrowsi)) { cout e endl « "20 array after 10Te0 conversion:" « endl; dispo2(42, nrows1); else { cout « endl « "Condition is not satisfied for 10To20 conversion." « endl; 74 75 76 77 78 79 cout « endl « "20To1D Conversion:" « endl; int d[I[NCOLS) ( 2, 3, 4 82 1, 2, 4 83 84 Emor List - Current Project (ConseleApplications) 2 Emors 85 3, 5, 9 O Warnings 0 O Messages * Build - IntelISense Curent Project Code Description E EOO epression must have a constant value E EO028 expression must have a constant value 86 Search Error List 87 Project ConsoleApplications ConsoleApplications File Line 88 5, 5, 7 Consolekpplication.cpp 63 ConsoleApplicationa.cpP % 89 90 91 1, 3, 2 92 93 int rows2 5; int size- 15; 94 95 96 cout cc endl c *20 array before 20TolD conversion:" c endl; 02 10 + + 97 100%. Ln: 109 Ch 2 SPC CRLF O Ready + Add to Source Control - 544 PM P Type here to search 74"F 8/6/2021 Team Explorer X D Toolbox

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 lines 63 and 96, 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 these 2 errors. I have attached an screenshot image. Thank you very much.

In C++, 

Can you please look at the code below and revise/fix so it will work according to instructions and criteria.

Instruction

1) Write a function that copies a 1D array to a 2D array. The function’s prototype is

bool copy1DTo2D(int d1[], int size, int d2[][NCOLS], int nrows);

where

size > 0

NCOLS > 0

nrows > 0

NCOLS is a global constant

size = NCOLS * nrows

the function returns true if the parameters and constants satisfy these conditions and false otherwise.

the relation between 1d array indices and 2d array indices is

2d row index = 1d array index / NCOLS

2d column index = 1d array index modulus operator NCOLS

 

2) Write a function that copies a 2D array to a 1D array. The function’s prototype is

bool copy2DTo1D(int d2[][NCOLS, int nrows, int d1[], int size);

where

size > 0

NCOLS > 0

nrows > 0

NCOLS is a global constant

the function return true if the parameters and constants satisfy these conditions and false otherwise.

the relation between 1d array indices and 2d array indices is

1d array index = NCOLS x 2d array row index + 2d array column index

Criteria

compiles, runs, tests

the program compiles with error, runs without crashing, and tests the functions thoroughly

copy 1d to 2d function

the function returns true if the parameters and global constant satisfy list of the relationships and restrictions in the problem and false otherwise.
the function copies a fixed size 1d array to a fixed size2d array. the function uses the formulas listed in the problem to calculate 2d array index pairs from 1d array indices.
 

copy 2d to 1d function

the function returns true if the parameters and global constant satisfy list of the relationships and restrictions in the problem and false otherwise.
the function copies a fixed size 2d array to a fixed size 1d array. the function uses the formulas listed in the problem to calculate 1d array indices from 2d array index pairs.

 

Expert C++ code:

#include <iostream>

using namespace std;

//constant declaration
int const 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];

    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;
    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
Edit View Project Build Debug Test Analyoe Tools Extensions Window Help
Search (Chl-Q
ConsoleApplication
O 3- -- Debug
x86
- Local Windows Debugger- II
A Live Share
ConsoleApplications.cpp" X
ConsoleApplicationa
(Global Scope)
O maino
63
64
65
66
67
68
69
70
71
72
73
int d2[orousi][NCOLS];
cout e endl c« "10 array before 10To20 conversion:" « endl;
dispo1(d1, sizel);
If (copy10Te20(41, sizei, d2, nrowsi)) {
cout e endl « "20 array after 10Te0 conversion:" « endl;
dispo2(42, nrows1);
else {
cout « endl « "Condition is not satisfied for 10To20 conversion." « endl;
74
75
76
77
78
79
cout « endl « "20To1D Conversion:" « endl;
int d[I[NCOLS) (
2, 3, 4
82
1, 2, 4
83
84
Emor List - Current Project (ConseleApplications)
2 Emors
85
3, 5, 9
O Warnings 0 O Messages * Build - IntelISense
Curent Project
Code Description
E EOO epression must have a constant value
E EO028 expression must have a constant value
86
Search Error List
87
Project
ConsoleApplications
ConsoleApplications
File
Line
88
5, 5, 7
Consolekpplication.cpp 63
ConsoleApplicationa.cpP %
89
90
91
1, 3, 2
92
93
int rows2 5;
int size- 15;
94
95
96
cout cc endl c *20 array before 20TolD conversion:" c endl;
02 10 + +
97
100%.
Ln: 109 Ch 2 SPC CRLF
O Ready
+ Add to Source Control -
544 PM
P Type here to search
74"F
8/6/2021
Team Explorer
X D
Toolbox
Transcribed Image Text:File Edit View Project Build Debug Test Analyoe Tools Extensions Window Help Search (Chl-Q ConsoleApplication O 3- -- Debug x86 - Local Windows Debugger- II A Live Share ConsoleApplications.cpp" X ConsoleApplicationa (Global Scope) O maino 63 64 65 66 67 68 69 70 71 72 73 int d2[orousi][NCOLS]; cout e endl c« "10 array before 10To20 conversion:" « endl; dispo1(d1, sizel); If (copy10Te20(41, sizei, d2, nrowsi)) { cout e endl « "20 array after 10Te0 conversion:" « endl; dispo2(42, nrows1); else { cout « endl « "Condition is not satisfied for 10To20 conversion." « endl; 74 75 76 77 78 79 cout « endl « "20To1D Conversion:" « endl; int d[I[NCOLS) ( 2, 3, 4 82 1, 2, 4 83 84 Emor List - Current Project (ConseleApplications) 2 Emors 85 3, 5, 9 O Warnings 0 O Messages * Build - IntelISense Curent Project Code Description E EOO epression must have a constant value E EO028 expression must have a constant value 86 Search Error List 87 Project ConsoleApplications ConsoleApplications File Line 88 5, 5, 7 Consolekpplication.cpp 63 ConsoleApplicationa.cpP % 89 90 91 1, 3, 2 92 93 int rows2 5; int size- 15; 94 95 96 cout cc endl c *20 array before 20TolD conversion:" c endl; 02 10 + + 97 100%. Ln: 109 Ch 2 SPC CRLF O Ready + Add to Source Control - 544 PM P Type here to search 74"F 8/6/2021 Team Explorer X D Toolbox
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Managing System
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
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