Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using C++ For this assignment, suppose that a fence is recording entry and exit into the park via a string as the gate swings open

using C++

For this assignment, suppose that a fence is recording entry and exit into the park via a string as the gate swings open and folks walk in or out with their pet. For example,

DP+dp+CP+cp

would indicate that an adult dog and an adult entered the park, then a puppy and child entered the park, then an adult cat and an adult entered the park and finally a kitten and a child entered the park. From this information, note that the character D is being used to represent an adult dog, the character P is being used to represent an adult person, the character d is being used to represent a puppy, the character p is being used to represent a child, the character C is being used to represent an adult cat and the character c is being used to represent a kitten. After processing this string, the park will have a dog and a puppy, a cat and a kitten and two adults and two children left inside. For example,

DP+cp-DP-cp

would indicate that an adult dog and an adult entered the park, then a kitten and a child entered the park, then an adult dog and an adult left the park and then a kitten and a child left the park. After processing this string, the park will not have any dogs, cats or people left inside. For example,

DdPp+ccPP

would indicate that an adult dog and puppy entered the park with an adult and a child followed by two kittens who entered with two adults. After processing this string, the park will have a puppy and an adult dog plus two kittens and three adults and a child left inside.

Precisely, to be a valid animal park string,

- pet(s) must be followed by owner(s) - pet(s) and owner(s) must leave the park together, but only once they have entered - cats and dogs cannot be mixed on a single entry into the park - cats and dogs cannot be mixed on a single exit from the park - the only characters allowed in string are: + - D d C c P p No spaces or any other character besides the 6 characters you see listed to the left. - the string cannot start with +

All of the following are examples of valid animal park strings:

  • CP+dp-CP-dp (no dogs, no cats and no people left in the park after the string is processed)
  • dp+cp (one puppy, one kitten and two children left in the park after the string is processed)
  • CP+dp-CP (one puppy and one child left in the park after the string is processed)
  • ccCP+ddDP (two kittens, one cat, two puppies, one dog and two adults left in the park after the string is processed)
  • dP+dp-ddPp (animals entering separately can leave together, as long as they leave after having entered and dogs and cats are not entering or leaving together)
  • DP+CP+cp+dp-Dp-Cp-dP-cP (any present group of pets and people can leave, once they have entered the park, whether they arrived with that pet or not)
  • CCP-CP (pets and people in any combination may be left befind after the string is fully processed)

All of the following are examples of invalid animal park strings:

  • asdf1ABC000:2-55 (no characters allowed besides c, C, d, D, p, P, + or -)
  • +dp+cp (no leading + allowed)
  • d p + c p (no spaces allowed)
  • -dp+dp (no leading - allowed and a pet cannot leave before it has entered)
  • dp-CP (a pet cannot leave before it has entered)
  • cCcDP (dogs and cats cannot be mixed on a single entry into the park)
  • cP+dP-cdPP (dogs and cats cannot be mixed on a single exit from the park)
  • cpP-P (you cannot leave without having a pet with you)
  • cp+P-cpP (you cannot enter without having a pet with you)
  • dddddPcccccP (on one entry, all the pets need to be grouped together followed by all their owners)

Your task

For this project, you will implement the following four functions, using the exact function names, parameter types, and return types shown in this specification. (The parameter names may be different if you wish).

bool isValidAnimalParkString(string animalparkString)

This function returns true if its parameter is a well-formed animal park string as described above, or false otherwise.

int dogsLeft(string animalparkString)

If the parameter is a well-formed animal park string, this function should return the number of dogs (both puppies and adult dogs) left after the string is fully processed. If the parameter is not a valid animal park string, return -1.

int catsLeft(string animalparkString)

If the parameter is a well-formed animal park string, this function should return the number of cats (both kittens and adult cats) left after the string is fully processed. If the parameter is not a valid animal park string, return -1.

int peopleLeft(string animalparkString)

If the parameter is a well-formed animal park string, this function should return the number of people (both children and adults) left after the string is fully processed. If the parameter is not a valid animal park string, return -1.

These are the only four functions you are required to write. Your solution may use functions in addition to these four if you wish. While we won't test those additional functions separately, using them may help you structure your program more readably. Of course, to test them, you'll want to write a main routine that calls your functions. During the course of developing your solution, you might change that main routine many times. As long as your main routine compiles correctly when you turn in your solution, it doesn't matter what it does, since we will rename it to something harmless and never call it (because we will supply our own main routine to thoroughly test your functions).

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions