C/C++ assignment help

I have this assignment, but not even sure what I'm suppose to do, I really need some help/pointers on what to do.
please help.

------
Given the "main" routine shown below:

int main(void) {
call to function1()
call to function2(value1)
call to function3(value2)
return 0;
}

Your task is to write functions 1, 2, and 3.

1. Function1() is optional and is ONLY used to initialize the
"environment."

2. Function2() and function3() must have a SINGLE value passed
to them, yet when called must add the two values and print
the result (this is why you may need to initialize the
"environment."

Comments

  • For "the environment" you need to define a global variable to hold the temporary results of a call to function2 or function3. This should be initialized to the flag value

    function1 needs to set that global value to a flag value to indicate that no value has been entered;

    function2 needs to place its value into the global value

    function3 needs to add its value to the global value andd print the result

    Expansion options:
    Have both function2 and function3 check to see if a global value has been loaded anbd then either load the global or do the print out accordingly.
    Reset the global after printing results

    : I have this assignment, but not even sure what I'm suppose to do, I really need some help/pointers on what to do.
    : please help.
    :
    : ------
    : Given the "main" routine shown below:
    :
    : int main(void) {
    : call to function1()
    : call to function2(value1)
    : call to function3(value2)
    : return 0;
    : }
    :
    : Your task is to write functions 1, 2, and 3.
    :
    : 1. Function1() is optional and is ONLY used to initialize the
    : "environment."
    :
    : 2. Function2() and function3() must have a SINGLE value passed
    : to them, yet when called must add the two values and print
    : the result (this is why you may need to initialize the
    : "environment."
    :
    :

  • forgot to mention this, I'm not allowed to use global variables. How do I do this without using global variables?
    thanx


    : For "the environment" you need to define a global variable to hold the temporary results of a call to function2 or function3. This should be initialized to the flag value
    :
    : function1 needs to set that global value to a flag value to indicate that no value has been entered;
    :
    : function2 needs to place its value into the global value
    :
    : function3 needs to add its value to the global value andd print the result
    :
    : Expansion options:
    : Have both function2 and function3 check to see if a global value has been loaded anbd then either load the global or do the print out accordingly.
    : Reset the global after printing results
    :
    : : I have this assignment, but not even sure what I'm suppose to do, I really need some help/pointers on what to do.
    : : please help.
    : :
    : : ------
    : : Given the "main" routine shown below:
    : :
    : : int main(void) {
    : : call to function1()
    : : call to function2(value1)
    : : call to function3(value2)
    : : return 0;
    : : }
    : :
    : : Your task is to write functions 1, 2, and 3.
    : :
    : : 1. Function1() is optional and is ONLY used to initialize the
    : : "environment."
    : :
    : : 2. Function2() and function3() must have a SINGLE value passed
    : : to them, yet when called must add the two values and print
    : : the result (this is why you may need to initialize the
    : : "environment."
    : :
    : :
    :
    :


  • If this is C++, you declare a class that holds the intermediate variable. Then the functions described are methods of that class and can operate on that variable. You would declare an instance of the class and call the class functions to provide the capabilities.

    : forgot to mention this, I'm not allowed to use global variables. How do I do this without using global variables?
    : thanx
    :
    :
    : : For "the environment" you need to define a global variable to hold the temporary results of a call to function2 or function3. This should be initialized to the flag value
    : :
    : : function1 needs to set that global value to a flag value to indicate that no value has been entered;
    : :
    : : function2 needs to place its value into the global value
    : :
    : : function3 needs to add its value to the global value andd print the result
    : :
    : : Expansion options:
    : : Have both function2 and function3 check to see if a global value has been loaded anbd then either load the global or do the print out accordingly.
    : : Reset the global after printing results
    : :
    : : : I have this assignment, but not even sure what I'm suppose to do, I really need some help/pointers on what to do.
    : : : please help.
    : : :
    : : : ------
    : : : Given the "main" routine shown below:
    : : :
    : : : int main(void) {
    : : : call to function1()
    : : : call to function2(value1)
    : : : call to function3(value2)
    : : : return 0;
    : : : }
    : : :
    : : : Your task is to write functions 1, 2, and 3.
    : : :
    : : : 1. Function1() is optional and is ONLY used to initialize the
    : : : "environment."
    : : :
    : : : 2. Function2() and function3() must have a SINGLE value passed
    : : : to them, yet when called must add the two values and print
    : : : the result (this is why you may need to initialize the
    : : : "environment."
    : : :
    : : :
    : :
    : :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories