首页 > > 详细

C辅导 HW4 Shapes W2017讲解C/C++设计

Introduction

#ifndef COLLECTION_H
#define COLLECTION_H
#include
#include”Shape.h”
#include”Square.h”
#include”Diamond.h”
using namespace std;
class Collection
{
private:
int lowest_X; //range
int lowest_Y;
int highest_X;
int highest_Y;
vector Shape_List; //the list of shapes
public:
Collection(int _lx,int _hx,int _ly,int _hy);
void addShape(Shape tmp);
void display();
int totalStars();
void moveBy(int _x,int _y);
void setSize(int _size);
};
#endif
:Collection.cpp Collection.h Diamond.h Diamond.cpp Shape.cpp Shape.h Square.cpp Square.h
Requirement
HW4_Shapes_W2017
PIC 10B Section 1 - Homework # 4 (due Friday, February 10, by 9 am)
You should upload each .cpp and .h file separately and submit them to
CCLE before the due date/time! Your work will otherwise not be considered
for grading. Do not submit a zipped up folder or any other type of file besides
.h and .cpp.
Be sure you upload files with the precise name requested of you and that it
matches the names you used in your editor environment otherwise there may
be linker and other errors when your homeworks are compiled on a different
machine. Also be sure your code compiles and runs on Visual Studio 2015.
LOW BUDGET GRAPHICS
In this homework, you’ll get to work with polymorphism and apply it to some very low-
budget graphics. The implementation that you choose is somewhat up to you provided it
conforms to the functionality described below. In the end, you will submit 4 or 5 files:
Collection.h, Shape.h, Square.h, and Diamond.h. You can also upload a .cpp
file with the implementations of these classes separately or implement the classes within
the header files.
Conventions: this problem is about plotting a Collection of Shapes. Each shape is
made up of a discrete set of points at specific x- and y-values. A Collection will only
display and count the points corresponding to Shapes it stores that are within its x- and
y-ranges. The x-positions increase as we move right (increase in column number); and
the y-positions increase as we move down (increase in row number).
Okay, now that we’ve established this, let’s consider the classes. The following is the
bare minimum necessary for you to understand what is required, but you may need to
add further functions, specifications, or variables than those specified.
1
The Collection class should
• have a constructor accepting 4 int inputs that respectively denote the lowest x-
position, the highest x-position, the lowest y-position, and the highest y-position
over which the class should display in its window;
• have an addShape function that when provided with a Shape object, adds it to
the collection;
• have a display function to display its shapes only on the appropriate range of x- and
y-values, from the lowest to highest values inclusive, printing ‘*’ if there is a shape
point present and ‘-’ if there is no shape point present; following this, it should list
the shape types, in order, within the vector, and this function must make use
of dynamic cast;
• have a totalStars function to return the total number of stars that are within the
plot range;
• have a moveBy function taking two arguments, the first describing how much to
move all shapes in the x-direction and the second describing how much to move all
shapes in the y-direction; and
• have a setSize function taking a single argument and setting the size property of
all shapes.
The Shape class should:
• have a constructor accepting three parameters that respectively denote the shape’s
x- and y-position and size;
• have a purely virtual function setStars that resets the values of the coordinates
storing a shapes location should it be moved or resized;
• have a moveBy function accepting two int inputs that respectively denote how
much to move the shape’s centre in the x- and y-directions, respectively, and which
invokes setStars; and
• have a setSize function accepting an input for the new size parameter that invokes
setStars afterwards.
The Square class should:
• have a constructor accepting three parameters: the first two representing its x- and
y-position (and for the square this denotes its top left position) and the third repre-
senting its size (and for the square this is the number of stars for its height/width).
The Diamond class should:
• have a constructor accepting three parameters: the first two representing its x- and
y-position (and for the diamond this denotes its centre) and the third representing
its size (and for the diamond this is the number of stars from its centre point to its
top inclusive).
Note that the Diamond class looks like a diamond and it is symmetric about its
centreline (see the output figure).
An example set of code and output are given below: your actual homework will be
graded against a different .cpp file. Do not submit a main routine!
You may assume the user will only enter valid parameters and use the function names
consistent with this homework.
Note below that only stars that are with an x-position from 0 to 10 inclusive and a
y-position from 0 to 10 inclusive are plotted. That’s why sp3, which overlaps a little with
sp1, only appears as 3x3, not 4x4.Hints:
• You may wish to include helper member function in Collection that returns a bool,
true if there is a star present and otherwise false, when given an x- and y-position.
• Although not required, you may wish to use the template class std::pair, which
is found in the header. Look this up, if you haven’t seen pairs before;
it’s easy to use, and a std::vector of them could be useful, depending on your
implementation.

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!