Schedule‎ > ‎

person.cpp

/**
    CS-11 Asn 9, person.cpp
    Purpose: Store info about a person

    @author Sharon Strelitz
    @version 1.0  02/20/2018
 */
#include <iostream>
#include <iomanip>
using namespace std;
const int NAME_WIDTH = 18;
const int AGE_WIDTH = 6;
const int INCOME_WIDTH = 11;

class Person {
  public:
    Person();  //default Constructor
    Person(string newName, int newAge, double newIncome);
    string getName() const;
    int getAge() const;
    double getIncome() const;
    void setName(string newName);
    void setAge(int newAge);
    void setIncome(double newIncome);
    void print const();
  private:
    string name;
    int age; 
    double income;
};

Person::Person()  {
  name = "";
  age = 0;
  income = 0;
}

Person::Person(string newName, int newAge, double newIncome){
  name = newName;
  age = newAge;
  income = newIncome;
}
 
string Person::getName() const {
        return name;
}

int Person::getAge() const {
        return age;
}
double Person::getIncome() const {
        return income;
}
void Person::setName(string newName) {
        name = newName;
}

void Person::setAge(int newAge) {
        age = newAge;
}
void Person::setIncome(double newIncome) {
        income = newIncome;
}
/**
    print:  print the information about a person

    @param  no input parameters
    @return void
*/
void Person::print() const {
    cout << fixed << setprecision(2);
    cout << setw(NAME_WIDTH) << left << getName();
    cout << setw(AGE_WIDTH) << right << getAge();
    cout << setw(INCOME_WIDTH) << right << getIncome() << endl;  
}

int main() {
  Person person1;
  person1.setName("Jose Engineer");
  person1.setAge(30);
  person1.setIncome(100000);
  Person person2("Maria Engineer", 22, 100000);
  Person person3("John Driver", 30, 12000);
  cout << setw(NAME_WIDTH) << left << "Name";
  cout << setw(AGE_WIDTH) << right << "Age";
  cout << setw(INCOME_WIDTH) << right << "Income" << endl;  
  person1.print();
  person2.print();
  person3.print();

}
Comments