C++ | Classes, more fun than I thought..

/ 25 Sept 2013 /
So for some reason, I'm enjoying classes in C++, surprise, OOP, here I come................... k.



#include <iostream>
#include <string>
#include <sstream>

using namespace std;

class Person{
 public:
  Person(string n, int a, string g) {
   setName(n);
   setAge(a);
   setGender(g);
  }
  void setName(string x) {
   name = x;
  }
  void setAge(int x) {
   age = x;
  }
  void setGender(string x) {
   gender = x;
  }
  string get() {
                        ostringstream os;
                        os << "\nName: " << name 
                  << "\nAge: " << age 
                  << "\nGender: " << gender 
                  << endl;
                        return os.str(); 
 private:
  string name;
  int age;
  string gender;
};


int main() {
 Person samir("John Applessed", 16, "Male");
 cout << samir.get();
 Person justin("Justin Bieber", 15, "Female");
 cout << justin.get();
 return 0;
}
 
Copyright © 2010 M(ath)+me, All rights reserved