Katya S.

asked • 07/04/21

c++, logical operators

Write a tiny library and submit it in files AboutDog.h and AboutDog.cpp. This library has the only function:

void AboutDog(const std::string & dogName, unsigned int description)

The function AboutDog outputs on the screen the following text:


This dog is called *dogName*. It is *list of dog features from description*.

description encodes the dogs properties the following way:

  1.  set bit 0 means the dog is big
  2.  set bit 1 means the dog is hairy
  3.  set bit 2 means the dog is brown
  4.  set bit 3 means the dog is smart

In the header file, define MACROS: DOG_BIG, DOG_HAIRY, DOG_BROWN, DOG_SMART.

I should be able to call the function like this:

AboutDog( "Spike", DOG_BROWN | DOG_SMART | DOG_HAIRY );

The above call should produce the output like this:

This dog is called Spike. It is hairy brown smart.

The order of features doesn't matter. Punctuation doesn't matter too. If description==0 skip the second sentence.


/****************************

Does anything else go into AboutDog.h?


#define DOG_BIG (0x1)

#define DOG_HAIRY (0x2)

#define DOG_BROWN (0x4)

#define DOG_SMART (0x8)


In AboutDog.cpp, how to output dog features?


2 Answers By Expert Tutors

By:

Naeem F. answered • 07/04/21

Tutor
5.0 (51)

Professional C++ Software Engineer with 30+ years of experience

Patrick B. answered • 07/04/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.