Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8992623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:59:56+00:00 2026-06-15T22:59:56+00:00

C++ skills are not that sharp when it comes to spotting errors that the

  • 0

C++ skills are not that sharp when it comes to spotting errors that the compiler does not know how to find. Obviously there is not a missing ‘;’ before the ‘*’. Perhaps one of those situations where it doesn’t like an include statement. Can someone please help find the error(s) and explain why it’s throwing it? Thank you!

Main.cpp

#include <iostream>
#include "Grid.h"
using namespace std;
int main()
{
    Grid myGrid(15, 15, 15, 3);
    myGrid.PrintGrid();
    cout << endl << "The node closest to <0,0> is " << myGrid.GetNodeClosestToOrigin()->letter << "." << endl;
    system("pause");
    return 0;
}

Edge.h

#pragma once

#include "Node.h"
using namespace std;
class Edge
{
public:
    Node* destination;
    double weight;
    Edge(Node* destination, double weight);
    ~Edge(void);
};

Edge.cpp

#include "Edge.h"
#include "Node.h"
using namespace std;
Edge::Edge(Node* destination, double weight)
{
    this->destination = destination;
    this->weight = weight;
}
Edge::~Edge(void)
{
}

Node.h

#pragma once
#include <vector>
#include "Node.h"
#include "Edge.h"
using namespace std;
class Node
{
public:
    int x;
    int y;
    char letter;
    vector<Edge> edges;
    Node(void);
    ~Node(void);
    void AddEdge(Node* destination);
    bool ContainsEdgeWithDestination(Node* destination);
    double GetDistanceTo(int x, int y);
    double GetDistanceTo(Node* node);
};

Node.cpp

#include "Node.h"
using namespace std;
Node::Node(void)
{
}
Node::~Node(void)
{
}
void Node::AddEdge(Node* destination)
{
    double weight = GetDistanceTo(destination);

    Edge myEdge(destination, weight);
    this->edges.push_back(myEdge);
}
bool Node::ContainsEdgeWithDestination(Node* destination)
{
    for (int i = 0; i < edges.size(); i++)
    {
        if (edges[i].destination == destination)
            return true;
    }
    return false;
}
double Node::GetDistanceTo(int x, int y)
{
    double a = ((double)x - (double)this->x)*((double)x - (double)this->x);
    double b = ((double)y - (double)this->y)*((double)y - (double)this->y);
    return sqrt(a + b);
}
double Node::GetDistanceTo(Node* node)
{
    return GetDistanceTo(node->x, node->y);
}

UPDATE:

Edge.h

#pragma once

#include "Node.h"

using namespace std;

class Grid
{
private:
    Node *nodes;
    int gridWidth;
    int gridHeight;
    int numNodes;
    int neighborsPerNode;
    double GetDistance(int x1, int y1, int x2, int y2);
public:
    Grid(int gridWidth, int gridHeight, int numNodes, int neighborsPerNode);
    ~Grid();
    void Initialize();
    bool IsNodeAtLocation(int x, int y);
    Node* GetNodeAtLocation(int x, int y);
    Node* GetNodeClosestToOrigin();
    void PrintGrid();
};

Grid.cpp

#include <iostream>
#include <random>
#include <math.h>
#include <stdlib.h>
#include <time.h>

#include "Grid.h"
#include "Node.h"

using namespace std;

Grid::Grid(int gridWidth, int gridHeight, int numNodes, int neighborsPerNode)
{
    this->gridWidth = gridWidth;
    this->gridHeight = gridHeight;
    this->numNodes = numNodes;
    this->neighborsPerNode = neighborsPerNode;

    nodes = new Node[numNodes];

    Initialize();
}

Grid::~Grid(void)
{
}

void Grid::Initialize()
{
    srand(time(NULL));

    // Create nodes.
    for (int i = 0; i < numNodes; i++)
    {
        int x;
        int y;

        do
        {
            // Randomize a position for a new node.
            x = rand() % gridWidth;
            y = rand() % gridHeight;
        } while (IsNodeAtLocation(x, y));

        // Position is available to place new node.
        nodes[i].x = x;
        nodes[i].y = y;
        nodes[i].letter = 65 + i;
    }

    // Create edges.
    int edgeCount[15];

    for (int i = 0; i < numNodes; i++) edgeCount[i] = 0;

    for (int i = 0; i < numNodes; i++)
    {
        if (edgeCount[i] < neighborsPerNode)
        {
            for (int j = edgeCount[i]; j < neighborsPerNode; j++)
            {
                // Randomize a node to create an edge to.
                int destination;

                while(true)
                {
                    destination = rand() % numNodes;
                    // Check if destination is current node.
                    if (destination == i) continue;

                    // Check if destination already has maximum amount of edges.
                    if (edgeCount[destination] >= neighborsPerNode) continue;

                    // Check if node already has an edge with this destination.
                    if (nodes[i].ContainsEdgeWithDestination(&nodes[destination])) continue;

                    // Should be ok. Create new edge.
                    nodes[i].AddEdge(&nodes[destination]);
                    nodes[destination].AddEdge(&nodes[i]);
                    edgeCount[destination]++;
                    break;
                }
            }
        }
    }

    cout << "We're in business" << endl;
}

bool Grid::IsNodeAtLocation(int x, int y)
{
    for (int i = 0; i < numNodes; i++)
    {
        if (nodes[i].x == x && nodes[i].y == y)
            return true;
    }

    return false;
}

Node* Grid::GetNodeAtLocation(int x, int y)
{
    for (int i = 0; i < numNodes; i++)
    {
        if (nodes[i].x == x && nodes[i].y == y)
            return &nodes[i];
    }

    return NULL;
}

Node* Grid::GetNodeClosestToOrigin()
{
    double smallestDistance = 999999.0;
    int indexOfNode;

    for (int i = 0; i < numNodes; i++)
    {
        double distance = GetDistance(0, 0, nodes[i].x, nodes[i].y);

        if (distance < smallestDistance)
        {
            smallestDistance = distance;
            indexOfNode = i;
        }
    }

    return &nodes[indexOfNode];
}

double Grid::GetDistance(int x1, int y1, int x2, int y2)
{
    double a = ((double)x2 - (double)x1)*((double)x2 - (double)x1);
    double b = ((double)y2 - (double)y1)*((double)y2 - (double)y1);
    return sqrt(a + b);
}

void Grid::PrintGrid()
{
    for (int i = 0; i < gridWidth * 2 + 2; i++)
        cout << "-";
    cout << endl;

    for (int y = 0; y < gridHeight; y++)
    {
        cout << "|";

        for (int x = 0; x < gridWidth; x++)
        {
            Node* myNode = GetNodeAtLocation(x, y);

            if (myNode != NULL)
                cout << myNode->letter << " ";
            else
                cout << "  ";
        }
        cout << "|" << endl;
    }

    for (int i = 0; i < gridWidth * 2 + 2; i++)
        cout << "-";
    cout << endl;
}

Error List:
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:59:57+00:00Added an answer on June 15, 2026 at 10:59 pm

    You have a circular include issue – node includes edge and the other way around. In the header files, replace

    #include <Node.h>
    

    with

    class Node;
    

    (similar for Edge) and it should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my skills with jquery core are not that great, though Ive been working with
I know there is a tool that enables me to see what actually gets
My google search skills have failed me, and I am not a database expert
What kind of skills should a WPF developer know to create MVVM applications? Things
i hava made a select box of skills..there are skills listed in it.. if
I did some tests on pow(exponent) method. Unfortunately, my math skills are not strong
I have this code that imports a csv file into an Access table. There
I have to do a very simple operation but my programming skills are not
I'm new to this kind of forum and my English skills are not the
Is there any compiler which will help me convert my python code to proper

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.