online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
// C++ Program to read a square matrix // and print the main diagonal elements #include <iostream> using namespace std; // Create a matrix based graph representation. // It will need to support the following operations. // Ask the user how many points there are. DONE // Ask the user to label those points, ie "ABC", "XYZ", "C12"... DONE // Define the matrix as a square matrix (2 dimensional array) based on the number of points, also keep an array of the labels. DONE // Repeatedly ask the user to define edges between two points. Add these edges to the matrix. DONE // Have a list method that will list out all of the edges in the graph. // REFERENCE // https://www.geeksforgeeks.org/how-to-access-elements-of-a-square-matrix/ // https://www.geeksforgeeks.org/comparison-between-adjacency-list-and-adjacency-matrix-representation-of-graph/ // https://www.cplusplus.com/reference/utility/make_pair/ // https://www.tutorialspoint.com/cplusplus-program-to-implement-adjacency-matrix // https://stackoverflow.com/questions/2828648/how-to-pass-a-multidimensional-array-to-a-function-in-c-and-c // https://www.techiedelight.com/pass-2d-array-function-parameter-cpp/ // https://www.tutorialspoint.com/Passing-two-dimensional-array-to-a-Cplusplus-function // one possible implementation would be make pair to track the label for edge cout statement for user input // Code is formatted to be best read with labels the size of 3 this is hard coded per implementation requirements. int main() { // PROTOTYPE void printMatrix(string *labelArray, int *matrix, int rowIndex, int columnIndex, int size); int size ; cout << "How many points would you like this to be. Points meaning -size- of matrix: "; cin >> size; // example 2x2 matrix // A B // A [][] // B [][] // determine size, and modulo to create matrix form string label; // labeling convention for determining assignments string labelArray[size]; // label containing array to track for printing and labeling purposes int edgeYesOrNo; int counter = 0; cout << "Will now ask to label the points of graph matrix.\n"; int *matrix = new int[size * size]; // this is how to define a 2d array int rowIndex; // these are to access individual elements int columnIndex; // ^^ for(int i=0; i<size; i++) { cout << "Enter label: "; // enter the label here to insure that there is no redundancy cin >> label; labelArray[i] = label; } // Get the square matrix cout << "Enter 1 for edge 0 for no edge" << endl; for (rowIndex = 0; rowIndex < size; rowIndex++) { for (columnIndex = 0; columnIndex < size; columnIndex++) { cout << "Is there an edge to: " << labelArray[counter] << " and " << labelArray[columnIndex] << ": "; cin >> edgeYesOrNo; matrix[size * size] = edgeYesOrNo; } counter++; } printMatrix(labelArray, matrix, rowIndex, columnIndex, size); delete[] matrix; return 0; } // Display the matrix void printMatrix(string *labelArray, int *matrix, int rowIndex, int columnIndex, int size) { cout << "The matrix is\n" << endl; cout << " "; for(int i=0; i<size; i++) { cout << labelArray[i] << " "; // To print the labels so its understandable } cout << endl; for (rowIndex = 0; rowIndex < size; rowIndex++) { cout << labelArray[rowIndex] << " "; for (columnIndex = 0; columnIndex < size; columnIndex++) { cout << matrix[size * size] << " "; } cout << endl; } return; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue