Fill in Order Details

  • Submit paper details for free using our simple order form

Make Payment Securely

  • Add funds to your account. There are no upfront payments. The writer will only be paid once you have approved your paper

Writing Process

  • The best qualified expert writer is assigned to work on your order
  • Your paper is written to standard and delivered as per your instructions

Download your paper

  • Download the completed paper from your online account or your email
  • You can request a plagiarism and quality report along with your paper

help with c 3

This assignment is the first of a two-part solution and will count for Lab #11, with the second part counting as Lab #12.

Graph and Input File

The data file posted in this module, contains a data set with information on a social media network (Facebook). This is a real data set with anonymized names from the data competition site Kaggle_(links to an external_site.) — lots more to explore there, by the way!

The format of the file is CSV (which you used in previous labs) but this time there are more fields in each row. The file forms an adjacency matrix for 200 people. Each row contains the name in the first field, then a series of 0 or 1 indicating whether that person is a friend of the person in that column. If there is a 1 in that column, the two people are friends (they are connected to each other in the graph), otherwise they are not. The graph is not connected — there are some disconnected “islands” of people in the file.

The supplied file starter.cpp builds a graph using a std::map structure from the data, where the “key” is the person’s name (a string) and the “value” is a Person structure holding the adjacencies:

struct Person {
vector<string> friends;
};

The ‘friends’ field is a list of neighbors, identified by their integer index into an array of names, which is also that person’s key in the map. For example, if friends[1] is 1, that person is adjacent to the person with column index 1. There are no weights in this graph; two people are either connected or not.

Assignment

Write a program that prompts the user for the names of two people, and output whether or not there is a path between them in the graph. You can output only a yes/no answer (no printing of the path is required). Continue looping for more input until the user enters ‘X’ for a name.

Hints

Use depth-first search (DFS) or breadth-first search (BFS), either recursive or interative, and stop the search when you reach the target node.

You will need to keep track of which nodes have been “visited” somewhere in your code.

Note that the first column (names) can be either a first name, or a first and last name. Like most data sets, this one could use some cleaning.

What to submit

Submit only your .cpp file for the solution.

Example Input/Output

Here are a few examples to try to make sure your code is working:

Enter the starting name (X to quit): Mirza Khan

Enter the ending name (X to quit): Amir
There IS a path between these two people.

Enter the starting name (X to quit): Tu Viloria

Enter the ending name (X to quit): Isabelle
There IS a path between these two people.

Enter the starting name (X to quit): Ali Ghufron

Enter the ending name (X to quit): Michael Felix
There is NOT a path between these two people.

Enter the starting name (X to quit): Hanno Plitz

Enter the ending name (X to quit): Denno
There is NOT a path between these two people.

Enter the starting name (X to quit): X

Exiting...

starter.cpp:

#include <fstream>

#include <iostream>

#include <sstream>

#include <vector>

#include <map>

#include <iomanip>

#include <cstdlib>

using namespace std;

//

// This file provides a starting point for Lab #11. It reads the

// input file (.csv), builds a graph from the adjacencies in the file,

// and will print the friends list for any node requested.

//

// The graph is a simple adjacency list format — each node (struct Person)

// contains a string vector of all of its friend nodes.

//

#define IS_QUIT(s) (s == “X” || s == “x”)

#define FILENAME “facebook.csv”

using namespace std;

struct Person {

vector<string> friends;

};

void parse_line(const string &str,

vector<string> &line) {

istringstream istr(str);

string tmp;

while (getline(istr, tmp, ‘,’)) {

line.push_back(tmp);

}

}

int main() {

ifstream inFile(FILENAME);

vector<string> row;

vector<string> names;

map<string, Person> everyone;

string inputLine;

// Verify that the file open was OK

if (!inFile.good()) {

cerr << “Invalid file.” << endl;

return (-1);

}

// Read the header line of the file (first line, contains column labels).

// We save this line (names) so we can lookup the string names in the

// below loop.

getline(inFile, inputLine);

parse_line(inputLine, names);

// Reach each subsequent entry

while (getline(inFile, inputLine)) {

if (inFile.eof())

break;

vector<string> row;

Person p;

parse_line(inputLine, row);

// Start at 1 (0th field is the string name)

for (size_t i = 1; i < row.size(); i++) {

int adj_status = atoi(row[i].c_str());

// A ‘1’ indicates an adjacency, so skip if we get a ‘0’

// If there is an adjacency to this person, push the string name

// of that person on the adjacency list.

if (adj_status == 1)

p.friends.push_back(names[i]);

}

// Add this (new) person to the map.

// In this map, the key is the string name of the person, and

// the value is their Person structure (adjacency list).

everyone.insert(make_pair(row[0], p));

}

for (;;) {

cout << endl << “Enter the name “

<< “and I’ll tell you their friends (X to quit): “;

getline(cin, inputLine);

if (IS_QUIT(inputLine))

break;

// Look up the adjacency list of this person in the map

if (everyone.count(inputLine) == 0) {

cout << “That person is not in the map.” << endl;

continue;

}

Person this_person = everyone[inputLine];

// Output all their friends

cout << inputLine << ” is friends with: ” << endl;

for (size_t i = 0; i < this_person.friends.size(); i++) {

cout << “t” << this_person.friends[i] << endl;

}

}

cout << “Exiting…” << endl;

return (0);

}

WHAT OUR CURRENT CUSTOMERS SAY

  • Google
  • Sitejabber
  • Trustpilot
Zahraa S
Zahraa S
Absolutely spot on. I have had the best experience with Elite Academic Research and all my work have scored highly. Thank you for your professionalism and using expert writers with vast and outstanding knowledge in their fields. I highly recommend any day and time.
Stuart L
Stuart L
Thanks for keeping me sane for getting everything out of the way, I’ve been stuck working more than full time and balancing the rest but I’m glad you’ve been ensuring my school work is taken care of. I'll recommend Elite Academic Research to anyone who seeks quality academic help, thank you so much!
Mindi D
Mindi D
Brilliant writers and awesome support team. You can tell by the depth of research and the quality of work delivered that the writers care deeply about delivering that perfect grade.
Samuel Y
Samuel Y
I really appreciate the work all your amazing writers do to ensure that my papers are always delivered on time and always of the highest quality. I was at a crossroads last semester and I almost dropped out of school because of the many issues that were bombarding but I am glad a friend referred me to you guys. You came up big for me and continue to do so. I just wish I knew about your services earlier.
Cindy L
Cindy L
You can't fault the paper quality and speed of delivery. I have been using these guys for the past 3 years and I not even once have they ever failed me. They deliver properly researched papers way ahead of time. Each time I think I have had the best their professional writers surprise me with even better quality work. Elite Academic Research is a true Gem among essay writing companies.
Got an A and plagiarism percent was less than 10%! Thanks!

ORDER NOW


Consider Your Assignments Done

“All my friends and I are getting help from eliteacademicresearch. It’s every college student’s best kept secret!”

Jermaine Byrant
BSN

“I was apprehensive at first. But I must say it was a great experience and well worth the price. I got an A!”

Nicole Johnson
Finance & Economics

Our Top Experts

See Why Our Clients Hire Us Again And Again!


OVER

10.3k
Reviews

RATING
4.89/5
Average

YEARS
13
Mastery

Success Guarantee

When you order form the best, some of your greatest problems as a student are solved!

Reliable

Professional

Affordable

Quick

Using this writing service is legal and is not prohibited by any law, university or college policies. Services of Elite Academic Research are provided for research and study purposes only with the intent to help students improve their writing and academic experience. We do not condone or encourage cheating, academic dishonesty, or any form of plagiarism. Our original, plagiarism-free, zero-AI expert samples should only be used as references. It is your responsibility to cite any outside sources appropriately. This service will be useful for students looking for quick, reliable, and efficient online class-help on a variety of topics.