Please write the following C code in C++. This is C now, I need the code in C++, not C# nor python or Java! WARNING IF YOU DO NOT DO THE REQUIRED TASK I WILL EITHER DOWNVOTE OR REPORT YOU. PLEASE PAY ATTENTION! I need this code to run on C++ . Screenshot of the result showing the .cpp file have to be also included, along with explanations/comment on the parts you changed.

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
 

Computer Science

Please write the following C code in C++.

This is C now, I need the code in  C++,

not C# nor python or Java!

WARNING IF YOU DO NOT DO THE REQUIRED TASK I WILL EITHER DOWNVOTE OR REPORT YOU.

PLEASE PAY ATTENTION! I need this code to run on C++ .

Screenshot of the result showing the .cpp file have to be also included, along with explanations/comment on the parts you changed.

#include <stdio.h>

#include <stdlib.h>

#include <stdbool.h>

 

#define MAX_SIZE 1000

int VERTEX_COUNT = 0;

 

bool **adjacencyMatrix(){

bool **Matrix = (bool **)malloc(sizeof(bool *) * MAX_SIZE);

for(int i = 0; i < MAX_SIZE;i++){

Matrix[i] = (bool *)malloc(sizeof(bool) * MAX_SIZE);

}

 

for (int i = 0; i < MAX_SIZE;i++){

for (int j = 0; j < MAX_SIZE;j++){

Matrix[i][j] = 0;

}

}

return Matrix;

}

 

void freeMatrix(bool **Matrix){

for(int i = 0; i < MAX_SIZE;i++){

free(Matrix[i]);

}

free(Matrix);

}

 

void readInput(bool **Matrix){

int a, b;

printf("get ready");

while(scanf("%d %d",&a, &b)){

VERTEX_COUNT = VERTEX_COUNT > b ? VERTEX_COUNT : b;

Matrix[a][b] = 1;

Matrix[b][a] = 1;

}

VERTEX_COUNT ++;

}

 

int *getDegree(bool **Matrix){

int *degree = malloc(sizeof(int) *VERTEX_COUNT);

for (int i = 0; i < VERTEX_COUNT;i++){

degree[i] = 0;

}

for (int i = 0; i < VERTEX_COUNT; i++){

for (int j = 0; j < VERTEX_COUNT; j++){

if (Matrix[i][j] == 1){

degree[i]++;

}

}

}

return degree;

}

 

bool **deleteVertex(bool **Matrix, int vertextodelete){

for (int i = 0; i < VERTEX_COUNT;i++){

Matrix[i][vertextodelete] = 0;

}

for (int j = 0; j < VERTEX_COUNT;j++){

Matrix[vertextodelete][j] = 0;

}

return Matrix;

}

 

bool **k_core_degeneracy(int k, bool **Matrix){

 

bool **resultMatrix = malloc(sizeof(bool *) * VERTEX_COUNT);

for (int i = 0; i < VERTEX_COUNT;i++){

resultMatrix[i] = malloc(sizeof(bool) * VERTEX_COUNT);

}

for (int i = 0; i < VERTEX_COUNT;i++){

for (int j = 0; j < VERTEX_COUNT;j++){

resultMatrix[i][j] = Matrix[i][j];

}

}

 

while(1){

int *degree = getDegree(resultMatrix);

 

int count = 0;

for (int i = 0; i < VERTEX_COUNT;i++){

if(degree[i]<k && degree[i]!=0){

count++;

}

}

 

if(count==0){

free(degree);

break;

}

 

for (int i = 0; i <VERTEX_COUNT; i++){

if (degree[i] < k){

resultMatrix = deleteVertex(resultMatrix, i);

}

}

free(degree);

}

return resultMatrix;

}

 

bool allzero(bool **matrix){

for (int i = 0; i < VERTEX_COUNT;i++){

for (int j = 0; j < VERTEX_COUNT;j++){

if(matrix[i][j]!=0){

return false;

}

}

}

return true;

 

}

 

void outputformat(bool **matrix){

for (int i = 0; i < VERTEX_COUNT;i++){

for (int j = 0; j < VERTEX_COUNT; j++){

if(matrix[i][j]!=0 && j>i){

printf("%d %d\n", i, j);

}

}

}

}

 

void freeResultMatrix(bool **Matrix){

for (int i = 0; i < VERTEX_COUNT;i++){

free(Matrix[i]);

}

free(Matrix);

}

 

int main(){

bool **Matrix = adjacencyMatrix();

printf("get ready 1");

readInput(Matrix);

bool **resultMatrix;

for (int i = 1;;i++){

resultMatrix = k_core_degeneracy(i, Matrix);

if(allzero(resultMatrix)){

freeResultMatrix(resultMatrix);

resultMatrix = k_core_degeneracy(i-1, Matrix);

printf("%d-core\n", i - 1);

break;

}

else{

freeResultMatrix(resultMatrix);

}

}

outputformat(resultMatrix);

freeMatrix(Matrix);

freeResultMatrix(resultMatrix);

return 0;

}

input is:

0 1
0 2
1 2
1 5
2 3
2 4
2 5
2 6
3 4
3 6
3 7
4 6
4 7
5 6
5 8
6 7
6 8

output is:

3-core 2 3 2 4 2 6 3 4 3 6 3 7 4 6 4 7 6 7
Expert Solution
steps

Step by step

Solved in 3 steps with 8 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
  • 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