01: // Person.mpp
02: /*
03: A test of the C++ preprocessor
04: */
05:
06: #include <iostream>
07: #include <string>
08: import Math;
09:
10: using namespace std; using std::cout;
11:
12: namespace BussinessLogic {
13:
14: class Person {
15: public:
16: static const std::string CanonicalName = "John Doe";
17: private:
18: std::string name;
19: unsigned int age;
20: std::string email;
21: double salary;
22: public:
23: explicit Person(const std::string &n, unsigned int a, const std::string &e)
24: : name(n), age(a), email(e)
25: {}
26: Person(const std::string &n) : name( n )
27: {}
28:
29:
30: inline int getAge() const
31: { return age; }
32: void setAge(int a)
33: { age = a; }
34:
35: inline const std::string &getEmail() const
36: { return email; }
37: void setEmail(const std::string &e)
38: { email = e; }
39:
40: inline const std::string &getName() const
41: { return name; }
42: void setName(const std::string &n)
43: {
44: if ( !n.empty() ) {
45: name = n;
46: }
47: }
48: inline void putSalary(double x) {
49: salary = x;
50: }
51:
52: inline double getSalary() const {
53: return salary;
54: }
55:
56: inline double getNetSalary() const {
57: return Math::removePercentage( salary, 0.20 );
58: }
59: std::string toString() const { return ( getName() + ": " + getEmail() ); }
60: };
61:
62: }
63:
64: int main()
65: {
66: BussinessLogic::Person p1( BussinessLogic::Person::CanonicalName, 0, "" );
67: BussinessLogic::Person p2( "Baltasar", 34, "jbgarcia@uvigo.es" );
68:
69: p2.putSalary( 5500 );
70:
71: cout << "\nCp3 test\n" << endl;
72: cout << p1.toString() << endl;
73: cout << p2.toString() << endl;
74: cout << "Salary: " << p2.getSalary() ;
75: cout << '(' << p2.getNetSalary() << ')' << endl;
76: cout << endl;
77: }