# Programming Assignments for Chapter 8

1. Complete the functions: printBox and main (marked with "Fill in here"). Function printBox prints a box whose height is half the width with signs and width specified by the users from keyboard.
```void  printBox(int numSigns, char sign);

int main ()
{
int  number;
char symbol;

cout << "Enter the number of signs for the box; "
<< "press return." << endl;
cin >> number;

cout << "Enter the sign for the box; "
<< "press return." << endl;
cin >> symbol;

//Fill in here...

return 0;
}

//Print a box with characters of "sign" of numSigns x numSigns/2
void  printBox(int numSigns, char sign)
{
//Fill in here
}

Enter the number of signs for the box; press return.
20
Enter the sign for the box; press return.
\$
\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
\$                  \$
\$                  \$
\$                  \$
\$                  \$
\$                  \$
\$                  \$
\$                  \$
\$                  \$
\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$
Press any key to continue . . .

Enter the number of signs for the box; press return.
30
Enter the sign for the box; press return.
#
##############################
#                            #
#                            #
#                            #
#                            #
#                            #
#                            #
#                            #
#                            #
#                            #
#                            #
#                            #
#                            #
#                            #
##############################
Press any key to continue . . .

```
2. Suppose an alien giant walks with decreasing steps (stride length). Each step is half of his last step. Write a function to calculate how far the alien giant can go with known steps if the giant's very step is one mile. Test your program with different numbers of steps to observe the results. With how many steps can the alien giant go more than two miles? Extra points will be given if you can find the result mathematically.
(Hint: Total distance = 1 + 1/2 + 1/4 + 1/8 + ...)
```double walk(int steps)
{
double totalDistance;
//Fill in here

return totalDistance;
}

int main()
{
//Sample function calls. You might change the number of steps to test how far the giant can go
cout << "With 10 steps the giant walked " << walk(10) << " miles." << endl;
cout << "With 30 steps the giant walked " << walk(30) << " miles." << endl;
return 0:
}
```
3. Write a function that finds the area and circumference of a circle, given the radius of the circle. The function needs to be called from a main function with a radius of 10.0. Note that the function takes radius as input and "produces" both area and circumference as output. (Hint: consider using passing-by-reference method. const double PI =3.141592653;)
4. Submit your programs and outputs to Blackboard.