Help

I trying to understand polymorphism. Need some assistance in having the same character output to a window using visual studio 2012. So I would create a program of which if I entered in cat in the program when it is run, it will display something like that is an animal. If I enter in dog, it would display that is an animal. So it would run slightly different code but output the same result. Any assistance is appreciated. Thanks.

I can generate the generic programs input output, hello world etc. Although not sure how to make the code call to another say COM file to run in the code.

Thanks again.
Would I be right in saying that you have been asked to write a program with an abstract base class and concrete classes for various different types of species? So, you are trying to ask how to implement such a program??
Right, so the idea is I have a base class, which will run a simple output to the window similar to a hello world simple code. The various species, but the species would run off of say a COM file. Correct. not sure how to create off of a COM input to trigger the same result in the output. Also not sure if I can do this within visual studio or if I need additional tools.

Thanks a bunch for any assistance,
What is the exact, word for word, assignment you have been given?
Here is what I have so far, but I need to tweak it so there is an input on the screen when I debut it. If the user inputs Comone there would only be one output "something funny, if the user input Comtwo the output would be "something funny", I started with if statements, but this each one did not incorporate separately like separate COM files. The way I have it they there are three messages of which pop "something funny". So I just do not know how to take the user input of either comone, cometwo or comethree and no matter what is input it would link to that part of header file and output "something funny" Thanks so much I appreciate the assistance.

main .cpp
#include <iostream>
#include "Comfile.h"
#include "Comone.h"
#include "Comtwo.h"
#include "Comthree.h"

const int cNumcom = 3;
int main()
{
Comfile* pFunny[cNumcom] = { new Comone, new Comtwo, new
Comthree };
for (int i = 0 ; i < cNumcom ; ++i)
{
std::cout << pFunny[i]->Sendsomthingfunny() << std::endl;
delete pFunny[i];
}
system ("pause");
return 0;
}



#include <string>
#ifndef COMFILE_H_
#define COMFILE_H_

class Comfile {
public:
Comfile() {};
virtual ~Comfile() {};
virtual std::string Sendsomthingfunny()
{
std::string str("Somethingfunny");
return str;
}
};
#endif /* COMFILE_H_ */


#include "Comfile.h"
#ifndef COMONE_H_
#define COMONE_H_

class Comone : public Comfile {
public:
Comone () {};
virtual ~Comone() {};
std::string Sendsomthingfunny()
{
std::string str("Somethingfunny");
return str;
}
};
#endif /* COMONE_H_*/




#include "Comfile.h"
#ifndef COMTWO_H_
#define COMTWO_H_

class Comtwo : public Comfile {
public:
Comtwo() {};
virtual ~Comthree() {};
std::string Sendsomthingfunny()
{
std::string str("Somethingfunny");
return str;
}
};
#endif /* COMTWO_H_ */



#include "Comfile.h"
#ifndef COMTHREE_H_
#define COMTHREE_H_

class Comthree : public Comfile {
public:
Comthree() {};
virtual ~Comthree() {};
std::string Sendsomthingfunny()
{
std::string str("Somethingfunny");
return str;
}
};
#endif /* COMTHREE_H_ */


Topic archived. No new replies allowed.