Created
October 22, 2011 10:40
-
-
Save davestevens/1305859 to your computer and use it in GitHub Desktop.
no description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stdlib.h> | |
using namespace::std; | |
class testClass { | |
public: | |
string myString1; | |
char *myString2; | |
unsigned myInt; | |
testClass(); | |
~testClass(); | |
void setStrings(string, char *); | |
void setInput(unsigned); | |
void testInput(void); | |
protected: | |
private: | |
}; | |
testClass::testClass() { | |
myString2 = (char *)malloc(sizeof(char) * 255); | |
if(myString2 == NULL) { | |
cout << "error allocating memory: myString2" << endl; | |
exit(-1); | |
} | |
return; | |
} | |
testClass::~testClass() { | |
free(myString2); | |
return; | |
} | |
void testClass::setStrings(string string1, char *string2) { | |
myString1 = string1; | |
strcpy(myString2, (char *)string2); | |
return; | |
} | |
void testClass::setInput(unsigned input) { | |
myInt = input; | |
return; | |
} | |
void testClass::testInput(void) { | |
if((myInt > 4) && (myInt < 6)) { | |
cout << myString1 << endl; | |
} | |
else { | |
cout << myString2 << endl; | |
} | |
return; | |
} | |
int main(void) { | |
testClass tC; | |
unsigned i; | |
tC.setStrings("this is string 1", "this is string 2"); | |
for(i=0;i<10;i++) { | |
tC.setInput(i); | |
tC.testInput(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment