FUNCTIONS

Write function headers for the following functions:

1. A function computetax takes a total due and tax rate and returns the tax that is owed on the total.

1. A function div takes two floating point numbers, divides the first by the second and returns the result.

Trace:

1.

#include<iostream>

using namespace std;

int var1;

int fun1(int,int);

int main()

{  int var2,result;

cout<<"we are in the main program\n";

var1 = 15;

var2 = 35;

cout<<"var1 is"<<var1<<endl;

cout<<"var2 is"<<var2<<endl;

result = fun1(var1,var2);

cout<<result<<'\t'<<var1<<'\t'<<var2<<endl;

var1 = fun1(var1,var2);

cout<<result<<'\t'<<var1<<'\t'<<var2<<endl;

return 0;

}

int fun1(int a,int b)

{

a++;

b++;

return a + b;

}

2.

#include<iostream>

using namespace std;

float num = 10;

float compute(float);

int main()

{

float x = 40;

cout<<"num: "<<num<<"x: "<<x<<endl;

cout<<compute(num);

cout<<compute(x);

cout<<"num: "<<num<<"x: "<<x<<endl;

return 0;

}

float compute(float x)

{

x = x * .10;

num = num + 30;

return x;

}

3.

#include<iostream>

using namespace std;

void testing();

int main()

{

int variable1 = 10;

int i;

cout<<"Before calls to the fuctions\n";

for (i = 1; i < variable1; i++)

{

cout<<"testing----------------------------------\n";

testing();

}

}

void testing()

{

int variable2 = 4;

int j;

for (j = 1; j < variable2; j++)

cout<<"*";

cout << endl;

variable2 = variable2 + 2;

}

4.

#include<iostream>

using namespace std;

void testing(int& x, int y);

int main()

{

int var1 = 0;

int var2 = 9;

cout<<"before funct"<<var1<<" "<<var2<<endl;

testing(var1,var2);

cout<<"after funct"<<var1<<" "<<var2<<endl;

return 0;

}

void testing(int& x, int y)

{

cout<<"in function"<<x<<" "<<y<<endl;

x = x + y;

y = y + x;

}