In this project you will get to create a complete class of objects, use and create a template, and use several helper files of your own making. The main function is provided for you, as is the data file, a class definition, and one template. As you can tell, fitting together what you write and what I have written for you is a little more complicated than for previous projects.
The main function is designed to do something fairly simple. It first reads in four groups of numbers. The first group contains integers; the second contains doubles, the third contains complex numbers; and the fourth contains very large positive integers. Then, main calls upon the InsertionSort function to sort each of the groups. Finally, main calls upon the MedianRange function to display the lowest, median, and highest number (and their sum) for each group. Each group has fewer than 50 values.
The following files are available in O:\JLW\310 or L:\JLW\310 or from 310LIB:
P3MAIN.CPP Contains the "include" list and the main function.
CPLEX.H Helper file containing the cplex class definition and the member functions (like the complex class) shown in class,
plus a member function for operator<
INSSORT.H Helper file that contains the InsertionSort template from chapter 3 in the book.
MIXEDNOS.DAT The data file for the main function.
Your job is to create a file named P3.H that contains:
bigint class
The complete object declaration and member functions needed to declare, input, output, sort, and add very large
positive integer values. Numbers that are in the bigint class are whole numbers that may be up to 40 digits long and are to be
maintained exactly (that is, no accuracy may be lost in dealing with these values).
MedianRange
A template function that expects to receive a sorted array and the number of elements it has as arguments and displays the first element, median element, last element, and the sum of these three numbers in a nicely formatted form. MedianRange does not return any result. Note: if a sorted array has N elements; the median is at element N/2.
Suggestion: First, put these elements into a .CPP file and compile it until there are no errors. Then, rename the file P3.H.
To fully test your helper file, compile and run P3MAIN. You will need to change the INCLUDE file path for Turbo C++ - attach ;A:\ to the end of the INCLUDE list. (Make the change in the Directories section under Options.) Visual C ++ version 4.0 does not require any adjustment for this project. Visual C++ 1.52 cannot be used for project 3; it does not understand templates. When you finish, hand in a diskette with P3.H on it.
Below is a complete listing of P3MAIN.CPP
#include#include #include "cplex.h" #include "inssort.h" #include "p3.h" void main (void) { int intarray[50]; // Integer array double dblarray[50]; // Double array cplex cplexarray[50]; // Complex array bigint bigarray[50]; // Big number array int icount, // Number of integers dcount, // Number of doubles ccount, // Number of complex values bcount; // Number of bigint values fstream f; // File istream object int j; // Loop control variable char fname[30]; // File name cout << "Enter the data file name: "; cin >> fname; f.open (fname, ios::in); // Open the data file if (f.fail()) { cout << "Problem opening file\n"; return; } f >> icount; // Read integers for (j = 0; j < icount; j++) f >> intarray[j]; f >> dcount; // Read doubles for (j = 0; j < dcount; j++) f >> dblarray[j]; f >> ccount; // Read complexes for (j = 0; j < ccount; j++) f >> cplexarray[j]; f >> bcount; // Read bigint numbers for (j = 0; j < bcount; j++) f >> bigarray[j]; f.close(); InsertionSort (intarray, icount); // Sort each array InsertionSort (dblarray, dcount); InsertionSort (cplexarray, ccount); InsertionSort (bigarray, bcount); cout << "\nFor the integer values:\n"; // Output low, median, and MedianRange (intarray, icount); // high for each array cout << "\nFor the double values:\n"; MedianRange (dblarray, dcount); cout << "\nFor the complex values:\n"; MedianRange (cplexarray, ccount); cout << "\nFor the big values:\n"; MedianRange (bigarray, bcount); }