home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2697
Discussions: 188,383, Posts: 2,243,488, Members: 232,612
Old March 31st, 2003, 07:07 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Mar 2003
Location: Florida USA
Posts: 18
C++ Declaring A Class

Hi Everyone

I am trying to write code for class BarrierType, using all eight listed methods.

I know I have to start with: (well I think I do)

void BarrierType: :SetCode(AnsiString NewCode)

but for the life of me I do not know where to start. I wondered if anyone could get me started, please don't say read a book, because I have until my eyes are seeing double. So as usual this is my last port of call. Please Help, I am not taking the p**s or trying to. I have been looking at it for days and still the light has not come on!!! How do I get the ball rolling.


Any help will be appreciated.

Morphios


Last edited by Morphios : July 22nd, 2003 at 06:34 PM.
Morphios is offline   Reply With Quote
Old March 31st, 2003, 08:16 PM     #2 (permalink)
Junior Member
 
Join Date: Mar 2003
Location: Florida USA
Posts: 18
Can I write the functions for this code like this, or have I completly gone in the wrong direction. I am having serious problems writing these functions.....Help!!


Code:
void BarrierType::SetCode(AnsiString NewCode)
{
    Code = NewCode;
    if NewCode == '4';
        NewCode = false;
    else
        NewCode = true;
}

Once again any help appreciated.

Morphios

Morphios is offline   Reply With Quote
Old March 31st, 2003, 11:48 PM     #3 (permalink)
Member
 
Join Date: Feb 2002
Posts: 161
Code:
void BarrierType::SetCode(AnsiString NewCode)
{
    Code = NewCode;
    if NewCode == '4';
        NewCode = false;
    else
        NewCode = true;
}
Your if statement is incorrect. You need to use parentheses ( ) , and you need to remove the semicolon at the end. Also, the NewCode == '4' comparison is most likely wrong, although it's impossible to tell for sure without seing the definition of the AnsiString class. Your code should probably look something like this:
Code:
void BarrierType::SetCode(AnsiString NewCode)
{
    Code = NewCode;
    if(NewCode == "4")
        NewCode = false;
    else
        NewCode = true;
}
Hopefully that should give you some hints as to how to write the functions.

Martee is offline   Reply With Quote
Old April 1st, 2003, 12:14 AM     #4 (permalink)
ILC
Senior Member
 
ILC's Avatar
 
Join Date: Oct 2001
Location: Eastern Shore
Posts: 701
Quite a bit goes into writing classes. You have been pretty vague…could you please specify a little better what exactly it is that you need help with?

I assume that the header file was given to you? Furthermore, I assume that you must define all of the functions within a set of given parameters? Do you know that you are going to need a class.h file and a class.cpp file?

Alright, here is a quickie (let us know if you need further help or a specific question):

Using the syntax you provided for us as the .h file, here would be the supplemental .cpp file:

Code:
#include “BarrierType.h”

BarrierType::BarrierType(void)
{
//insert function code here
//initialization function
}

void BarrierType::BarrierOpen(void)
{
	//insert code
}

void BarrierType::BarrierClosed(void)
{
	//insert code
}


void BarrierType::SwitchMode(void)
{
	//insert code
}

bool BarrierType::Open(void)
{
	//insert code
}

char BarrierType::GetMode(void)
{
	//insert code
}

bool BarrierType::SetCode(AnsiString NewCode)
{
	//insert code
}

bool BarrierType::Correct(AnsiString Attempt)
{
	//insert code
}
Let us know what it is you need help with.

ILC
ILC is offline   Reply With Quote
Old April 1st, 2003, 12:26 AM     #5 (permalink)
Senior Member
 
squeech's Avatar
 
Join Date: May 2002
Location: Rocky Mountain High
Posts: 613
Your header file looks great. Note: the SetCode and Correct functions do not REQUIRE you to declare the variable within the class definition, but it doesn't do any harm there either.

Example: "bool SetCode(AnsiString NewCode)" can be put as "bool SetCode(AnsiString)" in the class, as long as you declare that string in the function definition (like in Martee's response).

ILC gave a pretty good cut and dry layout of what your implementation file for the header should look like (that's the .cpp file that does along with the one you gave us).

Your example function def looked like this:

Code:
void BarrierType::SetCode(AnsiString NewCode)
{
    Code = NewCode;
    if NewCode == '4';
        NewCode = false;
    else
        NewCode = true;
}
One thing that I wanted to point out is that in your header file you protoyped the function SetCode with a Return type of bool, and not void.

If indeed you do define it as bool, then you need to return a boolean value to the function call. Like this:

Code:
bool BarrierType::SetCode(AnsiString NewCode)
{
     // Necessary code in here, including declaration of a
     // variable of type bool to return later

     return <variable name here>;
}
I'm sure you probably know this, but all functions not of type "void" must return a value.

squeech is offline   Reply With Quote
Old April 1st, 2003, 04:29 AM     #6 (permalink)
Junior Member
 
Join Date: Mar 2003
Location: Florida USA
Posts: 18
Thanks Guys

You have definitly started me off and given my food for thought, I must now go away and write the functions.

I thought C++ was going to be fun?

Thanks again and I'm sure 'I'LL BE BACK!!'.

Morphios
Morphios is offline   Reply With Quote
Old April 1st, 2003, 09:43 AM     #7 (permalink)
Junior Member
 
Join Date: Mar 2003
Location: Florida USA
Posts: 18
Hi All

Once again wondered if someone could look at what has been done and tell me if I am going in the right direction, or tell me where I am going wrong.




Code:
BarrierType::BarrierType(void)
{
    State.BarrierType = true;
    Mode.BarrierType = 'P';
    Code.BarrierType = '0000';
}

Question 1: Can I do this to initialize Class BarrierType
Question 2: Am I barking up the wrong tree again.

Once again any help greatfully appreciated.

Morphios

Last edited by Morphios : April 1st, 2003 at 10:02 AM.
Morphios is offline   Reply With Quote
Old April 1st, 2003, 01:07 PM     #8 (permalink)
Senior Member
 
squeech's Avatar
 
Join Date: May 2002
Location: Rocky Mountain High
Posts: 613
One thing to remember: The default constructor (or initialization function as I think you called it) is a member function of the class BarrierType. This means that it has access to the private member variables without use of the dot operator.

Also, that void does not have to be in there

Try this:
Code:
BarrierType::BarrierType()
{
     State = true;
     Mode = 'P';
     Code = "0000";
}
edit~A paramaterized constructor follows the same logic, except you enter paramaters in the parentheses and set your three values equal to them.
__________________
Talking in numbers doesn't make you smarter.
squeech is offline   Reply With Quote
Old April 1st, 2003, 02:18 PM     #9 (permalink)
Junior Member
 
Join Date: Mar 2003
Location: Florida USA
Posts: 18
squeech

Thank you, Thank you.

I now understand that you only need to use the dot notation outside the class.

see you all later, only have 7 more methods to write, that should take me till around midnight tomorrow.

Thanks again

Morphios
Morphios is offline   Reply With Quote
Old April 1st, 2003, 03:11 PM     #10 (permalink)
Junior Member
 
Join Date: Mar 2003
Location: Florida USA
Posts: 18
Quick question

Can I write the other 7 methods in a similar vain or should I be thinking of if and else statements e.g:




Code:
//These methods set the State to open and closed respectively.

void BarrierOpen(void);
    {
        BarrierOpen = State;
    }

void BarrierClosed(void);
    {
        BarrierClosed = State;
    }

I am trying to write the code file but am unsure if the methods need anything harder.

Guidance appreciated

Morphios
Morphios is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Most Active Discussions
Is It Just Me? (2890)
The United States Debt (20)
3-days in and no threads about Gaza (160)
I think I just killed my computer w.. (24)
Upgrading RAM (5)
hp compaq nc6000 problems (138)
Folderchat Weekday thread (441)
Antec 300 bulk purchase? (11)
Worth the upgrade?? (15)
Recent Discussions
Worth the upgrade?? (15)
Folderchat Weekday thread (441)
ADVICE (0)
How to increase my ram? (5)
Building a gaming computer advi.. (2)
Help with an Ati Radeon HD 4850.. (27)
CPU wont boot (4)
2nd video card (1)
special characters in quarkxpre.. (3)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 09:35 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28