//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//
ArraySystem1.cpp
//
//
//
// Purpose: Display,
average, sum, and fill static integer array containers. Associated
//
//
with each array is a MAX (capacity) and an ActNo (how many filled at any
//
//
given moment in time. Always keep the ActNo accurate. Make sure that you
//
//
never exceed the boundaries of the array - even if you pass incorrect
//
//
NoToFill, NoToDisplay, etc. into functions.
//
//
//
// Written By: Dr. Thomas
E. Hicks
Environment:Linux //
// Date: 9/17/01
Compiler: C++
//
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////
Includes /////////////////////////////////////////////
# include <iostream.h>
# include <stdlib.h>
# include <time.h>
# include <iomanip.h> ///////////////////////////////////////
Defines //////////////////////////////////////////////
# define MAX_BOWLING 90
# define MAX_EXAMS
10
# define MAX_NOS 300
# define VALID
true
# define INVALID
false
# define
UNIX
// # define
MAC
// # define
WINDOWS
/////////////////////////////////////
Prototypes /////////////////////////////////////////////
void ClearScreen (void);
void Commercial (void);
void SetRandNoGeneratorSeed
(void);
long int RandNo (long int Low,
long int High);
void Delay (long int NoSeconds);
void DisplayIntArray (char
Message[], int Array[], int NoToDisplay, int ActNo, int Max);
void RandomFillIntArray (int
Array[], int & ActNo, int Low, int High, int NoToFill, int Max);
void InitializeIntArray (int
Array[], int & ActNo, int Max);
main()
{
int
BowlingScores[MAX_BOWLING],
Exams [MAX_EXAMS],
Nos [MAX_NOS],
ActNoBowling = 0,
ActNoExams = 0,
ActNoNos = 0;
Commercial();
SetRandNoGeneratorSeed();
cout << "\n\n==================================================================================\n";
cout << "==================================== 1 ===========================================\n";
cout << "==================== Testing Display Values Are Garbage ==========================\n";
cout << "==================================================================================\n\n";
DisplayIntArray ("MAX_EXAMS Garbage Values Stored In Array Exams", Exams, MAX_EXAMS, ActNoExams, MAX_EXAMS);
DisplayIntArray ("15 Garbage Values Stored In Array Bowling", Bowling, MAX_BOWLING, ActNoBowling, MAX_BOWLING);
DisplayIntArray ("10 Garbage Values Stored In Array Nos", Nos, MAX_NOS, ActNoNos, MAX_NOS);
/*
cout << "\n\n==================================================================================\n";
cout << "==================================== 2 ===========================================\n";
cout << "============================= Testing Initialization =============================\n";
cout << "==================================================================================\n\n";
InitializeIntArray (Exams, ActNoExams, MAX_EXAMS);
InitializeIntArray (Bowling, ActNoBowling, MAX_BOWLING);
InitializeIntArray (Nos, ActNoNos, MAX_NOS);
DisplayIntArray ("Initialized Exams", Exams, 1000, ActNoExams, MAX_EXAMS);
DisplayIntArray ("Initialized Bowling", Bowling, 1000, ActNoBowling, MAX_BOWLING);
DisplayIntArray ("Initialized Nos", Nos, 1000, ActNoNos, MAX_NOS);
cout << "\n\n==================================================================================\n";
cout << "==================================== 3 ===========================================\n";
cout << "========================== Randomly Fill Arrays Half Full ========================\n";
cout << "============================== Testing Display ==================================\n";
cout << "==================================================================================\n\n";
RandomFillIntArray (Exams, ActNoExams, 60, 100, 5, MAX_EXAMS);
RandomFillIntArray (Bowling, ActNoBowling, 0, 300, 15, MAX_BOWLING);
RandomFillIntArray (Nos, ActNoNos, 1, 10000, 500, MAX_NOS);
DisplayIntArray ("Half Filled Exams", Exams, ActNoExams, ActNoExams, MAX_EXAMS);
DisplayIntArray ("Half Filled Bowling", Bowling, ActNoBowling, ActNoBowling, MAX_BOWLING);
DisplayIntArray ("Half Filled Nos", Nos, ActNoNos, ActNoNos, MAX_NOS);
cout << "==================================================================================\n";
cout << "==================================== 4 ===========================================\n";
cout << "======================== Re-Initialize Arrays ====================================\n";
cout << "===================== Testing Display [NoToDisplay Too Small] ====================\n";
cout << "==================================================================================\n\n";
InitializeIntArray (Exams, ActNoExams, MAX_EXAMS);
InitializeIntArray (Bowling, ActNoBowling, MAX_BOWLING);
InitializeIntArray (Nos, ActNoNos, MAX_NOS);
DisplayIntArray ("Initialized Exams", Exams, 3, ActNoExams, MAX_EXAMS);
DisplayIntArray ("Initialized Bowling", Bowling, 3, ActNoBowling, MAX_BOWLING);
DisplayIntArray ("Initialized Nos", Nos, 3, ActNoNos, MAX_NOS);
srand(5);
cout << "\n\n==================================================================================\n";
cout << "==================================== 5 ===========================================\n";
cout << "======================= Randomly Fill Arrays Do Not Overflow =====================\n";
cout << "============================== Testing Display ==================================\n";
cout << "==================================================================================\n\n";
RandomFillIntArray (Exams, ActNoExams, 60, 100, 1000, MAX_EXAMS);
RandomFillIntArray (Bowling, ActNoBowling, 0, 300, 1000, MAX_BOWLING);
RandomFillIntArray (Nos, ActNoNos, 1, 10000, 1000, MAX_NOS);
DisplayIntArray ("Overflowed Exams", Exams, ActNoExams, ActNoExams, MAX_EXAMS);
DisplayIntArray ("Overflowed Bowling", Bowling, ActNoBowling, ActNoBowling, MAX_BOWLING);
DisplayIntArray ("Overflowed Nos", Nos, ActNoNos, ActNoNos, MAX_NOS);
*/
return (0);
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//
InitializeIntArray
//
//
//
// Purpose: Set the NoToFill
to be 0. Place A 0 in each and every element of the Array.
//
//
//
// Required Include Headers
: <stdlib.h>
//
// Required Support Modules
: None
//
// Recommended Support
Modules: None
//
//
//
// Written By: Dr. Thomas
E. Hicks
Environment:Linux //
// Date: 9/17/01
Compiler: C++
//
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//You Do --> Leave two blank
lines at the bottom of each function to separate it from others
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//
RandomFillIntArray
//
//
//
// Purpose: If the NoToFill
> Max, set the NoToFill to be the Max. If the NoToFill is
//
//
negative, set the NoToFill to be the Max. Place NoToFill Random Numbers
//
//
in the range <Low <--> High> into Array starting at element 0. Update
the //
//
ActNo.
//
//
//
// Required Include Headers
: <stdlib.h>
//
// Required Support Modules
: RandNo
//
// Recommended Support
Modules: SetRandNoGeneratorSeed
//
//
//
// Written By: Dr. Thomas
E. Hicks
Environment:Linux //
// Date: 9/17/01
Compiler: C++
//
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//You Do --> Leave two blank
lines at the bottom of each function to separate it from others
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//
DisplayIntArray
//
//
//
// Purpose: Display the
Message and skip 2 lines. If the NoToDisplay is greater than the
//
//
Max, set the NoToDisplay to the Max. If The NoToDisplay is less than 0,
set //
//
the NoToDisplay to the Max. Provide a nice graphical view of the Array;
//
//
display the cells downward so that element 0 is at the bottom. Skip a line.
//
//
Display the ActNo and The Max. Skip three lines.
//
//
//
// Required Include Headers
: <iostream.h>
//
// Required Support Modules
: None
//
// Recommended Support
Modules: ClearScreen
//
//
//
// Written By: Dr. Thomas
E. Hicks
Environment:Linux //
// Date: 9/17/01
Compiler: C++
//
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
void DisplayIntArray (char Message[], int Array[], int NoToDisplay, int ActNo, int Max)
{
int
Counter;
cout << Message << endl << endl;
for (Counter = NoToDisplay -1 ; Counter >= 0; Counter --)
{
cout << " |------------------|\n";
cout << setw(4) << Counter << " | " << setw(16) << Array[Counter] << " |\n";
}
cout <<" |------------------|\n\n";
cout << " ActNo = " << ActNo << " Max = " << Max << "\n\n\n";
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//
ClearScreen
//
//
//
// Purpose: Clear the
console window on a UNIX/Linux System.
//
//
//
// Required Include Headers
: <stdlib.h>
//
// Required Support Modules
: none
//
// Recommended Support
Modules: none
//
//
//
// Written By: Dr. Thomas
E. Hicks
Environment:Linux //
// Date: 9/17/01
Compiler: C++
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
void ClearScreen (void)
{
# ifdef UNIX
system ("clear");
# endif
# ifdef WINDOWS
s ystem ("cls");
# endif
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//
Commercial
//
//
//
// Purpose: Display a
program commercial somewhere near the center of a window.
//
//
//
// Required Include Headers
: <iostream.h>
//
// Required Support Modules
: ClearScreen
//
// Written By: Dr. Thomas
E. Hicks
Environment:Linux //
// Date: 9/17/01
Compiler: C++
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
void Commercial (void)
{
ClearScreen();
cout << "
Array Calculation System\n";
cout << "
Written by\n";
cout << "
?????\n\n\n";
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//
SetRandNoGeneratorSeed
//
//
//
// Purpose: Use The Microprocessor
Clock To Set The Seed Of The Random Number Generator. //
//
//
// Required Include Headers:
<time.h>
//
// Required Support Modules:
none
//
// Recommended Support
Modules: RandNo
//
//
//
// Written By: Dr. Thomas
E. Hicks
Environment:Linux //
// Date: 9/17/01
Compiler: C++
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
void SetRandNoGeneratorSeed (void)
{
srand( (unsigned) time(NULL) );
}
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//
RandNo
//
//
//
// Purpose: Explicitly
Return A Random Number such that Low <= RandNo <= High.
//
//
//
// Required Include Headers
: <stdlib.h>
//
// Recommended Support
Modules: none
//
//
//
// Written By: Dr. Thomas
E. Hicks
Environment:Linux //
// Date: 9/17/01
Compiler: C++
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//You Do --> Leave two blank
lines at the bottom of each function to separate it from others
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//
Delay
//
//
//
// Purpose: Simply stall
or delay the computer for the desired number of seconds. This
//
//
module can be used to enable the user to read output on the console.
//
//
//
// Required Include Headers:
<time.h>
//
// Required Support Modules:
none
//
// Recommended Support
none
//
//
//
// Written By: Dr. Thomas
E. Hicks
Environment:Linux //
// Date: 9/17/01
Compiler: C++
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////void Delay (long int NoSeconds)
{
time_t
CurrentTime;
CurrentTime = time ((time_t *) NULL);
while (time ((time_t *) NULL) < CurrentTime + time_t(NoSeconds))
{
}
} |