COPY-AND-PASTE TEMPLATE
// Filename: <<< ??.cpp >>>
//
// Purpose: <<<< This is an all-purpose C++ console application copy and paste template >>>
//
// Created By: James M. Rhoades, 6/21/02
//
// Date Started: <<< date ?? >>>
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//-------------------------------- Header Files --------------------------------------
// NOTE: Not all these header files may be compatible together!!
#include <iostream> // std I / O
#include <string.h> // to use the string data type
#include <cstdlib.h> //
#include <stdlib.h> //
#include <math.h> // for sin,cos, tan
#include <ctime> // for rand num generation seed: srand(time(NULL));
#include <iomanip.h> // used for setprecision manipulator
#include <stdio.h> //
#include <fstream> // used for file I / O
#include <dos.h> //
#include <algorithm> // used for transform( a.begin( ),a.end( ), a.begin( ), toupper);
#include <conio.h> // used for clrscr( )
#include <windows.h> // used for sleep( ) function
//#include "filename.h" // user defined header file
using namespace std;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//------------------------------ On-The-Fly Class Definitions -----------------------------
//---------- On-The-Fly Class Member Functions --------------
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//---- inline functions --------------
//---- function prototypes -----
// <<< dataReturnType functionName(const string, myArray [], float &data, const someObj & ); //>>>
//---- template function prototypes ----------------
//<<< template <class T> >>>
// <<< T function (T x); >>>
//---- declare globals -------------------
// file pointers ??
// <<< ofstream outFile; >>>
// <<< ifstream inFile; >>>
// -------- structures ?? ------------
/* <<<
struct EmployeeStruct
{
char empName[31];
char empSS[12];
float empPayRate;
char empPayPeriod[11];
};
EmployeeStruct *employee;
>>> */
//--------------------------------------- MAIN --------------------------------
int main ()
{
// -------------------- Housekeeping --------------------
// decalre variables
// <<<
float flGOne = float(0.0);
float flGTwo = float(0.0);
float flGThr = float(0.0);
int intGNmOne = 0;
int intGNmTwo = 0;
int intGNmThr = 0;
char chUserInput = ' ';
char chGOne = ' ';
string strUserInput = "";
string strGOne = "";
string strGTwo = "";
// >>>
/* <<<
employee = new EmployeeStruct; // use this line again for each record as necessary
//(but needs pointer to each)
// verify memory has been allocated
if (!employee)
{
cout << "Memory was not allocated for that record for some reason, and it needs to be.";
}// end if !employee
>>> */
// declare arrays
/* <<<
//
(array holds "a good array! ")
char myArray[7][2] = { 'a', ' ',
// row 1
'g', 'o', // row 2
'o', 'd', // row 3
' ', 'a', // row 4
'r', 'r', // row 5
'a', 'y', // row 6
'!', ' ' }; // row 7
>>> */
// check for existing filenames?? HOW?
// open files
/* <<<
outFile.open( "someOutputFile.???", ios::app);
inFile.open("someInputFile.???", ios::in);
// verify files are open
if (!outFile.is_open())
{
cout << "The output file could not be opened for some reason.";
} // end if !outFile
if (!inFile.isopen())
{
cout << "The input file could not be opened for some reason.";
} // end if !inFile
>>> */
// set output format
/* <<<
cout.precision(2);
cout.fixed;
outFile.precision(2);
outFile.fixed;
>>> */
// -------------------------- End of Housekeeping -----------------------------
//------------------------------------------------------------------------------
// generate a random number
/* <<<
srand(time(NULL)); // seed the random number generator
num = lowerBound + rand ( ) % ( upperBound - lowerBound + 1); // generate a random number
>>> */
// ----------- a get user input --------------
// (should always get a line of input as a "string" and verify the data as necessary)
/* <<<
//
prompt for input
cout << "Please Input Your Name: ";
// convert to uppercase ( this can be optional )
transform(strUserInput.begin( ),strUserInput.end( ),strUserInput.begin( ),toupper);
// get input; NOTE: this will accept spaces and just Enter
also
getline(cin,userInput);
>>> */
//------------- if structure --------------
/* <<<
if ( strUserInput )
{
// statements when true
}
else if ( otherCondition )
{
// statements when related if is true
}
else
{
// statements when previous condition(s) is/are false
} // end if strUserInput
>>> */
/* <<<
strcpy(employee->empName, "Jack Smiley");
strcpy(employee->empSS, "094-88-7747");
employee->empPayRate = 10.00;
strcpy(employee->empPayPeriod, "Weekly");
cout << &employee->empName << endl;
cout << employee->empName << endl;
cout << employee->empSS << endl;
cout << employee->empPayRate << endl;
cout << employee->empPayPeriod << endl;
cout << endl;
EmployeeStruct *addressOne = employee;
employee = new EmployeeStruct; // make another record
strcpy(employee->empName, "Jeff Smarty");
strcpy(employee->empSS, "077-12-4417");
employee->empPayRate = 8.00;
strcpy(employee->empPayPeriod, "Weekly");
cout << &employee->empName << endl;
cout << employee->empName << endl;
cout << employee->empSS << endl;
cout << employee->empPayRate << endl;
cout << employee->empPayPeriod << endl;
cout << endl;
EmployeeStruct *addressTwo = employee;
employee = addressOne;
cout << &employee->empName << endl;
cout << employee->empName << endl;
cout << employee->empSS << endl;
cout << employee->empPayRate << endl;
cout << employee->empPayPeriod << endl;
cout << endl;
employee = addressOne;
delete employee; // free memory
employee = addressTwo;
delete employee; // free memory
>>> */
//--------- a function call ---------------
/* <<<
try
{
functionCall( string &strUserInput );
cout << setw(20) << strUserInput << endl;
}
catch ( char *errorMessage )
{
// take actions on error
cout << errorMessage << endl;
} // end function call functionCall
>>> */
// -------------- a nested if -------------
/* <<<
if( condition )
{
if( condition 2 )
{
// break or goto??
} // end if condition 2
} // end if condition
lblOne: // a line label for a goto
>>> */
//-------------------- a switch --------------------------
/* <<<
switch(selectorExpression)
{
case 1:
break;
case 'a':
break;
case "Story":
break;
default:
break;
} // end switch
>>> */
// ---------- close files --------
// <<< outFile.close(); >>>
// <<< inFile.close(); >>>
// ----------------- EOJ ----------------------
cout << "\n\n" << "Program ending . . ." ;
sleep(2);
cout << "program ended." << "\n\n";
cout << "Created By James M. Rhoades, June 2002, All rights reserved." << "\n\n";
return(0); // no outstanding errors to report on program exit
} // end main function
// ---------------------------------------------------------------------------------------
// ----------- a user defined function -----------
/* <<<
void functionName( string &strUsrInpt )
{
// declare local variables
// strUsrInpt = "User input is: " + strUsrInpt;
// throw("There was an error in functionName.");
} // end functionName
>>> */