Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- class City {
- public:
- string x; // x = name
- int pop; // pop = population
- float area; //area of cities in SqKm.
- City(){
- x = "noname";
- pop = 0;
- area = 0.0f;
- }
- cityDetails(){
- cout<<"Name of City?"<<endl;
- cin>>x;
- cout<<"Population of the city?"<<endl;
- cin>>pop;
- cout<<"Area of the city in SquareKilometres?"<<endl;
- cin>>area;
- }
- };
- class Neighbor {
- public:
- int y ,*d, i; // y = no. of neighbors; d = distance to neighbors; i = index of neighbors;
- Neighbor(){
- y = 0;
- d = 0;
- i = 0;
- }
- };
- class Graph {
- public:
- int v;
- City *cities;
- Neighbor *neighbors;
- Graph(){
- }
- void createGraph(){
- cout<<"How many cities?"<<endl;
- cin>>v;
- City c;
- for(int i=0; i<v; i++){
- cout<<"Enter details of "<<i+1<<"-th city: "<<endl;
- cities[i].cityDetails();
- }
- }
- void printGraph()
- {
- /*
- queue int q;
- color[start]=1;
- q.push(start);
- while(!q.empty())
- {
- int u = q.front();
- cout<<"Visited:"<<u<<"\n";
- q.pop();
- for(int i=0;i<g[u].size();i++)
- {
- int neighbor = g[u][i];
- if(color[neighbor]==0)
- {
- q.push(g[u][i]);
- color[neighbor]=1;
- }
- }
- color[u] = 2; // u becomes BLACK
- }
- */
- }
- friend istream& operator>>(istream&, Graph &g);
- friend ostream& operator<<(ostream&, Graph &g);
- friend Graph operator++(Graph& G, int);
- };
- ostream &operator << (ostream &output, Graph &g){
- output<<g.displayGraph()<<endl;
- return output;
- }
- istream &operator >> (istream &input, Graph &g){
- input>>g.createGraph();
- return input;
- }
- Graph operator++ (Graph&, int){
- }
- Graph operator+= (Graph&, int){
- }
- int main()
- {
- Graph g;
- cin>>g;
- cout<<g;
- G++;
- City cityObj;
- cout<<”Specity a new City: “; cin>>cityObj;
- G += cityObj;
- string cityName; City *neighborPtr; int n;
- cout<<”Enter a City name: “; cin>>cityName;
- getNeighborsOfcityName(g, cityName, neighborPtr, n);
- int totalPopulation=0;
- for(i=0;i<n;i++){
- totalPopulation += neighborPtr[i];
- cout<<”Total population of the neighbors of ”<<cityName<<” is: ”<< totalPopulation<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement