Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //********************************************************************
- // Inputs info about dogs from a text file
- // Stores the info in a linked list using pointers
- //
- //********************************************************************
- #include <fstream>
- #include <iostream>
- #include <string>
- #include "dogType.h"
- using namespace std;
- typedef dogType infoType ;
- struct nodeType
- {
- infoType info;
- nodeType *link;
- };
- dogType newOne ( ifstream & inFile) ;
- void printPound ( nodeType * pound);
- int main()
- {
- nodeType * pound , * box;
- ifstream inFile;
- dogType stray;
- inFile.open("theDogs.txt");
- if (!inFile )
- {
- cout << " file not found ";
- system ( "pause");
- return 1;
- }
- //Input dog info from inFile
- // store the items in a linked list
- pound = NULL;
- while (!inFile.eof () )
- {
- stray = newOne (inFile);
- box = new nodeType;
- box->info = stray;
- box -> link = pound;
- pound = box;
- } // end of while
- cout << "A listing of the dogs in the pound list \n\n";
- printPound ( pound ) ;
- system ("pause" );
- return 0;
- }
- //Inputs the name, breed, age, and color of a Dog.
- //returns a dogType object initialized with the input values.
- dogType newOne ( ifstream& inFile)
- {
- int years;
- string name ;
- string color;
- string breed;
- dogType canine ;
- inFile >> name ;
- inFile >> color ;
- inFile >> breed ;
- inFile >> years ;
- // cout << name << " " << color << " "
- // << years << " " << breed << endl ;
- canine.setName (name);
- canine.setAge ( years);
- canine.setBreed ( breed);
- canine.setColor ( color);
- return canine;
- }
- void printPound ( nodeType * pound)
- {
- int counter = 0;
- char sym ;
- if (pound == NULL)
- cout << "no dogs in the pound\n\n";
- nodeType * ptr;
- ptr = pound;
- while ( ptr != NULL)
- {
- counter++;
- ptr->info.print ();
- ptr = ptr->link;
- cout << endl;
- if ( counter % 8 ==0)
- {
- cout << "type y and hit enter to continue ";
- cin >> sym;
- cout << "\n\n";
- }
- }
- cout << "\n================================\n\n"
- << "End of the list \n\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement