1. Use the following class declarations. Write the complete description of all functions so that the program creates the following I/O
class POINT
{ private: int x, y;
public: /1 constructor to set x,y of each vertex to ZERO
POINT ();
// member to read x and y coordinate of each vertex
void ReadData(char vertex);
// display the ( x, y) of a given vertex
void Display( char vertex);
// friend to compute the distance between vertices p(x,y) and q(x,y)
friend float Distance(POINT p, POINT q);
// Compute and display the perimeter of ABCD
friend void DisplayPerimeter( float AB, float AC, float CD, float BD); //destructor to release all memory used by objects in the program
˜Two();
};
Sample I/O
For rectangle ABCD:
Enter the x and y coordinates of vertex A: 10 7
Enter the x and y coordinates of vertex B: 20 7
Enter the x and y coordinates of vertex C: 10 2
Enter the x and y coordinates of vertex D: 20 2
A(10.00,7.00)------------------------ B(20.00,7.00)
C(10.00,2.00)------------------------- D(20.00,2.00)
AB= 10.00
AC=5.00
CD=10.00
BD=5.00
Perimeter =30.00
Hint. Part of the main function should look like this
Int rnain()
{ POINT A, B, C, D; //create 4 objects and initialize their x and y
cout<<"For the rectangle ABCD:\n";
A.ReadData('A');
//draw the rectangle
A. Displayr('A'); cout<<"...............................";B.Display('B'); cout«endl;
//compute the length of each side
float AB = Distance (A,B); cout <<"\t AB=" <
//compute and display perimeter
DisplayPerimeter(AB, AC, CD, BD);
//terminate program
return 0;
}
class Two
{
private: int age[5];
public: // read data into array age void ReadData();
// friend to return the average of data in array age of object p friend int FindAverage (TWO p );
//member to find and return the max and min age
void FindMaxMin( int& maxAge, int& minAge); //display ages>age average
Void DisplayAboveAve( int ageAve);
//display the max and min ages
void DisplayMaxMinAge(int maxAge, int minAge);
//release all memory used by objects
~TWO() {}
};
Write all members and friends after the main
a. Write the main to produce the given I/O
3. Given the following class declarations
class THREE
{ private: int a[5];
public: void CopyData(string fname) ; //copy data from file into array a
void SortArray (); //sort the array a of the object activated this member
void DisplayArray();//display the array a of the object activated this member
~THREE();
};
And the following three files. (a) convert the class to a class template to receive the type and the size of array a. Describe all members after class. (b) we want to display the sorted form of each file by (i) coping data from the file into array a, 90 sort array a, 9iii) display the sorted form of array a
Filel.txt
25 50 13 77 9
|
File2.txt
Mary John Adam Bill Jack
|
File3.txt
C OR NE
|
|
|
|
Output
|
|
|
This is the sorted form of Filel.txt
9 13 25 50 77
|
This is the sorted form of File2.txt
Adam..... ........ ........ .........
|
This is the sorted form of File3.txt C E .....
|
|