SabirSazzad

Fahad sir Assignment (Half done)

Feb 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. int y=0,z=0;
  5.  
  6. class Nodes
  7. {
  8. protected:
  9.     string name;
  10.     int n;
  11.     string adjacent[10] = {"Null"} ;
  12.     int cost[10] = {0};
  13. public:
  14.     Nodes()
  15.     {
  16.         cout << "Input Node name:" <<endl;
  17.         getline(cin,name);
  18.         cout << "Input number of Adjacent & Cost:"<<endl;
  19.         cin >> this->n;
  20.  
  21.     }
  22.     void getData()
  23.     {
  24.        int i;
  25.        string str1 = "X";
  26.        char adjName[100];
  27.        cout << "Input Adjacent list:" <<endl;
  28.        cin.ignore();
  29.        for(i=0; i<n; i++)
  30.        {
  31.            cin.getline(adjName,100);
  32.            adjacent[i] = adjName;
  33.            if(adjacent[i].compare(str1) == 0)
  34.            {
  35.                adjacent[i] = "Null";
  36.                showInfo();
  37.                y=1;
  38.                break;
  39.            }
  40.  
  41.        }
  42.        if(y==0)
  43.        {
  44.            cout << "Input Cost list:" <<endl;
  45.            for(i=0; i<n; i++)
  46.            {
  47.                cin >> cost[i];
  48.                if(cost[i] == 88) //ASCII value of X
  49.                {
  50.                    cost[i] = 0;
  51.                    showInfo();
  52.                    break;
  53.                }
  54.            }
  55.        }
  56.  
  57.  
  58.     }
  59.     void showInfo()
  60.     {
  61.         cout<< "\n\nNode name is: "<< this->name <<endl;
  62.         int i;
  63.         cout << "\nAdjacent List:" <<endl;
  64.         for(i=0; i<n; i++)
  65.         {
  66.             cout << adjacent[i] << endl;
  67.         }
  68.         cout << "\nCost List:" <<endl;
  69.         for(i=0; i<n; i++)
  70.         {
  71.             cout << cost[i] <<endl;
  72.         }
  73.         z = 1;
  74.  
  75.     }
  76. };
  77. int main()
  78. {
  79.     Nodes san_franciso;
  80.     san_franciso.getData();
  81.     if(z==0)
  82.     {
  83.        san_franciso.showInfo();
  84.     }
  85.  
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment