All programming assignments should include the name or names

All programming assignments should include the name, or names, of the

students. This information should be placed in the introductory comments

section. The introductory comments should also contain the purpose of the

program. Clear, concise, commenting is an important skill to develop and

will be part of the grade for each program. Programs should be submitted

via Blackboard as “.cpp” source programs. Each member of a team should

submit a copy of the program.

The purpose of PSA 7 is practice our programming style and techniques on

a fairly simple real world example of an application. PSA7.cpp is a program

that analyzes various aspects of the clients at an animal shelter. Your task

is to fill in the three routines that provide the necessary information to the

main routine. You may not alter the code in main. You must use the

interfaces as defined.

The first two routines are almost trivial and the only thing that is special

about one of them is the need to use a persistent variable.

The third one, shotRecord is a bit challenging. You must determine if each

animal has had the correct shots. These are for Parvovirus, Rabies, and

Bordetella. One confusion factor here is that they could have also received

a shot for Leptospirosis; that is not a required shot. Further complicating

things is the fact that the only thing that is important is that they received

the shot; they may have received their inoculations in differing orders.

Programme it using \"CODE::BLOCK and also use the main function below:

#include <iostream>
#include <stdlib.h>
#include <cstddef>
#include <string>


using namespace std;

#define numberSpecies 4
#define numberShots 3

enum species {dog, cat, bird, rabbit};
enum shots {Parvovirus, Rabies, Bordetella, Leptospirosis};

string outString;

struct animal
{
    string name;
    unsigned int stay;
    enum species animalType;
    enum shots status[numberShots];
};

int displayAnimal(struct animal *animal)
{
    cout << \"Name:\\t\\t\" << animal->name << endl;

    cout << \"Species:\\t\";
    switch (animal->animalType)
    {
        case dog:
        cout << \"Dog\";
        break;

        case cat:
        cout << \"Cat\";
        break;

        case bird:
        cout << \"Bird\";
        break;

        case rabbit:
        cout << \"Rabbit\";
        break;

        default:
        cout << \"Unknown\";
    }
    cout << endl;

    cout << \"Length of stay: \" << animal->stay << endl << endl;

    return 0;
}

double averageStay(struct animal *animal)
{

    // Your code goes here.
    // Hint you will need to use a type we have not used before.
}

int countPopulation(struct animal census[], enum species kindAnimal, unsigned int k)
{
    unsigned int j, animalCount;

    // Your code goes here.

    return animalCount;
}

bool shotRecord(struct animal *animal)
{
    unsigned int temp, m, shot;

    temp = 0;

    // Your code goes here.
    // This is the trickiest one!
    return (temp == 3) ? true: false;
}

int main()
{
    #define censusSize 6

    struct animal census[censusSize];

    census[0].animalType = dog;
    census[0].name = \"Fred\";
    census[0].stay = 13;
    census[0].status[0] = Rabies;
    census[0].status[1] = Bordetella;
    census[0].status[2] = Parvovirus;

    census[1].animalType = cat;
    census[1].name = \"Felix\";
    census[1].stay = 25;
    census[1].status[0] = Rabies;
    census[1].status[1] = Bordetella;
    census[1].status[2] = Parvovirus;

    census[2].animalType = dog;
    census[2].name = \"Fido\";
    census[2].stay = 18;
    census[2].status[0] = Bordetella;
    census[2].status[1] = Parvovirus;
    census[2].status[2] = Leptospirosis;

    census[3].animalType = cat;
    census[3].name = \"Garfield\";
    census[3].stay = 13;
    census[3].status[0] = Rabies;
    census[3].status[1] = Parvovirus;

    census[4].animalType = rabbit;
    census[4].name = \"Peter\";
    census[4].stay = 18;
    census[4].status[0] = Rabies;
    census[4].status[1] = Parvovirus;
    census[4].status[2] = Bordetella;

    census[5].animalType = bird;
    census[5].name = \"Tweety\";
    census[5].stay = 25;
    census[5].status[0] = Rabies;
    census[5].status[1] = Bordetella;
    census[5].status[2] = Parvovirus;

    for (int m = 0; m < censusSize; m++)
       displayAnimal(&census[m]);

    double sum;
    sum = 0;
    for (int m = 0; m < censusSize; m++)
        sum = averageStay(&census[m]);

    cout << \"The average stay is \" << sum << \" days.\" << endl;

    int population[numberSpecies];
    population[dog] = countPopulation(census, dog, censusSize);
    population[cat] = countPopulation(census, cat, censusSize);
    population[bird] = countPopulation(census, bird, censusSize);
    population[rabbit] = countPopulation(census, rabbit, censusSize);

    cout << \"The number of dogs is \" << population[dog] << \".\" << endl;
    cout << \"The number of cats is \" << population[cat] << \".\" << endl;
    cout << \"The number of birds is \" << population[bird] << \".\" << endl;
    cout << \"The number of rabbits is \" << population[rabbit] << \".\" << endl;

    cout << endl;
    string temp;
    for (int m = 0; m < censusSize; m++)
    {
        if (shotRecord(&census[m]))
        {
            temp = census[m].name;
            cout << temp << \" has all of his/her required shots.\" << endl;
        }

    }

    cout << endl;

    system(\"pause\");
    return 0;
}

Solution

#include <iostream>
#include <stdlib.h>
#include <cstddef>
#include <string>


using namespace std;

#define numberSpecies 4
#define numberShots 3

enum species {dog, cat, bird, rabbit};
enum shots {Parvovirus, Rabies, Bordetella, Leptospirosis};

string outString;

struct animal
{
    string name;
    unsigned int stay;
    enum species animalType;
    enum shots status[numberShots];
};

int displayAnimal(struct animal *animal)
{
    cout << \"Name:\\t\\t\" << animal->name << endl;

    cout << \"Species:\\t\";
    switch (animal->animalType)
    {
        case dog:
        cout << \"Dog\";
        break;

        case cat:
        cout << \"Cat\";
        break;

        case bird:
        cout << \"Bird\";
        break;

        case rabbit:
        cout << \"Rabbit\";
        break;

        default:
        cout << \"Unknown\";
    }
    cout << endl;

    cout << \"Length of stay: \" << animal->stay << endl << endl;

    return 0;
}

double averageStay(struct animal *animal)
{

    // Your code goes here.
    // Hint you will need to use a type we have not used before.
}

int countPopulation(struct animal census[], enum species kindAnimal, unsigned int k)
{
    unsigned int j, animalCount;

    // Your code goes here.

    return animalCount;
}

bool shotRecord(struct animal *animal)
{
    unsigned int temp, m, shot;

    temp = 0;

    // Your code goes here.
    // This is the trickiest one!
    return (temp == 3) ? true: false;
}

int main()
{
    #define censusSize 6

    struct animal census[censusSize];

    census[0].animalType = dog;
    census[0].name = \"Fred\";
    census[0].stay = 13;
    census[0].status[0] = Rabies;
    census[0].status[1] = Bordetella;
    census[0].status[2] = Parvovirus;

    census[1].animalType = cat;
    census[1].name = \"Felix\";
    census[1].stay = 25;
    census[1].status[0] = Rabies;
    census[1].status[1] = Bordetella;
    census[1].status[2] = Parvovirus;

    census[2].animalType = dog;
    census[2].name = \"Fido\";
    census[2].stay = 18;
    census[2].status[0] = Bordetella;
    census[2].status[1] = Parvovirus;
    census[2].status[2] = Leptospirosis;

    census[3].animalType = cat;
    census[3].name = \"Garfield\";
    census[3].stay = 13;
    census[3].status[0] = Rabies;
    census[3].status[1] = Parvovirus;

    census[4].animalType = rabbit;
    census[4].name = \"Peter\";
    census[4].stay = 18;
    census[4].status[0] = Rabies;
    census[4].status[1] = Parvovirus;
    census[4].status[2] = Bordetella;

    census[5].animalType = bird;
    census[5].name = \"Tweety\";
    census[5].stay = 25;
    census[5].status[0] = Rabies;
    census[5].status[1] = Bordetella;
    census[5].status[2] = Parvovirus;

    for (int m = 0; m < censusSize; m++)
       displayAnimal(&census[m]);

    double sum;
    sum = 0;
    for (int m = 0; m < censusSize; m++)
        sum = averageStay(&census[m]);

    cout << \"The average stay is \" << sum << \" days.\" << endl;

    int population[numberSpecies];
    population[dog] = countPopulation(census, dog, censusSize);
    population[cat] = countPopulation(census, cat, censusSize);
    population[bird] = countPopulation(census, bird, censusSize);
    population[rabbit] = countPopulation(census, rabbit, censusSize);

    cout << \"The number of dogs is \" << population[dog] << \".\" << endl;
    cout << \"The number of cats is \" << population[cat] << \".\" << endl;
    cout << \"The number of birds is \" << population[bird] << \".\" << endl;
    cout << \"The number of rabbits is \" << population[rabbit] << \".\" << endl;

    cout << endl;
    string temp;
    for (int m = 0; m < censusSize; m++)
    {
        if (shotRecord(&census[m]))
        {
            temp = census[m].name;
            cout << temp << \" has all of his/her required shots.\" << endl;
        }

    }

    cout << endl;

    system(\"pause\");
    return 0;
}

All programming assignments should include the name, or names, of the students. This information should be placed in the introductory comments section. The intr
All programming assignments should include the name, or names, of the students. This information should be placed in the introductory comments section. The intr
All programming assignments should include the name, or names, of the students. This information should be placed in the introductory comments section. The intr
All programming assignments should include the name, or names, of the students. This information should be placed in the introductory comments section. The intr
All programming assignments should include the name, or names, of the students. This information should be placed in the introductory comments section. The intr
All programming assignments should include the name, or names, of the students. This information should be placed in the introductory comments section. The intr
All programming assignments should include the name, or names, of the students. This information should be placed in the introductory comments section. The intr

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site