//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///
Computer2.cpp
//
///
//
/// Purpose
: House all non-template methods for class Computer.
//
///
House function TestComputer(void).
//
///
//
/// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
/// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///---------------------------
Includes ----------------------------------
# include "Computer2.hpp"
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
Constructor Method Computer
//
//
//
// Purpose : Constructors for
Class Computer. Set Name to NewName and No to //
//
NewNo. Default NewName = blank. Default NewNo =
//
//
For purposes of teaching students the scope of Computer object
//
//
life and which overloaded constructor is being called, include an
//
//
output line such as the following:
//
//
puts ("Evoking Constructor Computer (NewName[], NewNo)");
//
//
Comment out the line once the constructor and destructor
//
//
methods are verified for accuracy.
//
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//
//
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
Computer::Computer (char NewName[],
int NewNo, long int NewRamMB,
long int NewHardDriveGB)
{
// puts ("Evoking Constructor
Computer (NewName, NewNo)");
// You Do!
}
Computer::Computer (int NewNo,
char NewName[], long int NewRamMB,
long int NewHardDriveGB)
{
// puts ("Evoking Constructor
Computer (NewNo, NewName)");
// You Do!}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
Destructor Method ~Computer
//
//
//
// Purpose : Delete the Computer
Object. No Destructor for this class is really //
//
required. It is included only to teach students about the scope
//
//
of an objects life. An attempt is made to make all code platform
//
//
independent. Some C++ compilers generate an error message any time //
//
a module has no lines of executable code; perhaps understandable.
//
//
Once a student understands the scope of a Computer object life,
//
//
the output line shall be commented out; this would leave a module
//
//
with no executable lines of code. To prevent this error, a
//
//
dummy integer variable, called DummyVariable is created and
//
//
initialized to 1 for compatability.
//
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
Computer::~Computer (void)
{
int
DummyVariable = 1;
// puts ("Evoking Destructor
Computer(void)");
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
Method Display
//
//
//
// Purpose : Display Name on
line 1, No on line 2, and blank on line 3.
//
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
void Computer::Display (char
Message[])
{
if (strlen (Message)
> 0)
puts(Message);
// You Do!
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
Method Display40
//
//
//
// Purpose : Display the most
important 40 characters of the structure.
//
//
No line feed.
//
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
void Computer::Display40(void)
{
// You Do!
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
Method Display50
//
//
//
// Purpose : Display the most
important 50 characters of the structure.
//
//
No line feed.
//
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
void Computer::Display50(void)
{
// You Do!
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
Method Set
//
//
//
// Purpose : Set Name to NewName
and No to NewNo. Default NewName = blank.
//
//
Default NewNo = 0.
//
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
void Computer::Set(char NewName[],
int NewNo, long int NewRamMB,
long int NewHardDriveGB)
{
// You Do!
}
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
char operator Overloads
//
//
//
// Purpose : Overload the operators
in such a way that the Name becomes the //
//
primary character key for the Computer Class. These methods enable //
//
the programmer to compare a Computer object with a character string//
//
for purposes of sorting and/or searching.
//
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// You Do!
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
Computer operator Overloads
//
//
//
// Purpose : Overload the operators
in such a way that the Name becomes the //
//
primary Computer key for the Computer Class. These methods enable
//
//
the programmer to compare a Computer object with another Computer
//
//
Object for purposes of sorting and/or searching.
//
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// You Do!
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
int operator Overloads
//
//
//
// Purpose : Overload the operators
in such a way that the No becomes the
//
//
primary long integer key for the Computer Class. These methods
//
//
enable the programmer to compare a Computer object with a long
//
//
integer for purposes of sorting and/or searching.
//
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// You Do!
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
Overload << Operator
//
//
//
//Purpose : Display the 40
characters that represent this Computer datatype. //
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// You Do!
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//
Function TestComputer
//
//
//
//Purpose : Test each and every
method in class Computer.
//
//
//
// Written By : Dr. Thomas
E. Hicks
Environment : Windows NT //
// Date
: 11/11/00
Compiler : Visual C++ //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
void TestComputer(void)
{
puts ("-----------------
Beginning of Procedure Test------------------------\n");
puts ("*************
Testing Constructor - Delcalre 1 Computer **********************\n");
Computer
Computer1;
///Declare one
puts ("\n*************
Testing Display Method [verifies constructor init] ********\n");
Computer1.Display();
puts ("\n*************
Testing Set Method****************************************\n");
Computer1.Set("Mac",
22);
Computer1.Display();
puts ("\n*************
Display40 by boxing in the informatin *****************\n\n");
puts ("| 1234567890123456789012345678901234567890
|");
puts ("--------------------------------------------");
printf ("| ");
Computer1.Display40();
puts (" |");
puts ("--------------------------------------------\n");
puts("\n*************
Display50 by boxing in the informatin *****************\n\n");
puts ("| 12345678901234567890123456789012345678901234567890
|");
puts ("-------------------------------------------------------");
printf ("| ");
Computer1.Display50();
puts(" |");
puts("-------------------------------------------------------\n");
puts("\n*************
Testing Constructor - Delcalre An Array of 4 Computers\n");
Computer
Computers[4];
puts("\n*************
Overload << operator *********************************\n\n");
Computer
Mac;
Mac.Set ("Mac",222,
128, 45);
Mac.Display();
puts ("| 1234567890123456789012345678901234567890
|");
puts ("--------------------------------------------");
printf ("\n| ");
cout.flush();
cout <<
Mac;
cout.flush();
puts(" |\n\n");
puts("\n*************
char Overload operator *******************************\n\n");
Computer
Computer5,
Computer3;
Computer5.Set ("Dell",
1111);
Computer5.Display("Info
Stored In Computer5:");
if (Computer5
== "Dell")
puts("Computer.Name == 'Dell'");
else
puts("Computer.Name != 'Dell'");
if (Computer5 ==
" DELL ")
puts("Computer.Name == ' DELL '");
else
puts("Computer.Name != ' DELL '");
if (Computer5 ==
"Mac")
puts("Computer.Name == Mac");
else
puts("Computer.Name != Mac");
Computer5.Set ("CCC",
3);
if (Computer5
== "AAA")
// Test = Char
puts("True ---> CCC = AAA");
else
puts("False --> CCC = AAA");
if (Computer5
> "AAA")
// Test > Char
puts("True ---> CCC > AAA");
else
puts("False --> CCC > AAA");
if (Computer5
>= "AAA")
// Test >= Char
puts("True ---> CCC >= AAA");
else
puts("False --> CCC >= AAA");
if (Computer5
< "AAA")
// Test < Char
puts("True ---> CCC < AAA");
else
puts("False --> CCC < AAA");
if (Computer5
<= "AAA")
// Test <= Char
puts("True ---> CCC <= AAA");
else
puts("False --> CCC <= AAA");
if (Computer5
!= "AAA")
// Test != Char
puts("True ---> CCC != AAA");
else
puts("False --> CCC != AAA");
Computer5.Display("Contents
of Computer5"); // Test = Char
Computer5 = "GolfBall";
Computer5.Display("New
Contents of Computer5");
puts("\n*************
int Overload operator *******************************\n");
Computer5.Set
("CCC", 3);
if (Computer5
== 5)
// Test = Integer
puts("True ---> 3 == 5");
else
puts("False --> 3 == 5");
if (Computer5
> 5)
// Test > Integer
puts("True ---> 3 > 5");
else
puts("False --> 3 > 5");
if (Computer5
>= 5)
// Test >= Integer
puts("True ---> 3 >= 5");
else
puts("False --> 3 >= 5");
if (Computer5
< 5)
// Test < Integer
puts("True ---> 3 < 5");
else
puts("False --> 3 < 5");
if (Computer5
<= 5)
// Test <= Integer
puts("True ---> 3 <= 5");
else
puts("False --> 3 <= 5");
if (Computer5
!= 5)
// Test != Integer
puts("True ---> 3 != 5");
else
puts("False --> 3 != 5");
Computer5.Display("Contents
of Computer5"); // Test = Integer
Computer5 = 21;
Computer5.Display("New
Contents of Computer5");
puts("\n*************
Computer Overload operator ***************************\n");
Computer5.Set
("Apple", 55);
Computer3.Set
("NEC", 22);
if (Computer5 ==
Computer3)
// Test == Computer
puts("True ---> Apple = NEC");
else
puts("False --> Apple = NEC");
if (Computer5 >
Computer3)
// Test > Computer
puts("True ---> Apple > NEC");
else
puts("False --> Apple > NEC");
if (Computer5 >=
Computer3)
// Test >= Computer
puts("True ---> Apple >= NEC");
else
puts("False --> Apple >= NEC");
if (Computer5 <
Computer3)
// Test < Computer
puts("True ---> Apple < NEC");
else
puts("False --> Apple < NEC");
if (Computer5 <=
Computer3)
// Test < Computer
puts("True ---> Apple <= NEC");
else
puts("False --> Apple <= NEC");
if (Computer5 !=
Computer3)
// Test != Computer
puts("True ---> Apple != NEC");
else
puts("False --> Apple != NEC");
Computer5.Display("New
Contents of Computer5");
Computer3.Display("New
Contents of Computer3");
Computer5 = Computer3;
// Test = Computer
Computer5.Display("New
Contents of Computer5");
Computer3.Display("New
Contents of Computer3");
puts("\n*************
The destructor will be called 6 times when exiting *******");
puts("-----------------
End of Procedure Test------------------------");
} |