首页 > > 详细

C辅导、辅导C++、辅导讲解 ECS40 Winter 2017讲解留学生C/C++程序

Introduction

#include “Shape.h”
#include “Domain.h”
#include
#include
using namespace std;
Domain::Domain(int sx, int sy):size_x(sx),size_y(sy)
{
sList.clear();
}
void Domain::addShape(char type, int x, int y)
{
Shape tmp;
int i;
int n;
int flag=1;
tmp = Shape::makeShape(type,x,y);
if(fits(tmp))
{
n=sList.size();
for(i=0;ioverlap(tmp))
{
flag=0;
break;
}
}
if(flag==1)
{
sList.push_back(tmp);
}
else
{
delete tmp;
}
}
else
{
delete tmp;
}
}
bool Domain::fits(const Shape s) const
{
bool ans=true;
int i;
for(i=0;i=size_x||s.getY(i)=size_y)
{
ans=false;
break;
}
}
return(ans);
}
void Domain::draw(void) const
{
int i,n;
cout” output.svg
The fill program will be tested with various sizes in the range [1,15], and various seed values.
It is not necessary to test for incorrect values in the command line arguments.
You can use the fill executable with specific command line arguments, and compare your svg
output with svg output test files provided on the web site to check the functionality of your
classes. Note: the random numbers generated on different computers may differ even if the
same seed is used. Make sure to generate and compare your output on the CSIF computers.
Make sure that your program reproduces the test output exactly. Use the diff command to
compare your files with the example files. Other command line arguments will also be used
when grading your implementation. The example files are generated using the following naming
convention. For example:
$ ./fill 12 10 2 > test_12_10_2.svg
Modifications of the Shape class
The Shape class should have the following features in addition to the ones defined in HW2 (see
the file Shape.h)
Additional public members of the Shape class
virtual const char color(void) const = 0
A pure virtual member function returning a C-style. string (such as e.g. “red” or “blue”) that
defines the color of the shape. The strings returned by the function should be as follows:
O cyan
I yellow
L purple
S blue
X orange
U red
int getX(int i) const
Returns the x coordinate of cell i of the shape. It is assumed that the value of the argument is
valid.
int getY(int i) const
Returns the y coordinate of cell i of the shape. It is assumed that the value of the argument is
valid.
void draw(void) const
A function that prints on stdout a sequence of statements that represent the shape in the
scalable vector graphics (svg) format. The output should consist of multiple lines, each line
representing one of the cells of the shape. Each cell should be drawn as a square of side 40
pixels, filled with the shape’s color. For example the draw() function called by a ‘S’ shape
located at position (4,2) should output the following four lines:
Specification of the Domain class
The Domain class is responsible for managing the shapes added to the domain. It has a member
function addShape which adds a shape to the domain after checking that the new shape fits
inside the domain area and does not overlap with any of the previously added shapes.
public members of the Domain class
Domain(int size_x, int size_y)
Constructor taking as arguments the horizontal and vertical size of the domain, expressed as the
number of cells in each direction.
void addShape(char type, int x, int y)
Creates a shape of appropriate type according to the type argument, and adds it to the domain.
The function should first test if the new shape fits within the domain, i.e. that all cells of the
shape are within the domain. If it doesn’t, the function should simply return and do nothing else.
Care must be taken to free any resources allocated until then.
The function should then test if the shape overlaps with any shape already present in the domain.
If there is overlap, the function should return and do nothing else. Care must be taken to free any
resources allocated until then.
bool fits(const Shape s) const
A function that returns true if the shape s fits inside the the boundaries of the domain. (i.e. the
coordinates of all its cells satisfy x >= 0, x=0, y
sList
A vector of base pointers to store pointers to the shapes added to the domain.
Submission
Create a tar file named hw3.tar containing the files fill.cpp Shape.h Shape.cpp
Domain.h Domain.cpp and Makefile. Do not compress the tar file. The Makefile should
include the necessary definitions to compile C++ files with the –Wall option. Include your
name and Student ID in a comment at the top of each file that you wrote (but not in the files
provided). Submit your project using: $ handin cs40 hw3 hw3.tar

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

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