Yasmeen Y.

asked • 07/02/21

C++ please check if it’s correct or not

The assignment is:

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.


answer:

AboutDog.h:

#include <iostream>


#define DOG_BIG 0

#define DOG_HAIRY 1

#define DOG_BROWN 2

#define DOG_SMART 3




AboutDog.cpp:

#include "AboutDog.h"

using namespace std;


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

cout<<"This dog is called "<<dogName<<". ";

if(description != 0) {

cout<<"It is";

if(description & DOG_BIG) {

cout<<" big";

}

if(description & DOG_HAIRY) {

cout<<" hairy";

}

if(description & DOG_BROWN) {

cout<<" brown";

}

if(description & DOG_SMART) {

cout<<" smart";

}

cout<<"."<<endl;

}

}

1 Expert Answer

By:

Patrick B. answered • 07/02/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Yasmeen Y.

Do I need to put main ?
Report

07/04/21

Patrick B.

the program will not link without it. Also, if you want to test it, you must call it from main()
Report

07/04/21

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.