Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create two programs, one in Python the other in C++. In one, write the graph pro

ID: 3865907 • Letter: C

Question

Create two programs, one in Python the other in C++. In one, write the graph provide below with file inputs to a binary file; you can choose the format. In the other, read the binary file you wrote and print out all the nodes that stop at Roads (have "Road" in the node name).

Note, neither C++ or Python natively store strings in binary; you'll have to know the length when writing and loading.

You can choose Python for your reader/C++ for your writer or vice versa.

Graph network: Used for word 'Road'

Barrow-in-Furness:Vicarstown:1
Vicarstown:Ballahoo:5
Vicarstown:Crovan's Gate:7
Ballahoo:Norramby:2
Ballahoo:Crovan's Gate:2
Crovan's Gate:Cros-ny-Cuirn:2
Crovan's Gate:Kellsthorpe Road:4
Cros-ny-Cuirn:Glennock:3
Glennock:Rheneas:3
Rheneas:Skarloey:1
Skarloey:Lakeside:1
Lakeside:Rheneas:1
Kellsthorpe Road:Rolf's Castle:2
Rolf's Castle:Kirk Ronan:2
Kellsthorpe Road:Kildane:7
Kildane:Abbey:2
Abbey:Kirk Machan:4
Kirk Machan:Shiloh:1
Shiloh:Skarloey Road:2
Skarloey Road:Devil's Back:1
Devil's Back:Culdee Fell Summit:1
Kirk Machan:Peel Godred:2
Kildane:Cronk:1
Cronk:Maron:2
Maron:Wellsworth:4
Wellsworth:Suddery:3
Suddery:Brendam:4
Wellsworth:Crosby:2
Crosby:Knapford:4
Knapford:Dryaw:2
Dryaw:Toryreck:1
Toryreck:Elsbridge:2
Elsbridge:Hackenbeck:3
Hackenbeck:Ffarquhar:1
Knapford:Tidmouth:1
Tidmouth:Haultraugh:3
Haultraugh:Arlesburgh West:2
Arlesburgh West:Arlesburgh Bridge St.:1
Arlesburgh Bridge St.:Ffaquhar Road:1
Ffaquhar Road:Marthwaite:1
Marthwaite:Arlesdale Green:1
Arlesdale Green:Arlesdale:1

Explanation / Answer

int main() { string name1 = "first", name2 = "sec", name3 = "third"; int j = 0, k = 0; ifstream ifs(name1.c_str()); // Here I want to read from the ordinary text file (name1). ifs >> j; // Now j equals to 5 because name1 contains digit 5. ifs.close(); ofstream ofs(name2.c_str(), ios::binary); ofs.write(as_bytes(j), sizeof(int)); // Here I want to write that j to name2 file in binary mode. ofs.close(); ifstream ifs1(name2.c_str(), ios::binary); // Here I want to read from that binary file (name2). ifs.read(as_bytes(k), sizeof(int)); // Here I hope k becomes 5. ofstream ofs1(name3.c_str()); ofs1
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote