Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- int y=0,z=0;
- class Nodes
- {
- protected:
- string name;
- int n;
- string adjacent[10] = {"Null"} ;
- int cost[10] = {0};
- public:
- Nodes()
- {
- cout << "Input Node name:" <<endl;
- getline(cin,name);
- cout << "Input number of Adjacent & Cost:"<<endl;
- cin >> this->n;
- }
- void getData()
- {
- int i;
- string str1 = "X";
- char adjName[100];
- cout << "Input Adjacent list:" <<endl;
- cin.ignore();
- for(i=0; i<n; i++)
- {
- cin.getline(adjName,100);
- adjacent[i] = adjName;
- if(adjacent[i].compare(str1) == 0)
- {
- adjacent[i] = "Null";
- showInfo();
- y=1;
- break;
- }
- }
- if(y==0)
- {
- cout << "Input Cost list:" <<endl;
- for(i=0; i<n; i++)
- {
- cin >> cost[i];
- if(cost[i] == 88) //ASCII value of X
- {
- cost[i] = 0;
- showInfo();
- break;
- }
- }
- }
- }
- void showInfo()
- {
- cout<< "\n\nNode name is: "<< this->name <<endl;
- int i;
- cout << "\nAdjacent List:" <<endl;
- for(i=0; i<n; i++)
- {
- cout << adjacent[i] << endl;
- }
- cout << "\nCost List:" <<endl;
- for(i=0; i<n; i++)
- {
- cout << cost[i] <<endl;
- }
- z = 1;
- }
- };
- int main()
- {
- Nodes san_franciso;
- san_franciso.getData();
- if(z==0)
- {
- san_franciso.showInfo();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment