Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. class City {
  6.  
  7. public:
  8.  
  9. string x; // x = name
  10. int pop; // pop = population
  11. float area; //area of cities in SqKm.
  12.  
  13. City(){
  14. x = "noname";
  15. pop = 0;
  16. area = 0.0f;
  17. }
  18.  
  19. cityDetails(){
  20. cout<<"Name of City?"<<endl;
  21. cin>>x;
  22. cout<<"Population of the city?"<<endl;
  23. cin>>pop;
  24. cout<<"Area of the city in SquareKilometres?"<<endl;
  25. cin>>area;
  26. }
  27.  
  28.  
  29.  
  30. };
  31. class Neighbor {
  32. public:
  33.  
  34. int y ,*d, i; // y = no. of neighbors; d = distance to neighbors; i = index of neighbors;
  35.  
  36.  
  37. Neighbor(){
  38. y = 0;
  39. d = 0;
  40. i = 0;
  41. }
  42. };
  43.  
  44. class Graph {
  45. public:
  46.  
  47. int v;
  48. City *cities;
  49. Neighbor *neighbors;
  50. Graph(){
  51. }
  52.  
  53. void createGraph(){
  54. cout<<"How many cities?"<<endl;
  55. cin>>v;
  56. City c;
  57. for(int i=0; i<v; i++){
  58. cout<<"Enter details of "<<i+1<<"-th city: "<<endl;
  59. cities[i].cityDetails();
  60. }
  61. }
  62. void printGraph()
  63. {
  64. /*
  65. queue int q;
  66. color[start]=1;
  67. q.push(start);
  68.  
  69. while(!q.empty())
  70. {
  71. int u = q.front();
  72. cout<<"Visited:"<<u<<"\n";
  73. q.pop();
  74.  
  75. for(int i=0;i<g[u].size();i++)
  76. {
  77. int neighbor = g[u][i];
  78.  
  79. if(color[neighbor]==0)
  80. {
  81. q.push(g[u][i]);
  82. color[neighbor]=1;
  83. }
  84. }
  85. color[u] = 2; // u becomes BLACK
  86. }
  87. */
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95. friend istream& operator>>(istream&, Graph &g);
  96. friend ostream& operator<<(ostream&, Graph &g);
  97. friend Graph operator++(Graph& G, int);
  98.  
  99. };
  100.  
  101. ostream &operator << (ostream &output, Graph &g){
  102. output<<g.displayGraph()<<endl;
  103. return output;
  104. }
  105.  
  106. istream &operator >> (istream &input, Graph &g){
  107. input>>g.createGraph();
  108. return input;
  109. }
  110. Graph operator++ (Graph&, int){
  111.  
  112. }
  113.  
  114. Graph operator+= (Graph&, int){
  115.  
  116. }
  117.  
  118.  
  119. int main()
  120. {
  121. Graph g;
  122. cin>>g;
  123. cout<<g;
  124. G++;
  125. City cityObj;
  126. cout<<”Specity a new City: “; cin>>cityObj;
  127. G += cityObj;
  128. string cityName; City *neighborPtr; int n;
  129. cout<<”Enter a City name: “; cin>>cityName;
  130. getNeighborsOfcityName(g, cityName, neighborPtr, n);
  131. int totalPopulation=0;
  132.  
  133. for(i=0;i<n;i++){
  134. totalPopulation += neighborPtr[i];
  135. cout<<”Total population of the neighbors of ”<<cityName<<” is: ”<< totalPopulation<<endl;
  136. }
  137.  
  138. return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement