You are on page 1of 5

Function Lab1 (5 points total)

Type in Word. Work with a partner and submit individually on Blackboard.

Program 1 (2.5 points)

#include <iostream>
using namespace std;
//prototypes
void DemonstrateProc1();
void DemonstrateProc2(int num);
int main()
{
    cout << "?. Execution starts with main. " << endl;
    DemonstrateProc1();
    cout << "?. Then we come here. " << endl;
    DemonstrateProc2(100);
    cout << "?. Finally we come here. "<< endl;
    return 0;
}
//****************************
void DemonstrateProc1()
{
    cout << "?. This is a sample procedure." << endl;
}
//****************************
void DemonstrateProc2(int num)
{
    cout << "?. This is another sample procedure. " << endl;
    cout << "   num is an argument or parameter. " << endl;
    cout << "   The value of num is " << num << endl;
}

     

1. Type in the above program including your name and date as a comment. Before running
the program, change each of the question marks to the numbers 1 through 5 indicating
the order in which that line will be executed. Run the program and check your numbers.
Fix and rerun if necessary. Submit the program and the output.
2. //RobbieKenderdine 4/26/2020
3. #include <iostream>
4. using namespace std;
5. //prototypes
6. void DemonstrateProc1();
7. void DemonstrateProc2(int num);
8. int main()
9. {
10.    cout << "1. Execution starts with main. " << endl;
11.    DemonstrateProc1();
12.    cout << "3. Then we come here. " << endl;
13.    DemonstrateProc2(100);
14.    cout << "5. Finally we come here. "<< endl;
15.    return 0;
16.}
17.//****************************
18.void DemonstrateProc1()
19.{
20.    cout << "2. This is a sample procedure." << endl;
21.}
22.//****************************
23.void DemonstrateProc2(int num)
24.{
25.    cout << "4. This is another sample procedure. " << endl;
26.    cout << "   num is an argument or parameter. " << endl;
27.    cout << "   The value of num is " << num << endl;
28.}
29.

1. Execution starts with main.

2. This is a sample procedure.

3. Then we come here.

4. This is another sample procedure.

num is an argument or parameter.

The value of num is 100

5. Finally we come here.

Program 2 (2.5 points)


//**************************************************
// NewWelcome program
// This program prints a "Welcome Home" message
//**************************************************
#include <iostream>
using namespace std;
void PrintLines( int ); // Function prototype
int main()
{
    PrintLines(2);
    cout << " Welcome Home!" << endl;
    return 0;
}
//****************************************************************
// PrintLines prints lines of asterisks, where
// numLines specifies how many lines to print
//***************************************************************
void PrintLines( int numLines )
{
    int line; // Loop control variable
    for (line = 0; line < numLines; line++)
    {
        cout << "*************************************" << endl;
    }
}

Type in the above program as lines.cpp. Add a comment to include your name and date. Compile
and run. Change the program so that it will print 2 lines of asterisks before the welcome message
and 4 lines of asterisks after the welcome message. Compile and run.

1. Is PrintLines an example of a void or value returning function?

PrintLines is an example of a void.

2. Is numLines being passed in or passed out?

numLines is being passed in.

3. On the program label the formal argument(s) and the actual argument(s).
4. Draw a hierarchy chart for the program. 
{

PrintLines

PrintLines2

PrintLines4

5. Turn in a copy of the program and output


6. //Robbie Kenderdine 4/26/2020
7. #include <iostream>
8. using namespace std;
9. void PrintLines( int ); //formal
10.int main()
11.{
12.    PrintLines(2);//actual
13.    cout << " Welcome Home!" << endl;
14.    PrintLines(4);//actual
15.    return 0;
16.}
17.
18.void PrintLines( int numLines ) //Formal
19.{
20.    int line; 
21.    for (line = 0; line < numLines; line++)
22.    {
23.        cout << "*************************************" << endl;
24.    }
25.}

*************************************

*************************************

Welcome Home!

*************************************

*************************************

*************************************
*************************************

You might also like