Need assistance with a tutorial on basic functions

Below is an entire tutorial from an online source. If possible, I would appreciate any help. I basically need a little direction of how to get started. I have been learning C++ for only about 2 weeks now and have had no other programming experience in the past.


//This tutorial assignment will practice the declaration
// and inplementation of simple functions.
// For simplicity, and to remove the extra time to define function prototypes,
// the main() function will be left at the bottom of this program file.
//
// For each of the three functions in this tutorial:
// -- determine what appears in the formal parameter list
// i.e. they all have no parametrs now, but that must change
// -- determine whether it is a value returning function, or void
// i.e. they are all void now, but some will have to change!
// -- determine which formal parameters will be references to variables
// -- code the function to perform its task
//
// The main function is already complete, except for some comment markers
// (which are present to avoid compiler errors).
// For each case, implement the function so that it matches
// the expected behavior as called by main().

// DO NOT rewrite the function calls in main -- only remove the comments.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

// Implement your functions here.
// (Remember to uncomment the calls in main() to test them)

// maximum:
// returns the larger of two integers
// example call: cout << maximum(14, 25); would output 25
void maximum( )
{

}

// intPower:
// given a real value (double) and an integer exponent
// raises the value to the desired power, returning the result
// DO NOT call the pow function... do the multiplication yourself
// example call: cout << intPower( -2.7, 2 ); would output 7.29
// This function may assume the given exponent is not less than zero.
// (but it may be exactly zero)
// recall: x ^ N = 1 * x * x * x .... (N times)
void intPower( )
{

}

// sort3:
// given references to three integer variables,
// rearranges them so the first is the largest, and the third is the smallest
// example call: sort3( k, l, m );
//
// HINT: It is possible to do this with exactly three statements of the form:
// if ( ____ > ____ )
// swap( ____, ____ );
// Some assertions are provided to help you
//
// There is already a function called swap that exchanges value
// which you may use. There is no need to implement that function.
void sortThree( )
{
// originally, the three values may be in any order



// the first is now greater than the second



// the first is greater than both the second and the third (it is largest)



// the values are now all sorted with the first largest and third smallest
}

// The code below will test the functions implemented above.
// Make no changes here aside from removing the '//' comment markers.
int main()
{
int i, j, k, l, m; // some generic integer variables

cout << setprecision(4); // show only 4 significant digits
for (i = 1; i <= 3; i++)
{
j = rand() % 100;
cout << "The larger of " << j << " and 25 is " << maximum( j, 25 ) << endl;
cout << "The larger of " << j << " and 50 is " << maximum( 50, j ) << endl;
}

for (i = 0; i <= 4; i++)
{
cout << right; // right justify these integer results
cout << "-2 ^ " << i << " = " << setw(2) << intPower( -2, i );
cout << left; // left justify these float results
cout << " 1.414 ^ " << i << " = " << setw(6) << intPower( sqrt(2.0f), i );
cout << endl;
}
cout << "10 ^ (-5) = " << intPower( 10, -5 ) << endl;

for (i = 0; i < 7; i++)
{
k = rand() % 100;
l = rand() % 100;
m = rand() % 100;
sort3( k, l, m );
cout << k << " >= " << l << " >= " << m << endl;
}
}
What is it that you have a hard time grasping?
Topic archived. No new replies allowed.