954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need to know hwo to go about this (classes/accessor functions)

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 biilding 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:

kosham
Newbie Poster
1 post since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

>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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You