I haven't been able to find a video or 'tut' that showcases what I'm trying to accomplish, which is this:
Class must have a constructor.
Class must have 2 class member variables of different data types, accessors, and mutators (getters and setters) to access these variables.
Program must have 3 files, one header file, one .cpp file for that class and one Main.cpp.
So far, I have been able to successfully create a class that meets the requirements for one data type, 'int'. The problem I am running into is, for my second data type, I opted to use a 'string' data type variable. (I realized I could just have easily used a 'char' data type as the other member variable but, I thought this would be more challenging. So far, it apparently has been as I'm stumped cold)
I could really use some help from anyone looking from outside the bubble :) Any pointers would be appreciated, tremendously. As always, thank you for your time and patience with a newbie.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
// HEADER FILE: type.h //
class type
{
private:
string myBreed;
string breed;
public:
type(void);
~type(void);
void getBreed();
void setBreed(string);
}; // end of HEADER FILE: type.h //
// IMPLEMENTATION FILE: type.cpp //
#include <string>
#include "type.h"
using namespace std;
type::type(void)
{
cout << "creating breed" << endl;
}
type::~type(void)
{
}
void type::getBreed()
{
return myBreed;
}
void type::setBreed(string myBreed)
{
breed = myBreed;
} // end ofIMPLEMENTATION FILE: type.cpp //
// MAIN FILE //
#include <iostream>
#include "cat.h"
#include "type.h"
using namespace std;
int main()
{
cat myCat;
myCat.setAge(10);
type mBreed;
myBreed.setBreed("calico");
cout << myCat.getAge() << endl;
cout << myBreed.getBreed() << endl;
system("pause");
return 0;
} // end of MAIN FILE //
|