Question

The goal of this homework is to write a small database system for an Animal Shelter....

The goal of this homework is to write a small database system for an Animal Shelter. This is a no-kill
shelter like the one just west of the Addition Airport. You will accept animal “donations” to the
shelter, but mostly only dogs and cats. (But yes, there may be the occasional hamster or other nondog,
non-cat animal donation.) At present, all we need to do is write the skeleton of a database that
will track all the animals in the shelter. We will add animals to the database and print reports based
on the database. (Clearly there is a lot more functionality we could add to this program, but for
now, we will just do the above.)

Approach:
1. Use three classes for this project: Animal, Cat, and Dog. Cat and Dog will be subclasses of
Animal.
2. Each animal in the database will have the following attributes:
a. Type (dog, cat, hamster, etc.)
b. Name
c. Age
d. Weight
e. Breed
f. Color
g. Health
3. There is a data file that you will need to read and parse to create the animal objects and set
their data attributes in the database. An example file input will look like this:
AnimalType,Name,Age,Weight,Breed,Color,Health,Sound
cat,Morris,9,3,mixed,yellow,good,meow
cat,Mittens,1,,Calico,brown and white,good,Mew mew
cat,Junior,1,2,Tabby,black,needs shots,Meow
chipmunk,Chippy,2,1,white and gold,good,sniff sniff
dog,Priss,,3,Heinz,white,good,bark
cat,Charcoal,1,2,Siamese,white and yellow,good
The data file will be a CSV (comma-separated-values) file saved from an Excel file; thus it will
be a plain text file with commas used as field separators. Note as in the above example that
some of the values might be empty, meaning “unknown.” Each line of the data file will
represent one animal – a cat, a dog, or some other animal. Dogs and Cats will be created
using their own Class definitions; other animals will simply be Animals and only animals.
The final data file that you are to use will be uploaded to the eLearning site and called
AnimalShelterData.csv.
4. Keep track of the number of objects created for each type; thus you will know how many
cats have been created, how many dogs, and how many total animals (you don’t have to
count “other” animals since you can always compute that with
Nbr “others” created = nbr Animals created – nbr Dogs created + nbr Cats created
5. Use a separate static variable within each class to count the objects created, and create a
method to keep count of the number of objects and to assign a unique number to every
newly created object. For example, there will be both a numberOfCats member and a
myCatNumber member in the Cat class.
6. Create a .h file and a .cpp file for each of the three classes and link them into the main.cpp
file.
7. Create and maintain three separate vectors of objects – one each for Animal, Cat, and Dog.
Store every animal in the Animal vector (the Animal vector will store all three types of
objects – animals, cats, and dogs).
8. In addition, keep a separate vector of Cats and one of Dogs. Store all cats in the Cat vector
and all dogs in the Dog vector (that’s in addition to storing them in the Animal vector). You
won’t need any other classes.
9. Read the data input file line by line, collecting the animal attributes. Create an object of the
appropriate type and set all the attributes to the values you read from the file.
10. For each class, create an Introduction method that will have the animal/cat/dog speak and
then say its name, age, color, health, etc.
11. Once you’ve read the entire database and created all the objects and vectors, create four
reports:
a. Report 1: total number of animals created, number of cats created, number of dogs
created
b. Report 2: An Animal report. Have each animal in the Animal vector introduce itself
(by “speaking”, giving its name, age, etc.)
c. Report 3: A Cat report: same as above but using all Cat attributes.
d. Report 4: A Dog report: same as above but using all Dog attributes.
12. Print the reports to both the console and to a disk file. Submit the disk file with your project
submission. Remember, both a disk file output stream and the console are ostream objects!
So all you need is one set of output routines that you can use for both, as we saw in class.

Annotations for the code:
1. Create and submit with your project a README.txt file that contains any special notes you
want me and/or the grader to be aware of when examining, executing, and grading your
program.
2. The main function can be at either the beginning or the end of the program. I don’t care which.
3. Add comments at the top of your program file to include your name, the name of the program,
and any relevant notes on how your design works when executed.
4. Add a change log in your comments that list the major changes you make to your logic and
when – nothing too terribly detailed, but a list of breadcrumbs that will remind you and others
of what you’ve done as your program becomes more sophisticated and/or nearly complete.
5. Point out (in the comments at the top of your program) any special features or techniques you
added using a comment saying something like “// Special Features:”
6. Comment your code effectively, as we discussed in class. Use descriptive variable names
everywhere so that the code becomes as self-documenting as possible. Use additional
commentary only to improve readability and comprehensibility by other people.
7. You absolutely MUST use consistent indentation and coding styles throughout the program.
Failure to do so will result in a loss of three points.
8. If the program does not work at all, or works incorrectly, at least 5 points will be deducted.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.Animal.h

#pragma once

#include <iostream>
using namespace std;

class Animal
{
public:
Animal();
~Animal();
string speak();
string Type;
string Name;
string Age;
string Weight;
string Breed;
string Color;
string Health;
string Sound;
};

2. Animal.cpp

#include "Animal.h"

Animal::Animal()
{
}


Animal::~Animal()
{
}

string Animal::speak()
{
return "Name:" + Name + ",Age:" + Age + ",Weight:" + Weight + ",Breed:" + Breed + ",Color:" + Color + ",Health:" + Health + ",Sound:" + Sound;
}


3. Dog.h

#pragma once
#include "Animal.h"
class Dog :
public Animal
{
public:
Dog();
~Dog();
int MyDogNumber;
static int NoOfDogCounts;
string speak();
};

4. Dog.cpp

#include "Dog.h"

Dog::Dog()
{
MyDogNumber = NoOfDogCounts;
NoOfDogCounts++;
}
string Dog::speak()
{
return "Name:" + Name + ",Age:" + Age + ",Weight:" + Weight + ",Breed:" + Breed + ",Color:" + Color + ",Health:" + Health + ",Sound:" + Sound;
}

Dog::~Dog()
{
}


5.Cat.h

#pragma once
#include "Animal.h"
class Cat :
public Animal
{
public:
Cat();
~Cat();
int MyCatNumber;
static int NoOfCatCounts;
string speak();
};

6. Cat.cpp

#include "Cat.h"

Cat::Cat()
{
MyCatNumber = NoOfCatCounts;
NoOfCatCounts++;
}


Cat::~Cat()
{
}

string Cat::speak()
{
return "Name:" + Name + ",Age:" + Age + ",Weight:" + Weight + ",Breed:" + Breed + ",Color:" + Color+",Health:"+Health + ",Sound:" + Sound;
}


7. driver.cpp


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "Dog.h"
#include "Cat.h"

using namespace std;

int Dog::NoOfDogCounts = 0;
int Cat::NoOfCatCounts = 0;
int main()
{
ifstream datafile;
ofstream report;
string line;
string temp;
string name;
string atype;
string age;
string weight;
string color;
string sound;
string health;
string breed;

vector<Animal *> animals;
vector<Dog *> dogs;
vector<Cat *> cats;

datafile.open("animalshelter.csv");
if (!datafile)
{
cout << "Error in file readig" << endl;
return 0;
}
getline(datafile, line); // skip header line
getline(datafile, line); // Get the frist line from the file, if any.
while (datafile) { // Continue if the line was sucessfully read.
// Process the line.
atype = line.substr(0, line.find(','));
line = line.erase(0, line.find(',') + 1);
name = line.substr(0, line.find(','));
line = line.erase(0, line.find(',') + 1);
age = line.substr(0, line.find(','));
line = line.erase(0, line.find(',') + 1);
weight = line.substr(0, line.find(','));
line = line.erase(0, line.find(',') + 1);
breed = line.substr(0, line.find(','));
line = line.erase(0, line.find(',') + 1);
color = line.substr(0, line.find(','));
line = line.erase(0, line.find(',') + 1);
health = line.substr(0, line.find(','));
sound = line.erase(0, line.find(',') + 1);
Animal * obj;
if (atype == "cat")
{
obj = new Cat();
}
else if (atype == "dog")
{
obj = new Dog();
}
else
{
obj = new Animal();
}
obj->Age = age;
obj->Breed = breed;
obj->Color = color;
obj->Health = health;
obj->Name = name;
obj->Sound = sound;
obj->Type = atype;
obj->Weight = weight;

animals.push_back(obj);
if (atype == "cat")
{
cats.push_back((Cat *)obj);
}
else if (atype == "dog")
{
dogs.push_back((Dog *)obj);
}
getline(datafile, line);
}
// print report
report.open("report.txt");
if (report)
{
cout << "Total Animals created:" << animals.size() << ", Total cats created:" << cats.size() << ",Total dogs created:" << dogs.size() << endl;
report << "Total Animals created:" << animals.size() << ",Total cats created:" << cats.size() << ",Total dogs created:" << dogs.size() << endl;
cout << "Animals" << endl;
for (int i = 0; i < animals.size();i++)
{
cout << animals[i]->speak() << endl;
report << animals[i]->speak() << endl;
}
cout << "Cats" << endl;
for (int i = 0; i < cats.size();i++)
{
cout << "Name:" + cats[i]->Name + ",Age:" + cats[i]->Age + ",Weight:" + cats[i]->Weight + ",Breed:" +
cats[i]->Breed + ",Color:" + cats[i]->Color + ",Health:" + cats[i]->Health + ",Sound:" + cats[i]->Sound << endl;
report << "Name:" + cats[i]->Name + ",Age:" + cats[i]->Age + ",Weight:" + cats[i]->Weight + ",Breed:" + cats[i]->Breed
+ ",Color:" + cats[i]->Color + ",Health:" + cats[i]->Health + ",Sound:" + cats[i]->Sound << endl;

}
cout << "Dogs" << endl;
for (int i = 0; i < dogs.size();i++)
{
cout << "Name:" + dogs[i]->Name + ",Age:" + dogs[i]->Age + ",Weight:" + dogs[i]->Weight + ",Breed:" +
dogs[i]->Breed + ",Color:" + dogs[i]->Color + ",Health:" + dogs[i]->Health + ",Sound:" + dogs[i]->Sound << endl;
report << "Name:" + dogs[i]->Name + ",Age:" + dogs[i]->Age + ",Weight:" + dogs[i]->Weight + ",Breed:" + dogs[i]->Breed
+ ",Color:" + dogs[i]->Color + ",Health:" + dogs[i]->Health + ",Sound:" + dogs[i]->Sound << endl;
}
report.close();
}

datafile.close();
return 0;
}

report.txt

Total Animals created:4,Total cats created:2,Total dogs created:1
Name:Morries,Age:9,Weight:3,Breed:Mixed,Color:yellow,Health:good,Sound:meow
Name:Mittens,Age:,Weight:1,Breed:Calico,Color:brown and White,Health:good,Sound:mew,mew
Name:chimpy,Age:2,Weight:6,Breed:gs,Color:green,Health:good,Sound:ss
Name:priss,Age:,Weight:3,Breed:herinz,Color:white,Health:good,Sound:bark
Name:Morries,Age:9,Weight:3,Breed:Mixed,Color:yellow,Health:good,Sound:meow
Name:Mittens,Age:,Weight:1,Breed:Calico,Color:brown and White,Health:good,Sound:mew,mew
Name:priss,Age:,Weight:3,Breed:herinz,Color:white,Health:good,Sound:bark

Add a comment
Know the answer?
Add Answer to:
The goal of this homework is to write a small database system for an Animal Shelter....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • EX16_XL_CH10_GRADER_ML2_HW - Animal Shelter 1.5 Project Description: You manage a small animal shelter in Dayton, Ohio....

    EX16_XL_CH10_GRADER_ML2_HW - Animal Shelter 1.5 Project Description: You manage a small animal shelter in Dayton, Ohio. Your assistant created an XML document that lists some of the recent small animals that your shelter took in. In particular, the XML document lists the animal type (such as cat); the age, sex, name, color, and date the animal was brought in; and the date the animal was adopted. You want to manage the data in an Excel worksheet, so you will create...

  • Use python write Thank you so much! pets.txt dog alyson 5.5 cat chester 1.5 cat felice...

    Use python write Thank you so much! pets.txt dog alyson 5.5 cat chester 1.5 cat felice 16 dog jesse 14 cat merlin 5 cat percy 12 cat puppet 18 to_transfer.txt cat merlin 5 cat percy 12 intake.txt bird joe 3 cat sylvester 4.5 the website is https://www2.cs.arizona.edu/classes/cs110/spring17/homework.shtml Welcome to animal shelter management software version 1.0 Type one of the following options adopt a pet adopt intake add more animals to the shelter list. display all adoptable pets quit exit the...

  • IS Chapter 10 homework Help

    EX16_XL_CH10_GRADER_ML2_HW - Animal Shelter 1.6 Project Description:You manage a small animal shelter in Dayton, Ohio. Your assistant created an XML document that lists some of the recent small animals that your shelter took in. In particular, the XML document lists the animal type (such as cat); the age, sex, name, color, and date the animal was brought in; and the date the animal was adopted. You want to manage the data in an Excel worksheet, so you will create a link...

  • Answer using Java Part I: Feeding the Animals (3 points) Filename(s): PetShelter.java Alicia is responsible for...

    Answer using Java Part I: Feeding the Animals (3 points) Filename(s): PetShelter.java Alicia is responsible for buying a week's supply of food and medication for the dogs and cats at a local animal shelter. The food and medication for each dog costs twice as much as those for a cat. Each week the number of cats and dogs changes, as well as how much money she has available to spend on the animals. Write a program that asks the user...

  • PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is...

    PRG/421 Week One Analyze Assignment – Analyzing a Java™Program Containing Abstract and Derived Classes 1.    What is the output of the program as it is written? (Program begins on p. 2) 2. Why would a programmer choose to define a method in an abstract class (such as the Animal constructor method or the getName()method in the code example) vs. defining a method as abstract (such as the makeSound()method in the example)? /********************************************************************** *           Program:          PRG/421 Week 1 Analyze Assignment *           Purpose:         Analyze the coding for...

  • In Exercise 1, displayAnimal uses an Animal reference variable as its parameter. Change your code to...

    In Exercise 1, displayAnimal uses an Animal reference variable as its parameter. Change your code to make the displayAnimal function anim parameter as an object variable, not a reference variable. Run the code and examine the output. What has changed? Polymorphic behavior is not possible when an object is passed by value. Even though printClassName is declared virtual, static binding still takes place because anim is not a reference variable or a pointer. Alternatively we could have used an Animal...

  • **IN JAVAA** Write a program where a user populates a collection of various cats and dogs....

    **IN JAVAA** Write a program where a user populates a collection of various cats and dogs. The user should be able to specify which type they wish to enter, and then are prompted with the pertinent information for every type of pet.    Requirements: The structure of the program should follow this UML class diagram. You may also include helper methods and attributes that are not noted in the class. Additional Notes: The weight for animal should be strictly greater...

  • In Java and make sure the extra credit is in the program aswell

    in Java and make sure the extra credit is in the program aswell Submission Instructions Submit by midnight on the due date and include your submission (a zip file) as an attachment. Assignment Design a class named Animal. An Animal object has the following data members: name (String), age (integer), amount-food-eaten-per-day (integer, representing ounces) and a preferred food (String). Create a toStringO method in the Animal class. Create a no-arg constructor method that sets default values to the 4 data...

  • This is the question about object-oriend programming(java) please show the detail comment and prefect code of...

    This is the question about object-oriend programming(java) please show the detail comment and prefect code of each class, Thank you! This question contain 7 parts(questions) Question 1 Create a class a class Cat with the following UML diagram: (the "-" means private , "+" means public) +-----------------------------------+ | Cat | +-----------------------------------+ | - name: String | | - weight: double | +-----------------------------------+ | + Cat(String name, double weight) | | + getName(): String | | + getWeight(): double | |...

  • The purpose of this project is to give students more exposure to object oriented design and...

    The purpose of this project is to give students more exposure to object oriented design and programming using classes and polymorphism in a realistic application that involves arrays of objects and sorting arrays containing objects A large veterinarian services many pets and their owners. As new pets are added to the population of pets being serviced, their information is entered into a flat text file. Each month the vet requests and updates listing of all pets sorted by their "outstanding...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT