Advertisement
blainebrown

Untitled

Nov 29th, 2011
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. //********************************************************************
  2. // Inputs info about dogs from a text file
  3. // Stores the info in a linked list using pointers
  4. //
  5. //********************************************************************
  6.  
  7. #include <fstream>
  8. #include <iostream>
  9. #include <string>
  10. #include "dogType.h"
  11.  
  12. using namespace std;
  13.  
  14. typedef dogType infoType ;
  15.  
  16.  
  17.  
  18. struct nodeType
  19. {
  20. infoType info;
  21. nodeType *link;
  22. };
  23.  
  24. dogType newOne ( ifstream & inFile) ;
  25. void printPound ( nodeType * pound);
  26.  
  27.  
  28.  
  29.  
  30. int main()
  31. {
  32.  
  33. nodeType * pound , * box;
  34.  
  35. ifstream inFile;
  36. dogType stray;
  37.  
  38. inFile.open("theDogs.txt");
  39. if (!inFile )
  40. {
  41. cout << " file not found ";
  42. system ( "pause");
  43. return 1;
  44. }
  45.  
  46.  
  47.  
  48. //Input dog info from inFile
  49. // store the items in a linked list
  50. pound = NULL;
  51.  
  52. while (!inFile.eof () )
  53. {
  54. stray = newOne (inFile);
  55. box = new nodeType;
  56. box->info = stray;
  57. box -> link = pound;
  58. pound = box;
  59. } // end of while
  60.  
  61. cout << "A listing of the dogs in the pound list \n\n";
  62. printPound ( pound ) ;
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. system ("pause" );
  70. return 0;
  71.  
  72. }
  73. //Inputs the name, breed, age, and color of a Dog.
  74. //returns a dogType object initialized with the input values.
  75. dogType newOne ( ifstream& inFile)
  76. {
  77. int years;
  78. string name ;
  79. string color;
  80. string breed;
  81. dogType canine ;
  82.  
  83.  
  84. inFile >> name ;
  85. inFile >> color ;
  86. inFile >> breed ;
  87. inFile >> years ;
  88.  
  89. // cout << name << " " << color << " "
  90. // << years << " " << breed << endl ;
  91.  
  92. canine.setName (name);
  93. canine.setAge ( years);
  94. canine.setBreed ( breed);
  95. canine.setColor ( color);
  96.  
  97. return canine;
  98. }
  99.  
  100. void printPound ( nodeType * pound)
  101. {
  102. int counter = 0;
  103. char sym ;
  104. if (pound == NULL)
  105. cout << "no dogs in the pound\n\n";
  106.  
  107. nodeType * ptr;
  108. ptr = pound;
  109. while ( ptr != NULL)
  110. {
  111. counter++;
  112. ptr->info.print ();
  113. ptr = ptr->link;
  114. cout << endl;
  115. if ( counter % 8 ==0)
  116. {
  117. cout << "type y and hit enter to continue ";
  118. cin >> sym;
  119. cout << "\n\n";
  120. }
  121. }
  122. cout << "\n================================\n\n"
  123. << "End of the list \n\n";
  124. }
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement