Pointers to class fields

Posted by newbie_cpp on Stack Overflow See other posts from Stack Overflow or by newbie_cpp
Published on 2010-05-25T10:14:19Z Indexed on 2010/05/25 10:31 UTC
Read the original article Hit count: 237

Filed under:
|
|

My task is as follows :

Using pointers to class fields, create menu allowing selection of ice, that Person can buy in Ice shop. Buyer will be charged with waffel and ice costs.

Selection of ice and charging buyers account must be shown in program.

Here's my Person class :

#include <iostream>
using namespace std;

class Iceshop {
    const double waffel_price = 1;
public:

}
class Person {
    static int NUMBER;   
    char* name;
    int age;
    const int number;
    double plus, minus;
public:

    class Account {
        int number;
        double resources;

        public:      
            Account(int number, double resources)
                : number(number), resources(resources)
            {}       
    }   

    Person(const char* n, int age)
        : name(strcpy(new char[strlen(n)+1],n)),
            number(++NUMBER), plus(0), minus(0), age(age)
    {}


    Person::~Person(){
        cout << "Destroying resources" << endl;
        delete [] name;
    }   

    friend void show(Person &p);

   int* take_age(){
       return &age;
   }

   char* take_name(){
         return name;      
   }

    void init(char* n, int a) {
        name = n;
        age = a;
    }

    Person& remittance(double d)  { plus += d; return *this; }
    Person& paycheck(double d) { minus += d; return *this; } 
    Account* getAccount();

};

int Person::

Person::Account* Person::getAccount() {
    return new Account(number, plus - minus);
}


void Person::Account::remittance(double d){
    resources = resources + d;
}

void Person::Account::paycheck(double d){
    resources = resources - d;    
}

void show(Person *p){
    cout << "Name: " << p->take_name() << "," << "age: " << p->take_age() << endl; 
}

int main(void) {
    Person *p = new Person;  
    p->init("Mary", 25);

    show(p);

    p->remittance(100);

    system("PAUSE");
    return 0;
}

How to start this task ? Where and in what form should I store menu options ?

© Stack Overflow or respective owner

Related posts about c++

Related posts about homework