Print Name  ___________________

                                                                                                                            Signature   ___________________
 
 

   Computer 2 Operator Overload Lab
Individual Assignment
 10 Points


Set Netscape Margins [ Left = 1; Right =. 2; Top =. 4; Bottom = .4; Select Document Title,  Page Number, Page, Black Text, Black Lines]
1] You must use Microsoft Visual C++ for this lab.

2]  Add this class to your  Project, called DLList assume in C:\Temp\DLList

3]  Create file Computer2.hpp; add it to your project.
 

//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//                                 Computer2.hpp                                //
//                                                                              //
//  Purpose    : House includes, defines, class definitions, function           //
//               prototypes, and all template methods.                          //
//                                                                              //
//  Written By : Dr. Thomas E. Hicks                  Environment : Windows NT  //
//  Date       : 11/11/00                             Compiler    : Visual C++  //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////

# ifndef COMPUTER_CLASS //========================================================

// ----------------------------------- Includes ----------------------------------
# include <stdio.h>
# include <iostream.h>
# include <iomanip.h>
# include <string.h>
# include "Utilities.hpp"

// ----------------------------------- Defines -----------------------------------
# define COMPUTER_CLASS

//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//                                     Class Computer                           //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
class Computer
{
public:
   Computer (char NewName[] = "", int NewNo = 0, long int NewRamMB = 0, 
             long int NewHardDriveGB = 0);
   Computer (int NewNo, char NewName[] = "",  long int NewRamMB = 0, 
             long int NewHardDriveGB = 0);
   ~Computer (void);
   void Set (char NewName[] = "", int NewNo = 0, long int NewRamMB = 0, 
             long int NewHardDriveGB = 0);

   void Display(char Message[] = "");
   void Display40(void);
   void Display50(void);

   friend ostream & operator << (ostream & OutputStream, Computer C);

   // I have decided that Name is to be the Primary Character Key for this record type. 
   bool operator == (const char Key[]);
   bool operator >  (const char Key[]);
   bool operator >= (const char Key[]);
   bool operator <  (const char Key[]);
   bool operator <= (const char Key[]);
   bool operator != (const char Key[]);
   void operator =  (const char Key[]);

// I have decided that No is to be the Primary Integer Key for this record type. 
   bool operator == (const long int Key);
   bool operator >  (const long int Key);
   bool operator >= (const long int Key);
   bool operator <  (const long int Key);
   bool operator <= (const long int Key);
   bool operator != (const long int Key);
   void operator =  (const long int Key);

// I have decided that Name is to be the Primary Key for this record type. 
   bool operator == (const Computer & C);
   bool operator >  (const Computer & C);
   bool operator >= (const Computer & C);
   bool operator <  (const Computer & C);
   bool operator <= (const Computer & C);
   bool operator != (const Computer & C);
   void operator =  (const Computer & C);

private:
   char 
      Name [26];
   int
      No;
   long int
      RamMB, 
      HardDriveGB; 
};

// ------------------------- Non-Class Functions Prototypes-----------------------
void TestComputer(void);

# endif // COMPUTER_CLASS ========================================================

4] Create file Computer2.cpp; add it to your project. It  should resemble the following.
 

//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///                               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------------------------");
}

5] Use the following Program Main.cpp
 

#include <iostream.h> 
#include "Utilities2.hpp" 
#include "Part2.hpp" 
# include "Computer2.hpp" 

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

   puts("############################### Start of Main #####################");
   puts("                          Computer - Operator Overloads");
   puts("                                    written by             ");
   puts("                                       ????                \n\n");
   fflush(stdout);
// TestPart();
   TestComputer();
   cout.flush();
   puts(" \n ++++++++++++++++++++++ End of Main +++++++++++++++++++++ \n\n");
   return 0; 

6] Add all missing code.

7] Before printing programs for the remainder of the semester,  do the following:

File-Page Setup
Header is to be :  &C&F  -  Your Name  -  &D
Footer is to be :  &C - &P -
Margins : Left = 1.25,  Right = .5, Top = .5, Bottom = .5
OK

Tools->Options
Select Format Tab -- [on far right!]
Category - All Windows [on left]
Font Courier New 8 point [on right]
OK

7] Print your program output!
Start->Run->Command  (if Windows 95/98/2000)    or   Start->Run->cmd  (if Windows NT)
Enter the following in the DOS command window:
C:
cd \Temp\DLList\Debug
DLList  > Output.txt

8] Follow the directions for printer page setup. Print a copy of the following files :  Computer.hpp, Computer.cpp. Delete the temporary files in the Debug folder.

9] Copy program DLList.exe to a blank floppy disk. Put your name on the disk label. Copy folder DLList, with all of the project components, to the floppy disk.



10] Those Labs labeled "Individual Assignment" are to be done separately by each individual. Using a pen,  each individual is to print  his/her name at the top of this document in the space provided and sign it.  Those Labs labeled "Team Assignment" may be done as a team or individually. Using a pen,  each individual on the team is to print print his/her name at the top of this document in the space provided and sign it. Submit only one copy of team assignments!

Include the following in your wire-band binder:

A] Add Divider to back of Part Operator Lab

B] Copy of Computer2.hpp followed Computer2.cpp

C] Copy of this assignment sheetl.

D] A printed copy of  Output.txt from this program.

E] The floppy disk containing DLList