User:Ray Calvin Baker/Recursive cpp

Ray Calvin Baker 04:05, 28 November 2011 (UTC) New page for C++ source code -- to be ported to QB64, if/when I can do it.  // RECURSIVE.cpp : Defines the entry point for the console application. //


 * 1) include "stdafx.h"

// For _getche, etc.
 * 1) include 

// Function prototypes: int All        (int nTries); int Cheese     (int nTries); int Coffee     (int nTries); int Endive     (int nTries); // X int  Esoresso   (int nTries); // X int  HarryPotter(int nTries); int Macaroni   (int nTries); int Pasta      (int nTries); int RedBaron   (int nTries); int Repast     (int nTries); int Sauce      (int nTries); void SensibleKey(void); int Shad       (int nTries); int Sharp      (int nTries); int Spiced     (int nTries); int Tomatoes   (int nTries);

int main(int argc, char* argv[]) {

printf("Hello World!\n"); printf("I want to explore the process of RECURSION.\n\n");

printf("TOMATOES\n"); printf("Iteration 0\n"); Tomatoes(0); SensibleKey;

printf("Iteration 1\n"); Tomatoes(1); SensibleKey;

printf("Iteration 2\n"); Tomatoes(2); SensibleKey;

printf("Iteration 3\n"); Tomatoes(3); SensibleKey;

printf("Iteration 4\n"); Tomatoes(4); SensibleKey;

printf("Iteration 5\n"); Tomatoes(5); SensibleKey;

printf("RED BARON\n"); printf("Iteration 0\n"); RedBaron(0); SensibleKey;

printf("Iteration 1\n"); RedBaron(1); SensibleKey;

printf("Iteration 2\n"); RedBaron(2); SensibleKey;

printf("Iteration 3\n"); RedBaron(3); SensibleKey;

printf("Iteration 4\n"); RedBaron(4); SensibleKey;

printf("HARRY POTTER\n"); printf("Iteration 0\n"); HarryPotter(0); SensibleKey;

printf("Iteration 1\n"); HarryPotter(1); SensibleKey;

printf("Iteration 2\n"); HarryPotter(2); SensibleKey;

printf("Iteration 3\n"); HarryPotter(3); SensibleKey;

printf("Iteration 4\n"); HarryPotter(4); SensibleKey;

printf("Iteration 5\n"); HarryPotter(5); SensibleKey;

return 0; } // End main..

int All(int nTries) { if ( nTries == 0 ) { printf(" a luscious lunch "); return 0; } else { printf(" a luscious lunch "); return nTries - 1; } // endifelse. } // End All.

int Cheese(int nTries) { if ( nTries == 0 ) { printf("cheddar, havarti, emmenthaler (especially ");		Sharp(0);		printf(" emmenthaler)"); return 0; } else { printf("cheddar, havarti, emmenthaler (especially ");		Sharp(nTries - 1);		printf(" emmenthaler)"); return nTries - 1; } // endifelse. } // End Cheese.

int Coffee(int nTries) { if ( nTries == 0 ) { printf("choice of fine flavors, especially ESPRESSO "); return 0; } else { printf("choice of fine flavors, especially ESPRESSO "); return nTries - 1; } // endifelse. } // End Coffee.

int HarryPotter(int nTries) { if ( nTries == 0 ) { printf("I recurse you, HarryPotter the ignorant, HarryPotter the distraction!\n"); return 0; } else { printf("I recurse you, "); HarryPotter(nTries - 1); printf(" the ignorant, "); HarryPotter(nTries - 1); printf(" the distraction!\n");

return nTries - 1; } // endifelse. } // End HarryPotter.

int Macaroni(int nTries) { if ( nTries == 0 ) { printf("MACARONI and "); Cheese(0); printf(" (a ");		Repast(0);		printf(" of Naples, Italy)"); return 0; } else { Macaroni(nTries - 1); printf(" and "); Cheese(nTries - 1); printf(" (a ");		Repast(nTries - 1);		printf(" of Naples, Italy)");

return nTries - 1; } // endifelse. } // End Macaroni.

int Pasta(int nTries) { if ( nTries == 0 ) { printf("PASTA and "); Sauce(0); printf("(that's ALL!)"); return 0; } else { Pasta(nTries - 1); printf(" and "); Sauce(nTries - 1); printf("(that's ALL!)"); return nTries - 1; } // endifelse. } // End Pasta.

int RedBaron(int nTries) { if ( nTries == 0 ) { printf("I recurse you, RedBaron, in your RedBaron biplane!\n"); return 0; } else { printf("I recurse you, "); RedBaron(nTries - 1); printf(", in your "); RedBaron(nTries - 1); printf(" biplane!\n"); return nTries - 1; } // endifelse. } // End RedBaron.

int Repast(int nTries) { if ( nTries == 0 ) { printf("rather extraordinary "); Pasta(0); printf(" and "); Sauce(0); printf(" typical"); return 0; } else { printf("rather extraordinary "); Pasta(nTries - 1); printf(" and "); Sauce(nTries - 1); printf(" typical"); return nTries - 1; } // endifelse. } // End Repast.

int Sauce(int nTries) { if ( nTries == 0 ) { Shad(0); printf(" and unusual "); Coffee(0); printf(" (eccellente!) "); return 0; } else { Shad(nTries - 1); printf(" and unusual "); Coffee(nTries - 1); printf(" (eccellente!) "); return nTries - 1; } // endifelse. } // End Sauce.

void SensibleKey(void) { int nIn;

printf("\nPlease press any \"sensible\" key. "); nIn = _getche; printf("\nThank you for the '%c' = %d.\n", nIn, nIn); } // End SensibleKey.

int Shad       (int nTries) { if ( nTries == 0 ) { printf(" SPAGHETTI, heated el dente "); return 0; } else { printf(" SPAGHETTI, heated el dente "); return nTries - 1; } // endifelse. } // End Shad.

int Sharp(int nTries) { if ( nTries == 0 ) { printf(" strong, hearty, and rather pungent "); return 0; } else { printf(" strong, hearty, and rather pungent "); return nTries - 1; } // endifelse. } // End Sharp.

int Spiced     (int nTries) { if ( nTries == 0 ) { printf(" sweetly pickled in CHEESE ENDIVE dressing "); return 0; } else { printf(" sweetly pickled in CHEESE ENDIVE dressing "); return nTries - 1; } // endifelse. } // End Spiced.

int Tomatoes(int nTries) { if ( nTries == 0 ) { printf(" TOMATOES on MACARONI (and TOMATOES only), exquisitely SPICED "); return 0; } else { Tomatoes(nTries - 1); printf(" on "); Macaroni(nTries - 1); printf(" and "); Tomatoes(nTries - 1); printf(" only), exquisitely ");		Spiced(nTries - 1);		printf(".\n");		return nTries - 1;	} // endifelse. } // End Tomatoes.

// End of the RECURSIVE.cpp file. 