Hello i need help creting a class using an accessor funciton and a mutator function.

Problem objective:

i have to desing a general C++ class that will be used to represent "Building" objects, and meets the following criteria:

  1. each building object has a number of rooms(integer value)
  2. each Building object has a number of floors(integer value)
  3. each building object has a floor area(integer value)
  4. each building aobject has a heating type (*char value). the type of heating used is either electric(value=e) or oil(value =o).
  • all data members i include must be private, must be accessed oly by a public member function and each datamember must have an accessor function to retreive the current value and a mutator function to assign a new value.

  • ckass definition has to include botha constructor (initial values of integer data members should be zero and character values should = e) and a destructor function. the destructor shold display a message to the screen that the object has been destroyed. also an overloaded constructor must be created for th 'building' object.

And here is what i have done sofar.. I am a newbie, and at this point i feel lost.. i am learning from the deital and deital how to learn C++, and my instructors arent much help, so at this point i dont know what to do. I had 2 weeks to get familier with C and learn C++. so im stressed

// declaration of building class


//prevent multiple inclusions of header file
#ifndef BUILDING_H
#define BUILDING_H

//building data type definition
class Building 
{
public:
    building(int =0, int=0, int=0, char=e);   //Constructor
    ~building();      

private:
    int rooms;
    int floorNumber;
    int floorArea;
    char heatingType;

can anyone help.. pleae.. i dont know how to implement accessor and mutator functions. and how to overload a constructor.

thankyou :mrgreen:

>i dont know how to implement accessor and mutator functions.
Accessor and mutator are just fancy terms for a function that gives you the value of a member and a function that sets the value of a member:

class test {
  int member;
public:
  int accessor() { return member; }
  void mutator(int value) { member = value; }
};

>and how to overload a constructor.
Just write another one that doesn't take the same type and number of arguments as any of the others.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.