Skip to content

Instantly share code, notes, and snippets.

@davestevens
Created October 22, 2011 10:40
Show Gist options
  • Save davestevens/1305859 to your computer and use it in GitHub Desktop.
Save davestevens/1305859 to your computer and use it in GitHub Desktop.
no description
#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