c++ #ifndef NETWORK #define NETWORK struct Node{ int x; int y; string label; Nod
ID: 3804566 • Letter: C
Question
c++
#ifndef NETWORK
#define NETWORK
struct Node{
int x;
int y;
string label;
Node()=default;
Node(int i, int j, string l) : x(i), y(j), label(l) {} ;
string to_string () const;
bool equal_nodes(const Node&);
double distance(const Node &)const;
};
struct Network{
string label;
map nodes;
vector route;
Network()=default;
Network(ifstream &);
string to_string () const;
Node get_node(string);
void put_node(Node);
bool in_route(const Node&);
Node closest(Node &);
string calculate_route(const Node&, const Node&);
};
#endif
1. Network(ifstream & )constructor.
oreads in a text description of the network from the provided (open) file stream
ofor each line, creates a new Node and initializes it according to the provided Node constructor (see test cases for format)
o adds the new node to the map nodes , where the string is the Node label.
2. Node get_node(string) and void put_node(Node). Either return a Node (based on a string, the label of a node in the map nodes) or adds a Node to the map nodes in a network.
o If get_node cannot find the indicated label in the nodes map, it throws an out_of_range error.
ouput for first method: A:(1,1)
output for second method:
network.txt contains:
Explanation / Answer
#include <stdio.h>
int main(void)
{
int const j = 20;
/* The below assignment is invalid in C++, results in error
In C, the compiler *may* throw a warning, but casting is
implicitly allowed */
int *ptr = &j; // A normal pointer points to const
printf("*ptr: %d ", *ptr);
return 0;
}
#include <stdio.h>
int main(void)
{
int const j = 20;
/* The below assignment is invalid in C++, results in error
In C, the compiler *may* throw a warning, but casting is
implicitly allowed */
int *ptr = &j; // A normal pointer points to const
printf("*ptr: %d ", *ptr);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.