944,051 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3959
  • C++ RSS
Jan 21st, 2005
0

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

Expand Post »
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:
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kosham is offline Offline
1 posts
since Jan 2005
Jan 21st, 2005
0

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

>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:
C++ Syntax (Toggle Plain Text)
  1. class test {
  2. int member;
  3. public:
  4. int accessor() { return member; }
  5. void mutator(int value) { member = value; }
  6. };
>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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Can you take a variable from a text file to use...
Next Thread in C++ Forum Timeline: Dynamic Initialization implies Dynamic Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC