Skip to content

Instantly share code, notes, and snippets.

@peaceman
Created April 7, 2011 05:58
Show Gist options
  • Save peaceman/907121 to your computer and use it in GitHub Desktop.
Save peaceman/907121 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <conio.h>
class ArbeitsplatzPC {
private:
std::string macAdresse;
char netz;
bool checknetz(char netz);
bool checkMac(std::string macAddress);
bool checkHex(char magic);
public:
ArbeitsplatzPC(std::string macAddress, char netz);
bool setnetz(char netz);
char getnetz();
bool setMAC(std::string macAddress);
std::string getMAC();
};
ArbeitsplatzPC::ArbeitsplatzPC(std::string macAddress, char netz) {
this->setMAC(macAddress);
this->setnetz(netz);
}
bool ArbeitsplatzPC::checknetz(char netz) {
return true;
}
bool ArbeitsplatzPC::checkMac(std::string macAddress) {
if (macAddress.length() != 17) {
return false;
}
for (int i = 1; i <= 17; i++) {
if (i % 3 == 0) {
if (macAddress[i - 1] != '-') {
return false;
}
} else {
bool result = this->checkHex(macAddress[i - 1]);
if (result == false) {
return false;
}
}
}
return true;
}
bool ArbeitsplatzPC::checkHex(char magic) {
switch (magic) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case 'a':
case 'A':
case 'b':
case 'B':
case 'c':
case 'C':
case 'd':
case 'D':
case 'e':
case 'E':
case 'f':
case 'F':
return true;
break;
default:
return false;
}
}
bool ArbeitsplatzPC::setnetz(char netz) {
this->netz = netz;
return true;
}
char ArbeitsplatzPC::getnetz() {
return this->netz;
}
bool ArbeitsplatzPC::setMAC(std::string macAddress) {
bool result = this->checkMac(macAddress);
if (result == true) {
this->macAdresse = macAddress;
}
return result;
}
std::string ArbeitsplatzPC::getMAC() {
return this->macAdresse;
}
int main() {
ArbeitsplatzPC pc1("11-11-11-11-11-11", 'C');
std::cout << "pc1.getMAC() " << pc1.getMAC() << std::endl;
std::cout << "pc1.getnetz() " << pc1.getnetz() << std::endl;
std::cout << "pc1.setMAC(\"sdfasdf\") " << pc1.setMAC("sdfasdf") << std::endl;
getch();
return 0;
}
@peaceman
Copy link
Author

fuuuuuuuuuuuuuuuuuuuuuuuuu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment