All of the work in this project is my own!  I have not left copies of my code in public folders on university computers. I have not given any of this project to others. I will not give any portion of this project to others taking this class. I realize that the penalty for turning in work that is not my own can range from an "F" in the class to dismissal from Trinity University. 

                                                                                             Print Name  __________________________

                                                                                              Signature   __________________________


Dynamic Array II Lab
Individual Assignment
40 Points


Set Netscape Margins [ Left = 1; Right = .2; Top = .6; Bottom = .6; Select Document Title, Location,  Page Number, Page Total Black Text l]


1]  Create a  program DynamicArray2.cpp

2] Class Shall be called IntArray. The first array element filled shall be element 1. Do not use element 0 at any time in this program! Keep the ActNo accurate at all times!
 

class IntArray
{
public: 
 IntArray(long int NewMax = 10);
 bool Empty (void);
 void Display(char Message[] = "", long int NoToDisplay = -999);
 void QuickAndDirtyDisplay (char Message[] = "");
 ~IntArray(void);
 void Initialize (void);
 void FillRandom(int NoToFill, int Low, int High);
 int Sum (void);     // Return 0 if empty!
 int High (void);   // Return 0 if empty!
 long double Average (void);  // Return 0 if empty!
 int Low (void);  // Return 0 if empty!
 void Stats(char Message[] = "");
 void BubbleSort (void);
 void FillFromFile (char FileName[]);
 long int BinarySearch (int SoughtKey);
// Return 0 if empty or not there!
 long int SequentialSearch (int SoughtKey);
// Return 0 if empty or not there!
private:
   long int
       Max,
       ActNo;
   int
       *Array;
};

3] You must make at least one of the two BubbleSort improvements!

4]  Fill from file, shall open the passed file and start filling the Array at element 1, until either there are no more numbers or until the quantity of numbers on the file has been exhausted. Provide an error message for the user if the passed file name is wrong! [See Sample Programs!]

5] The Sequential Search is to start by examining element 1 for the SoughtKey; if the value is found there, explicitly return 1. If not,  move on to element 2; if the value is found there, explicitly return 2. If not,  move on to element 3;etc. until you have exhausted the valid (ActNo) of elements. If the value is not found, return 0.

6] The Binary Search is to start by examining the middle element for the SoughtKey; if the value is found there, explicitly return the address/mid. If not,  look in either the top or bottom half of the array. If the value is not found, return 0.

7] Create only two datafile for this program!  Call them Data1.fil and Data2.fil. Do not create a Data3.fil!

8] Data1.fil shall contain the following data, 1 to a line:

90 100 80 70 60 10 20 50 40 30 0

9] Data2.fil shall be created, but Empty!

10] Data3.fil shall not exist!

11] Make up your own file Data4.fil; it shall contain at least 60 integer values.

12 Write a module, called TestInArray1, which shall do the following: Note the changes!

  1. Create an IntArray object, called Exams; pass it no arguments.
  2. Create an IntArray object called Bowling; pass it integer value 10.
  3. Create an IntArray object, called Nos; pass it integer value 100;
  4. Create an IntArray object, called BadNos; pass it integer value -30.
  5. Evoke the Display method with Exams; pass it "Original Exams" and 5;
  6. Evoke the Display method with Bowling; pass it "Original Bowling" and 5;
  7. Evoke the Display method with Nos; pass it "Original Nos" and 5;
  8. Evoke the Display method with BadNos; pass it "Original BadNos" and 5;
  9. Completely fill the Exam object with random values in the range  80-100.
  10. Evoke the Display method with Exams; pass it "Exams[10] with values 80-100";
  11. Fill 70% of the Nos object with random values in the range  -5 to +5
  12. Evoke the QuickAndDirtyDisplay method with Nos; pass it "Nos [70%] with values -5 to +5".
  13. Attempt to fill 500 of the Bowling object with random values in the range 100-200.
  14. Evoke the QuickAndDirtyDisplay method with Bowling; pass it "Bowling [500] with values -5 to +5".
  15. Attempt to fill -3 of the BadNos object with random values in the range 1-10;
  16. Evoke the Display method with BadNos; pass it "BadNos[-3] with values 1-10"
  17. Initialize the Exam object.
  18. Evoke the Display method with Exams; pass it "Initialized Exams".
  19. Initialize the Nos object.
  20. Evoke the QuickAndDirtyDisplay method with Nos; pass it "Initialized Nos".
  21. Initialize the Nos object.
  22. Fill 10 of the Nos object with random values in the range 1-100
  23. Write a line of code that will display "High Nos        = 87" {if 87 is High Value};
  24. Write a line of code that will display "Low Nos         = 22" {if 22is LowValue};
  25. Write a line of code that will display "Average Nos = 52.3" {if 52.31 is the mean/arithmetic average};
  26. Write a line of code that will display "Sum Nos         = 523" {if 523 is the Sum};
  27. Write a line of code that will call/evoke the Stats module for object Nos. Pass the Message "Statistics for Nos Object"

13] Write a module, called TestInArray2, which shall do the following: Note the changes!

  1. Create an IntArray object, called Exams; pass it no arguments.
  2. Create an IntArray object called Bowling; pass it integer value 5.
  3. Create an IntArray object, called Nos; pass it integer value 1000;
  4. Initialize the Exams object
  5. Write a line of code that will attempt to fill array Exams from file; pass it Data1.fil
  6.  Write a line of code that will call/evoke the Stats module for object Exams. Pass it "Exams Filled From Data1.fil".
  7. Initialize the Exams object.
  8. Write a line of code that will attempt to fill array Exams from file; pass it Data2.fil
  9. Write a line of code that will call/evoke the Stats module for object Exams. Pass it "Exams Filled From Data2.fil".
  10. Initialize the Exams object.
  11. Write a line of code that will attempt to fill array Exams from file; pass it Data3.fil
  12. Write a line of code that will call/evoke the Stats module for object Exams. Pass it "Exams Filled From Data3.fil".
  13. Initialize the Nos object.
  14. Write a line of code that will attempt to fill array Nos from file; pass it Data4.fil
  15. Write a line of code that will call/evoke the Stats module for object Nos . Pass it "Nos Filled From Data4.fil"

14] Do Something That Demonstrates Your Sorting & Searching Works: Possible Solution Might Be:

IntArray
  
Nos(1000);

Nos.FillFromFile("Data1.fil");
Nos.
QuickAndDirtyDisplay ("Unsorted Contents of Nos");

should have 90 100 80 70 60 10 20 50 40 30 0

cout << "Search For First [90] = " << Nos.SequentialSearch(90) << endl;
cout << "Search For Last [0] = " << Nos.SequentialSearch(0) << endl;
cout << "Search For Mid [80] = " << Nos.SequentialSearch(80) << endl;
cout << "Search For Mid [30] = " << Nos.SequentialSearch(30) << endl;
cout << "Search Not There [110] = " << Nos.SequentialSearch(110) << endl;
cout << "Search Not There [-3] = " << Nos.SequentialSearch(-3) << endl;
cout << "Search Not There [15] = " << Nos.SequentialSearch(-3) << endl;

Nos.BubbleSort ();
Nos.QuickAndDirtyDisplay ("Sorted Contents of Nos");

should have 0 10 20 30 40 50 60 70 80 90 100

cout << "Search For First [0] = " << Nos.BinarySearch(0) << endl;
cout << "Search For Last [100] = " << Nos.BinarySearch(100) << endl;
cout << "Search For Mid [80] = " << Nos.BinarySearch(80) << endl;
cout << "Search For Mid [30] = " << Nos.BinarySearch(30) << endl;
cout << "Search For Too High [110] = " << Nos.BinarySearch(110) << endl;
cout << "Search For Too Low [-3] = " << Nos.BinarySearch(-3) << endl;
cout << "Search For Not Mid 15] = " << Nos.BinarySearch(-15) << endl;

15] Each and every program file that you turn in this semester shall contain a documentation block at the top. Document yours!
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
///                            xxxxxxx.cpp                                      //
///                                                                             //
/// Purpose    :                                                                //
///                                                                             //
/// Written By : Dr. Thomas E. Hicks                  Environment : Linux       //
/// Date       : 9/10/00                              Compiler    : g++         //
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////

16] Have the main progrm call only TesArray1 module. The following line of code will execute your program and send the output to a file called Output.txt . Although you will not be able to see the prompts, enter the data specified above.

a.out > Output1.txt

17] Now change your main program to call only the TestArray2 module.

a.out > Output2.txt

g++ DynamicArray2.cpp -o MyFirstNameLastName <-- substitute your FirstLast name [all one word - capitalize the first letters! Jane Doe  would do the following:

g++ DynamicArray2.cpp -o JaneDoe

18] Mail me a copy of  the compiled binary file :

To: thicks@trinity.edu
Subject: ArrayLab II
cc: JaneDoe@trinity.edu   <===send a copy to your e-mail address
Body of Message: The Array Lab II Homework for Jane Doe is attached! substitute your name

Attachment : JaneDoe

I shall run your program with my data files!

19] Start Windows 2000/NT/98/95. Print your programs. Set the left margin to 1 " and the right margin to .5". Make the font Courier 10 or New Courier 10. Print DynamicArray2.cpp.  Print Output.txt.

20] Copy files DynamicArrays2.cpp and Output1.txt  and Output2.txt to a floppy disk.



21] 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] Divider

B] Copy of this assignment sheet. Using an ink pen, print your name and sign this lab at the top.

C] Listing  Output2.txt

D] Divider

E] Listing DynamicArrays2.cpp

F] Divider

G] Output2.txt Listing

H] Disk containing the files.