#include “Shape.h”#include #include using namespace std;int main(){Shape t1, t2;char ch;int x,y;try{cin >> ch >> x >> y;t1 = Shape::makeShape(ch,x,y);t1->print();cin >> ch >> x >> y;t2 = Shape::makeShape(ch,x,y);t2->print();t2->move(1,-1);t2->print();if ( t1->overlap(t2) )cout elsecout delete t1;delete t2;}catch ( invalid_argument exc ){cout }}所有用例均已测试完毕编译命令:make执行命令./testShape RequirementECS40 Winter 2017 2017-02-08Homework 2 due Fri 2017-02-17 at 20:00Use the handin directory hw2 to submit your workShape editorNote: the concepts and software developed in Homework2 may be used in Homework3.DescriptionIn this assignment you will write a program that manipulates geometric shapes.We will consider the following set of shapes, named O, I, L, S, X, U (the names are reminiscentof the shapes). We can represent shapes by drawing the squares forming the shape as shown inFigure 1:Figure 1The cells (or squares) forming a shape are indexed by a number starting from 0, as shown in Fig1. A shape can be placed on a board by specifying the position of its “zeroth cell” in the x-yplane. In Figure 2 below, shapes have been placed on a board as follows:Figure 2- A shape of type “L” placed at (0,7)- A shape of type “L” placed at (5,8)- A shape of type “I” placed at (9,6)- A shape of type “X” placed at (5,4)- A shape of type “O” placed at (8,5)- A shape of type “U” placed at (0,2)- A shape of type “O” placed at (1,0)- A shape of type “S” placed at (4,0).- A shape of type “S” placed at (7,1).HW2 AssignmentThe goal of HW2 is to implement classes representing shapes. A given program will use thisclass to create shapes at arbitrary locations in the x-y plane and move them. The program uses afunction to move shapes and to detect if shapes overlap. The board is assumed to be the entire x-y plane.The class Shape is an abstract base class from which six classes are derived, named: O, I, L, S,X, U. A detailed specification of the class Shape is given below. You are given the header fileShape.h (at ). Your task is to write theimplementation file Shape.cpp containing the implementation of all classes. You are notallowed to modify the file Shape.h (Do not insert your name or SID in it since we will use thecmp command to check that the file is the same as the original). Your class implementation fileShape.cpp should compile without warning using the command$ g++ -Wall –c Shape.cppYou are also given a program testShape.cpp and a Makefile (same web site as above).These two files should not be modified. The testShape.cpp program tests the functionalityof the Shape class. You should be able to build the executable testShape using thecommand$ makeYou will use the testShape executable and the input aC++代写 Homework 2代写留学生C/C++课程设计、代写Shape问题作业nd output test files provided on the website to check the functionality of your classes and verify that your program reproduces the testoutput exactly. Use the diff command to compare your output file with the output file provided.Note that these test files do not check all the functionality and you are responsible for verifyingyour implementation. Other test files will also be used when grading your implementation. ThetestShape program reads input from stdin and writes to stdout. It can be used e.g. as$ ./testShape It can be assumed that input will consist of two lines. Each line consists of one characterfollowed by two integers. The character and integers are separated by white space as in e.g.X 2 -3Specification of the Shape classWe describe here the detailed specification of the Shape class. The positions of the cellsoccupied by a shape are stored in two integer arrays whose size depends on the shape, i.e. ashape occupies the cells located at (x[0],y[0]), (x[1],y[1]), etc…Study carefully the file Shape.h. Some members are public and some protected. Somemembers are virtual. Make sure you understand why. Study the file testShape.cpp in orderto understand how the classes will be used.Public membersvirtual char name(void) = 0;This pure virtual function returns the name of the class instance as a character, i.e. O, I, L, S, X,U.void print(void)This function prints information about the location of the shape by showing the position of thecells that the shape occupies:name at (x[0],y[0]) (x[1],y[1]) …For example, from Figure 2:X at (5,4) (4,5) (5,5) (6,5) (5,6)bool overlap(const Shape s)This function should return true if the shape calling the function overlaps with the shape s.This can be checked by comparing the arrays x and y of both shapes. If there is no overlap, i.e.no cells are shared by the two shapes, the function should return false.void move(int dx, int dy)This function moves the shape by a displacement (dx, dy). This function modifies the values ofthe arrays x and y. Note that this function is the same for all shapes and need not be implementedas a virtual function.static Shape makeShape(char ch, int posx, int posy)This function is a “shape factory”. It is used to generate instances of shapes. It creates an instanceof the appropriate kind of shape (specified by the character ch, with values ‘O’, ‘I’, ‘L’,‘S’,’X’, ‘U’) at the given position (posx,posy) using the operator new, and returns a pointerto the instance. If the character ch is not one of the allowed letters, the function should throw aninvalid_argument exception. The error printed by the program should correspond to theexample given in one of the test files.protected membersint x,yThe arrays holding the coordinates of the cells occupied by the shape.SubmissionCreate a tar file named hw2.tar containing the files Shape.h, Shape.cpp,testShape.cpp and Makefile. Do not compress the tar file. The files Shape.h,testShape.cpp and Makefile must be identical to the files provided. Include your nameand Student ID in a comment at the top of the Shape.cpp file. Submit your project using:$ handin cs40 hw2 hw2.tar& 转自:http://ass.3daixie.com/2018052454222858.html
讲解:C++ Homework 2C/C++、Shape
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...