I want this code in C++

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 this code in C++

#include <stdio.h>

#include<malloc.h>
//function to fill
int Equalcols(int *A,int rows,int cols)
{
    //creating a dynamic array of length cols to store sum of each column
    int *b=(int*)(malloc(sizeof(int)*cols));
    int i,j;
    //initializing the values zero in b array
    for(i=0;i<cols;i++)
    {
        *(b+i)=0;
    }
    //loop to add elements of each column to respective index in b array
    for(i=0;i<rows;i++)
    {
        for(j=0;j<cols;j++)
        {
            //adding value of element in respective column to index in b array
            *(b+j)+=*(A+j+cols*i);
            //printf("%d %d\n",j+cols*i,*(A+j+cols*i));
        }
    }
    //loop to check whether sum is equal or not
    for(i=1;i<cols;i++)
    {
        //printf("%d %d\n",*(b+i-1),*(b+i));
        //checking for consecutive value are not equal
        if(*(b+i-1)!=*(b+i))
        {
            //returning 0
            return 0;
        }
    }
    //returning 1
    return 1;
}

int main()
{
    //variables to store no. of  rows and columns value
    int rows,cols,i,j;
    //telling user about the Maximum dimensions
    printf("Maximum allowed dimensions of array is 10 X 10\n");
    //asking user for no. of rows
    printf("Enter no. of rows: ");
    //entering user input
    scanf("%d",&rows);
    //asking user for no. of columns
    printf("Enter no. of columns: ");
    //entering no. of columns
    scanf("%d",&cols);
    
    //2D array creation
    int *A=(int*)(malloc(sizeof(int)*rows*cols));

    //loop to ask user input for elements in array
    for(i=0;i<rows;i++)
    {
        printf("Enter the elements of %d row:\n",i);
        for(j=0;j<cols;j++)
        {
            //storing value in particular index
            scanf("%d",(A+cols*i+j));
        }
    }

    //calling function
    int res=Equalcols(A,rows,cols);
    if (res)
    {
        printf("\nSum of elements in columns are equal.");
    }
    else
    {
        printf("\nSum of elements in columns are not equal.");
    }
    return 0;
}

Expert Solution
Step 1

The code has been converted into C++ using the respective libraries that are required to perform the functionality of this code.

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
ADT and Class
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