Skip to content

Instantly share code, notes, and snippets.

@denzuko
Created May 30, 2012 18:57
Show Gist options
  • Select an option

  • Save denzuko/2838287 to your computer and use it in GitHub Desktop.

Select an option

Save denzuko/2838287 to your computer and use it in GitHub Desktop.
CodeTests 0x01
/**
* ar_user.h
* CodeTests 0x01
*
* Copyright (C)2012, Dwight Spencer (Denzuko) <dspencer@denzuko.co.cc>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef _AR_USER_H_
namespace ActiveRecord {
class User {
private:
string first_name,
last_name,
password;
public:
void User();
// attr_writers
void first_name(string);
void last_name(string);
void password(string);
// attr_readers
string full_name();
string first_name();
string last_name();
string password();
}
void User::User() {
this.first_name = "Joe";
this.last_name = "Hacker";
this.password = "crackme";
}
void User::User(string fname, string lname, string pwd) {
this.first_name = fname;
this.last_name = lname;
this.password = pwd;
}
string User::full_name() {
return this.first_name << " " << this.last_name;
}
void User::first_name(first_name) {
// test first_name.len < 127;
this.first_name = first_name;
}
void User::last_name(last_name) {
// test last.len < 127;
this.last_name = last_name;
}
void User::password(password) {
// do some hashing here
this.password = password;
}
}
#endif
/**
* user.cpp
* CodeTests 0x01
*
* Copyright (C)2012, Dwight Spencer (Denzuko) <dspencer@denzuko.co.cc>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <ar_user>
using namespace std;
using namespace ActiveRecord;
void greet(string full_name);
int main(int argc, const char** argv)
{
ActiveRecord::User *user;
try {
user = new User("Dwight","Spencer","secret");
greet(user.full_name);
user.last_name("Seavey");
greet(user.full_name);
} catch(...) {
cerr << "Error Found.." << endl;
}
exit(true);
}
void greet(string full_name)
{
cout << "Welcome, " << full_name << "." << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment