Answer to Question #39506 in C++ for Verasak Sitawan

Question #39506
Create C++ structure named Dog with a string field for the Dog’s name. Create a structure named Cat with a string field for the Cat’s name. Write a program that declares one Dog and one Cat, and assign names to them. Write two overloaded functions named speak(). If you pass the Dog to speak(), the speak()function should display the Dog’s name and a description of how dogs speak (for example, “Spot says woof ”). If you pass the Cat to the version of speak()that accepts a Cat parameter, then it should display the Cat’s name and a description of how cats speak (for example, “Tiger says meow”).
Expert's answer
#include <stdio.h> 
#include <stdlib.h>
#include <string.h>

struct Dog /* declare structures*/
char name [256];
struct Cat
char name [256];
/* declare overloaded function*/
void speak(Dog dog)
printf ("%s says woof\n",;
void speak (Cat cat)
printf ("%s says meow\n",;
int main() /* main function*/
Dog dog; /*struct vars*/
Cat cat;
/*assign names to Dog and Cat*/
strcpy (,"Spot");
strcpy (,"Tiger");
/*call of overloaded function*/
speak (dog);
speak (cat);
/*system delay*/
system ("pause");
return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

New on Blog