# 代做Assignment 3程序设计、代写program编程

- 首页 >> Algorithm 算法

Assignment 3
Assignment 3 includes a bonus problem. If you complete the bonus problem you may receive up to
140/100 points before the normal early submission bonus is applied. This code should be written in
C++, but you may include the C stdio.h to do your input and output.
It will be easier for you to complete this assignment using the Visual Studio IDE (in WINDOWS). This
will allow you to create a project and include all the code files provided so the IDE will compile for
you. We will grade this assignment using the Windows Visual Studio IDE available in CSIL. A tutorial
on using Visual Studio (not visual studio code) will be posted soon after the assignment. If you work
on the command line you will need to be sure each class is compiled separately then linked into the
final executable when you compile and link the main program, You will need to use the make.
PROBLEM 1: (40 points)
Will be added by 10PM JULY 24
PROBLEM 2 WRITING CLASS TRIANGLE (60 points)
Your will write part of a class named Triangle that can be used to build Triangle objects (that represent
equilateral triangles) that you can display graphically. Your Triangle class is defined in the provided file
Triangle.h. You are also provided with a file Triangle.cpp which includes some of the methods listed
below. DO NOT CHANGE the file Triangle.h or the provided methods in Triangle.cpp. The
attributes and methods defined for class Triangle are described below.
sideLength an int that holds the length of each side of the Triangle. The length of the
side is measured as a number of pixels
xLocation an int that holds the x coordinate of the upper left hand corner of the
Triangle (left end of the base of the triangle)
yLocation an int that holds the y coordinate (in pixels) of the upper left hand corner
of the Triangle (left end of the base of the triangle)
trianglesCreated an int that counts how many Triangles have been created in the
application
trianglesExisting an int that counts how many Triangles are presently in existence in the i
application (does not include Triangles that have been destroyed)
triangColour an object of type Colour (the Colour class is provided for you) that holds
the Colour that the plotted Triangle will have
In addition your class should have the following constructors and public member functions. The
prototypes for all the following functions are given in the class definition provided for you in file
Triangle.h. You must use the file Triangle.h as part of your class.
 Default constructor (sets private member sideLength to 10 and members xLocation and yLocation
to 0, increments counters, sets triangColour to black (0, 0, 0,255)
 Constructor that initializes sideLength, xLocation, yLocation and triangColour to the provided values
of the corresponding actual arguments in the constructor call. It also increments both counters and
checks the triangles are completely on the page.
 Constructor that initializes xLocation, yLocation and triangColour (also increments both counters,
sets sideLength and to 10, and checks that the whole triangle is on the page
 Copy constructor
 Destructor
 Accessor functions to access each of the private members
 An overloaded print function which prints the values of each private member in the Triangle Class.
(use same format as you did for the Rectangle class). Print the attributes of Triangle in the order the
definitions of the attributes are listed above.
 Mutator functions to set each of the private members (to set the values of each of the private
variables from outside the class). When changing values or sideLength, xLocation or yLocation make
sure that the triangle remains on the page.
 void member function TriangleDivide. TriangleDivide creates three sub-Triangles of the Triangle.
Each of the sub-Triangles is stored in an array of Triangles that is passed to the method (the array of
Triangles is created before the Divide method is called). The image below indicates the sub-Triangles
that should be stored. All sub triangles are of equal size and are equilateral triangles. The red
triangles are the sub-Triangles to be stored. The original equilateral triangle that was divided is
shown in blue in the adjacent image.
The array of Triangles passed into Triangle divide must be at least 3 elements long but may be longer.
The function is called by an object of the triangle class, the Colour of the sub-triangles should be the
Colour of the Triangle object calling the function. The sub-triangles all lie inside the Triangle object
that calls this function. This function should write (or overwrite) the attributes for the three subtriangles into the first three elements of the array pointed to by the pointer that is an argument of the
function.
 overloaded operators, =, = = and <<
1. The << operator should produce the same output as the print function
2. The assignment operator should copy all values of variables.
3. The comparison operator (= =) should make sure that the values of all variable members of the
classes are identical. If any one variable member is not the same in both objects being
compared the objects are not equal.

sub Triangles in red Original Triangle in blue
You have been given a main program to partially test the class Triangle in the file triangleTest.cpp. This
series of tests produces the outputs shown below (with the tables describing each). This will test most
of the possible problems with your triangle class, I do not guarantee that the tests supplied will test for
all possible problems we will check for when we grade. I am providing the complete file rather than
making you write most of it to make your development more manageable due to the short time available
for this assignment. A file, triangleTestOut.txt, that describes the printed output you should generate in
the program window has also been added to the posted list of files. The project will not compile unless
you write the needed parts of Triangle.cpp, so to get started you can write methods that only print a
short message and return. Then you can fill in the actual bodies of the methods one by one. Remember
you have the solution for the rectangle class in lab 10 to refer to as a model. Your triangle class must
detect and correct Triangles that are off or partially on the page. Your class must detect and correct both
Triangles off the page when created using a constructor and Triangles off the page after being changed
by a mutator. Your submitted programs will not be tested with your test code. We will run your code
for your classes using our own test code. This means you need to read the specification carefully and use
the definition of the class without changing it to be sure that your code will work with our test functions.
As addition help in debugging your classes should produce the images below if the rectangles and
triangles specified are created and plotted.
colour xLocation yLocation width
T10 Red 610 823 300
T11 Black 100 -5 230
T12 Grey -5 100 190
T13 Dark
Blue
400 50 300
T14 Grey 300 700 230
T15 Purple 450 680 210
T16 Light
Blue
300 300 400
Test Triangle divide (Dark Blue T17 partially
visible under grey sub-triangles)
T17 Dark
Blue
10 350 300
Sub1 Grey 10 350 150
Sub2 Grey 160 350 150
Sub3 Grey 85 479 150
Purple Triangle at lower right becomes
purple triangle at upper left when xLocation
is changed to 650
Purple Triangle at upper left becomes purple
triangle at lower left when xLocation is
changed to 150 then yLocation to 650 then
sideLength to 350
colour xLocation yLocation sideLength
T1 Dark
Blue
225 520 120
T2 Black 240 580 50
T3 Red 150 300 375
T4 Grey 90 400 210
T5 Light
blue
195 540 230

BONUS PROBLEM: WRITING CLASS GASKET (40 points)
Your will write part of a class named Gasket that can be used to build Gasket objects (that represent
Gasket.h. DO NOT CHANGE the file Gasket.h. The attributes and methods defined for class
 sideLength an int that holds the length of each side of the Gasket. The length of the side is
measured as a number of pixels
 xLocation an int that holds the x coordinate (in pixels) of the upper left hand corner of the
Gasket (left end of the base of the largest triangle in the Gasket)
 yLocation an int that holds the y coordinate (in pixels) of the upper left hand corner of the
Gasket (right end of the base of the largest triangle in the Gasket)
 iterations The number of iterations. One iteration consists of dividing each triangle in the
list of triangles in the gasket into parts using TriangleDivide.
 gasketColour an object of type Colour (the Colour class is provided for you) that holds the
colour that the plotted Triangles in the Gasket will have
 lenSubTriList an int that holds the number of triangles in the array of Triangles that are
 listOfSubTriangles a pointer to a Triangle (to be used for dynamically allocation the array of
Triangles of length lenSubTriLIst)
In addition your class should have the following constructors and public member functions. The
prototypes for all the following functions are given in the class definition provided for you in file
 Default constructor (sets private member sideLength to 100, members xLocation and yLocation and
iterations to 0, members lenSubTriList to 1 and allocates the dynamic memory for an array containing
1 triangle. The default constructor sets gasketColour to black (0, 0, 0.255)
 Constructor that initializes iterations, sideLength, xLocation, yLocation and gasketColour to the
provided values of the corresponding actual arguments in the constructor call. This constructer
calculates the length of the list of Triangles needed and allocates an array large enough to hold all
triangles at the iteration given by the value of the iterations member. The constructor builds the
 Copy constructor
 Destructor
 Accessor functions to access private members xLocation, yLocation, iterations, sideLength and
 Mutator functions to access private members xLocation, yLocation, iterations, sideLength and
 An overloaded print function which prints the values of each private member in the Gasket Class. (use
same format as you did for the Rectangle class). This function also prints each Triangle in the Gasket.
 Member function GasketDisplay. You can create this function without directly calling the bitmap
library. You need to print each triangle in the Gasket using the TriangleDisplay function
The results expected are shown below for some values of the number of iterations. Member function
GasketDivide takes the list of triangles for iteration n-1 and divides each of them into 3 triangles using
TriangleDIvide. This makes a new list of Triangles for iteration n
The array of triangles passed to the GasketDivide function must be at least 3 times longer than the list
of triangles to be divided. When GasketDivide has completed the array of Triangles will hold a list of
triangles containing 3 times as many triangles.

iteration 1 iteration 2 iteration 3 iteration 4
When you implement the methods in the Gasket class make sure that your Gasket objects remain on the
page by checking the values using the same rules as presented above for Triangles in the Triangle class
or in the already provided mutator functions. If the gasket is moved because xLocation or yLocation is
off the page print an error message telling the user their Gasket has been moved. If the size of the gasket
is modified so the Gasket does not extend off the page print an error message telling the user their
You also need to test the Gasket class. To reduce the amount of coding for this assignment a
gasketTest.cpp file has been provided. This test file will produce the plots shown above and the two
plots shown immediately below. Running the test file will also produce an output. The expected output
is shown in the provided file gasketOutput.txt. If you wish you can also implement the tests originally
provided which are still given at the bottom of the assignment.

colour xLocation yLocation sideLength iterations
G1 Black Default
G2 Light
Blue
150 200 400 0
G3 Grey 350 480 300 1
G5 Dark
Blue
250 700 200 1
G6 Red 666 200 200 0
G7 Light
blue
100 888 150 0