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

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2005
Posts: 1
Reputation: kosham is an unknown quantity at this point 
Solved Threads: 0
kosham's Avatar
kosham kosham is offline Offline
Newbie Poster

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

 
0
  #1
Jan 21st, 2005
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:
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,783
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 745
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
0
  #2
Jan 21st, 2005
>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:
  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.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC