| | |
Need to know hwo to go about this (classes/accessor functions)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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:
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:
>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:
>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.
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)
class test { int member; public: int accessor() { return member; } void mutator(int value) { member = value; } };
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.
![]() |
Similar Threads
- Game: Robots (Class, Constructors, etc.) (C++)
- Classes vs Functions (Python)
- Help with Classes (I don't know where to go with this...) (C++)
- WHY IS THIS NOT WORKIGN!? INCLUDING HEADER FILES AND CPP FILES --hello everyone! (C++)
- overloading << not working (C++)
- Difference between classes and structs? (C++)
- invoking class functions from user input (C++)
- Problem with program involving classes (C++)
Other Threads in the C++ Forum
- Previous Thread: Can you take a variable from a text file to use...
- Next Thread: Dynamic Initialization implies Dynamic Help
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






