Listing 9, NestedCounterLoop01
/*File: NestedCounterLoop01.cpp
This C++ program illustrates the use of a pair of for loops
to create a nested counter loop. Screen output from this
program follows:
0 0 0 0 0
0 1 2 3 4
0 2 4 6 8
**********************************************************/
#include <iostream>
using namespace std;
class NestedCounterLoop01{
public:
static void classMain(){
NestedCounterLoop01* ptrToObject =
new NestedCounterLoop01();
ptrToObject -> doSomething();
}//End classMain function
//-----------------------------------------------------//
//An instance function of the NestedCounterLoop01 class
void doSomething(){
int rowLim = 3;
int colLim = 5;
for(int rCnt = 0;rCnt < rowLim;rCnt = rCnt + 1){
for(int cCnt = 0;cCnt < colLim;cCnt = cCnt + 1){
cout << rCnt * cCnt << " ";
}//end inner loop
cout << endl;
}//end outer loop
}//end doSomething function
};//End NestedCounterLoop01 class
//-------------------------------------------------------//
int main(){
NestedCounterLoop01::classMain();
return 0;
}//end main
Listing 9
|