(P.S. It DOES work if everything is in the main .cpp problem but when i split them up into headers it doesn't build) Any help GREATLY appreciated.
Bug Class.cpp
#include <iostream>;
#include <string>;
#include "bug.h";
#include "swimming.h";
#include "flying.h";
#include "crawling.h";
using namespace std;
int main ()
{
string bugName;
Bug myBug;
Flying flyingBug;
Crawling crawlingBug;
Swimming swimmingBug;
int end;
char classChoice;
cout << "Welcome To *Creat Your Own Bug*" << endl;
cout << "You will be selecting different traits throughout\nthe program to create a custom bug of your choice" << endl;
cout << "-------------------------------" << endl << endl;
cout << "To begin, lets give you bug a name: ";
getline(cin, bugName);
myBug.getTraits(bugName);
cout << endl << "Now Lets Further Develop Your Bug" << endl;
cout << "Select which class of Bug you want to develop:" << endl;
cout << "F : Flying\nC : Crawling\nS : Swimming" << endl;
cin >> classChoice;
switch (classChoice)
{
case 'F':
case 'f':
flyingBug.getFlyTraits(bugName, myBug.numEyes, myBug.numLegs, myBug.color);
break;
case 'C':
case 'c':
crawlingBug.getCrawlTraits(bugName, myBug.numEyes, myBug.numLegs, myBug.color);
break;
case 's':
case 'S':
swimmingBug.getSwimTraits(bugName, myBug.numEyes, myBug.numLegs, myBug.color);
break;
}
cin >> end;
return 0;
}
swimming.h
#ifndef SWIMMING_H
#define SWIMMING_H
#include <iostream>;
#include <string>;
class Swimming : public Bug
{
private:
int lifespan;
int breathingTime;
public:
void getSwimTraits(string, int, int, char);
void printTraits(string, int, int, char, int, int);
};
void Swimming::getSwimTraits(string bName, int numEyes, int numLegs, char color)
{
Bug myBug;
cout << endl << "How long (in years) would you like you bug to live? ";
cin >> lifespan;
cout << endl << "How long (in minutes) will your bug be able to breathe underwater? ";
cin >> breathingTime;
cout << endl;
cout << "-------------------------------" << endl;
printTraits(bName, numEyes, numLegs, color, lifespan, breathingTime);
}
void Swimming::printTraits(string bName, int numEyes, int numLegs, char color, int lifespan, int flyingTime)
{
Bug myBug;
myBug.printTraits(bName, numEyes, numLegs, color);
cout << "Life Span: " << lifespan << " Years" << endl;
cout << "Flying Time: " << breathingTime << " Minutes" << endl;
}
#endif
crawling.h
#ifndef CRAWLING_H
#define CRAWLING_H
#include <iostream>;
#include <string>;
class Crawling : public Bug
{
private:
int lifespan;
int websize;
public:
void getCrawlTraits(string, int, int, char);
void printTraits(string, int, int, char, int, int);
};
void Crawling::getCrawlTraits(string bName, int numEyes, int numLegs, char color)
{
Bug myBug;
cout << endl << "How long (in years) would you like you bug to live? ";
cin >> lifespan;
cout << endl << "How big (inches) of a web would you bug be able to make? ";
cin >> websize;
cout << endl;
cout << "-------------------------------" << endl;
printTraits(bName, numEyes, numLegs, color, lifespan, websize);
}
void Crawling::printTraits(string bName, int numEyes, int numLegs, char color, int lifespan, int flyingTime)
{
Bug myBug;
myBug.printTraits(bName, numEyes, numLegs, color);
cout << "Life Span: " << lifespan << " Years" << endl;
cout << "Web Size: " << websize << " Inches Long" << endl;
}
#endif
flying.h
#ifndef FLYING_H
#define FLYING_H
#include <iostream>;
#include <string>;
using namespace std;
class Flying : public Bug
{
private:
int lifespan;
int flyingTime;
public:
void getFlyTraits(string, int, int, char);
void printTraits(string, int, int, char, int, int);
};
void Flying::getFlyTraits(string bName, int numEyes, int numLegs, char color)
{
Bug myBug;
cout << endl << "How long (in years) would you like you bug to live? ";
cin >> lifespan;
cout << endl << "How long (in minutes) will your bug be able to Fly? ";
cin >> flyingTime;
cout << endl;
cout << "-------------------------------" << endl;
printTraits(bName, numEyes, numLegs, color, lifespan, flyingTime);
}
void Flying::printTraits(string bName, int numEyes, int numLegs, char color, int lifespan, int flyingTime)
{
Bug myBug;
myBug.printTraits(bName, numEyes, numLegs, color);
cout << "Life Span: " << lifespan << " Years" << endl;
cout << "Flying Time: " << flyingTime << " Minutes" << endl;
}
#endif
bug.h
#ifndef BUG_H
#define BUG_H
#include <iostream>;
#include <string>;
class Bug
{
public:
string bName;
int numEyes;
int numLegs;
char color;
int getTraits(string);
void printTraits(string, int, int, char);
Bug();
Bug(string, int, int, char);
};
Bug::Bug()
{
bName;
numEyes = 0;
numLegs = 0;
color = '*';
}
Bug::Bug(string, int nE, int nL, char col)
{
bName;
numEyes = nE;
numLegs = nL;
color = col;
}
int Bug::getTraits(string bName)
{
cout << endl << "Now, your bug gets a choice of a number of\nEyes, Legs, and A color of your choice\n";
cout << "How many Eyes would you like your Bug to have(at Least 2)? ";
cin >> numEyes;
if (numEyes < 2)
{
numEyes = 2;
}
else {
numEyes = numEyes;
}
cout << endl << "How many legs would you like you bug to have(at Least 2)?" ;
cin >> numLegs;
if (numLegs < 2)
{
numLegs = 2;
}
else {
numLegs = numLegs;
}
cout << endl << "Lastly, what color would you like your bug to be: " << endl;
cout << "w : White\nb : Blue\ng : Green\ny : Yellow\n";
cin >> color;
cout << endl;
cout << "-------------------------------" << endl;
printTraits(bName, numEyes, numLegs, color);
return numEyes, numLegs;
}
void Bug::printTraits(string bName, int numEyes, int numLegs, char color)
{
cout << "Name: " << bName << endl;
cout << "Number of Eyes: " << numEyes << endl;
cout << "Number of Legs: " << numLegs << endl;
switch (color)
{
case 'W':
case 'w':
cout << "Color : White" << endl;
break;
case 'B':
case 'b':
cout << "Color : Blue" << endl;
break;
case 'G':
case 'g':
cout << "Color : Green" << endl;
break;
case 'Y':
case 'y':
cout << "Color : Yellow" << endl;
break;
}
}
#endif

New Topic/Question
Reply




MultiQuote





|