• Congratulations to the Class of 2024 on your results!
    Let us know how you went here
    Got a question about your uni preferences? Ask us here

Control Parameter (1 Viewer)

Dario

Member
Joined
Jul 25, 2002
Messages
210
Location
Horsley, NSW
Gender
Male
HSC
2002
Does anyone know what a control parameter actually is ? I know it is a filled in arrow in a structure diagram but what does it do and what is is used for ? Our teacher couldn't explain it and it isn't in our textbook either.
 

del

Member
Joined
Jul 8, 2002
Messages
412
Gender
Undisclosed
HSC
N/A
it's like a flag value
 

SamD

Member
Joined
Jul 21, 2002
Messages
256
Gender
Male
HSC
N/A
Dario, maybe you should buy my text after all, this stuff is in chapter 3 and that ain't on the web!!!!

Anyhow here goes:

I'm assuming you have some understanding of what a parameter is. Well a control parameter is a parameter upon which the sequence of execution depends. Therefore the value of the control parameter is used to detemine which path execution takes through the code. Under most cirumstances control parameters are boolean values but they don't have to be.

For example the response from a bank back to an EFTPOS machine determines if the transaction is approved (or not approved). The EFTPOS machine executes different code based on this control parameter value.
 
T

tactic

Guest
from what i remember last semester a control parameter is a value that is passed which is needed by the module it is passed to or returned to to perform an operation..

eg this..

int calc(int num1, int num2, int num3)
{
num3 = num1 + num2;
return num3;
}


void main()
{
int num1, num2, num3;
cin >> num1;
cin >> num2;
cin >> num3;
calc(num1, num2, num3);
cout << num3;
}

in this code num1 2 and 3 are parameters which are passed to the module calc and are added and stored in num3 then it is passed back and displayed. This shows no use of control parameters because the parameters passed do not control the way the program runs..

and now for an example with control parm passing

ing validate(int num1, int num2, int num3)
{
//some crap to check if its valid numbers
return valid; //this will return a 0 if it is invalid and a 1 if it is valid
}

int calc(int num1, int num2, int num3)
{
num3 = num1 + num2;
return num3;
}

void main()
{
int num1, num2, num3, valid;
cin >> num1;
cin >> num2;
cin >> num3;
validate(num1, num2, num3);
if(valid==1)
{
calc(num1, num2, num3);
cout << num3;
} else {
cout << "invalid number(s)";
}
}


this is basily the same as the above but this time it passes the paramters to a validation module which will check if the numbers are valid, when they are valid it will return a 1 and when they are not valid a 0. The variable valid is a control paramter and it is passed back to the mainline, as you can see it actualy has some effect on the control of the program by the if-else statement..


hope it helps..
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top