Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Daniel Hong
- //Assignment 5
- //Hoenigman
- #include "CommunicationNetwork.h"
- #include <iostream>
- #include <fstream>
- #include <sstream>
- #include <string>
- using namespace std;
- void CommunicationNetwork::addCity(string previous, string newCity)
- {
- City *temp = new City;
- temp -> cityName = newCity;
- head -> prev = temp;
- temp -> message = "";
- if (previous == "First")
- {
- temp -> next = head;
- temp -> prev = NULL;
- head = temp;
- }
- else
- {
- City *current = head;
- while (current != NULL)
- {
- if (current -> cityName == previous)
- {
- temp -> next = current -> next;
- current -> next = temp;
- break;
- }
- current = current -> next;
- }
- }
- }
- void CommunicationNetwork::printNetwork()
- {
- City *current = head;
- cout << "===CURRENT PATH===" << endl;
- while (current != nullptr)
- {
- cout << current -> cityName << " -> ";
- current = current -> next;
- }
- cout << " NULL" << endl;
- cout << "==================" << endl;
- }
- void CommunicationNetwork::transmitMsg(char *filename)
- {
- string word;
- ifstream file;
- file.open(filename);
- if (!file.is_open())
- {
- cout << "File not found." << endl;
- }
- while (file >> word)
- {
- City *current = head;
- current -> message = word;
- City *sender = new City;
- while (current != NULL)
- {
- cout << current -> cityName << " received " << current -> message << endl;
- if (current -> next != NULL)
- {
- current -> next -> message = current -> message;
- if (current != head)
- {
- sender -> message = "";
- }
- sender = current;
- }
- current = current -> next;
- }
- }
- }
- void CommunicationNetwork::buildNetwork()
- {
- string cities[10] =
- {
- "Los Angeles",
- "Phoenix",
- "Denver",
- "Dallas",
- "St. Louis",
- "Chicago",
- "Atlanta",
- "Washington, D.C.",
- "New York",
- "Boston",
- };
- City *city;
- City *prev = new City;
- for (int i = 0; i < 10; i++)
- {
- city = new City;
- city -> cityName = cities[i];
- city -> message = "";
- city -> next = NULL;
- if (i == 0)
- {
- head = city;
- prev = head;
- }
- else
- {
- prev -> next = city;
- prev = city;
- }
- }
- }
- CommunicationNetwork::~CommunicationNetwork()
- {
- clearNetwork();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement