Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(main.cpp) #include #include #include #include #include linkedList.h using namespace std; void getAllPuppiesFromFile (string filename, linkedList& allPuppies ) { istringstream inSS; ifstream input(filename); if (input.is_open()) {

image text in transcribed
(main.cpp)
#include
#include
#include
#include
#include "linkedList.h"
using namespace std;
void getAllPuppiesFromFile (string filename, linkedList& allPuppies )
{
istringstream inSS;
ifstream input(filename);
if (input.is_open()) {
Puppy newPuppy;
while (input >> newPuppy.name >> newPuppy.breed >> newPuppy.age ) {
allPuppies.insertLast(newPuppy);
}
}
else {
cout
}
}
int main ( int argc, char **argv )
{
linkedList allPuppies;
string filename = "puppies.txt";
getAllPuppiesFromFile ( filename, allPuppies );
if ( argc >= 2 ) {
allPuppies.printAll();
}
else {
allPuppies.printOldestPuppy();
}
return 0;
}
(linkedList.cpp)
#include
#include
#include
#include
#include "linkedList.h"
using namespace std;
void getAllPuppiesFromFile (string filename, linkedList& allPuppies )
{
istringstream inSS;
ifstream input(filename);
if (input.is_open()) {
Puppy newPuppy;
while (input >> newPuppy.name >> newPuppy.breed >> newPuppy.age ) {
allPuppies.insertLast(newPuppy);
}
}
else {
cout
}
}
int main ( int argc, char **argv )
{
linkedList allPuppies;
string filename = "puppies.txt";
getAllPuppiesFromFile ( filename, allPuppies );
if ( argc >= 2 ) {
allPuppies.printAll();
}
else {
allPuppies.printOldestPuppy();
}
return 0;
}
image text in transcribed
(puppies.txt)
Jacky Poodle 12
Bella Beagle 2
Luna Boxer 5
Max Bulldog 6
Shawny Labrador 16
Bailey Terrier 11
Cooper Rottweiler 4
Given the software to manage puppies in an animal shelter. Puppies are stored as a singly linked list. Initial input is provided as a text file. Definition of all relevant classes (i.e. class Puppy, class linkedlist, class nodeType) are in the file linked List.h. The code to read all puppies from a textfile and create the linked list is in main.cpp. Both file are not be changed a. Implement the function insertLast() in the file linkedList.cpp to add another puppy to the end of the linked list b. Implement the function printOldestPuppy in the file linkedList.cpp which traverses the linked List and prints at the end the oldest Puppy using the following format: oldest Puppy 18 Zoldest puppy.name> Age oldest puppy, age> les main.cpp linked List.cpp linked List.h linkedList.h 1 Fifndef LINKEDLIST_H 2 #define LINKEDLIST_H 3 4 #include 5 6 using namespace std; 7 class Puppy { 9 public: 1e string name; 11 string breed; 12 13 puppies.txt int age; 15 16 struct nodeType { Puppy info; nodetype "link; 17 18 19 ); & 21 22 23 24 25 26 -27 28 29 3e 31 32 33 class linked List C private int count: node Type first; node Type -last; public linkedlisto; int length: void insertFirst(const Puppy newItem); void insertlast(const Puppy& newItem); void printAll() const; void printoldestPuppy const; }; 34 35 36 27 sendit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Moving Objects Databases

Authors: Ralf Hartmut Güting, Markus Schneider

1st Edition

0120887991, 978-0120887996

More Books

Students also viewed these Databases questions

Question

3. You can gain power by making others feel important.

Answered: 1 week ago

Question

Write down the circumstances in which you led.

Answered: 1 week ago