SlideShare a Scribd company logo
1 of 14
Download to read offline
I am writing a program that places bolcks on a grid the the sape of different letters. It can also
move the blocks and checks if they overlap. I have most of the test cases figured out except for
four. Can someone help me out?
Thanks in advance.
output:
input:
output:
input:
output:
I CAN ONLY MODIFY ONE FILE SHAPE.CPP
#ifndef SHAPE_CPP
#define SHAPE_CPP
#include
#include
#include "Shape.h"
using namespace std;
// Constructor for O
O::O(int posx, int posy)
{
x = new int[1];
y = new int[1];
x[0] = posx;
y[0] = posy;
}
char O::name() const
{
return 'O';
}
int O::size() const
{
return 1;
}
// Constructor for I
I::I(int posx, int posy)
{
x = new int[2];
y = new int[2];
x[0] = x[1] = posx;
y[0] = posy;
y[1] = posy+1;
}
char I::name() const
{
return 'I';
}
int I::size() const
{
return 2;
}
// Constructor for L
L::L(int posx, int posy)
{
x = new int[3];
y = new int[3];
x[0] = x[2] = posx;
y[0] = y[1] = posy;
x[1] = posx+1;
y[2] = posy+1;
}
char L::name() const
{
return 'L';
}
int L::size() const
{
return 3;
}
// Constructor for S
S::S(int posx, int posy)
{
x = new int[4];
y = new int[4];
x[0] = posx;
x[1] = posx+1;
x[2] = posx+1;
x[3] = posx+2;
y[0] = y[1] = posy;
y[2] = y[3] = posy+1;
}
char S::name() const
{
return 'S';
}
int S::size() const
{
return 4;
}
/*
Constructor for X
the constructor initialises the cell co-ordinates
X is spread across 5 cells
*
* * *
*
The Numbering of cells is done from bottom-top and left to right
(x[0], y[0]) is the position of bottom most cell
(x[1], y[1]) is the position of left most cell of the 2nd row from bottom
(x[2], y[2]) is the position of the middle cell in the 2nd row from bottom
....
*/
X::X(int posx, int posy)
{
x = new int[5];
y = new int[5];
x[0] = x[2] = x[4] =posx;
x[1] = posx-1;
x[3] = posx+1;
y[0] = posy;
y[1] = y[2] = y[3] = posy+1;
y[4] = posy+2;
}
/*
This function returns the name of type of object i.e it is a X, or L, or U ...
*/
char X::name() const
{
return 'X';
}
int X::size() const
{
return 5;
}
// Constructor for U
U::U(int posx, int posy)
{
x = new int[7];
y = new int[7];
x[0] = x[3] = x[5] = posx;
x[1] = posx+1;
x[2] = x[4] = x[6] = posx+2;
y[0] = y[1] = y[2] = posy;
y[3] = y[4] = posy+1;
y[5] = y[6] = posy+2;
}
char U::name() const
{
return 'U';
}
int U::size() const
{
return 7;
}
void Shape::print() const
{
//get the size of the object i.e no of cells across which this is spread
int sz = size();
// get the type of object i.e O, L, X...
char n = name();
cout< > st;
int sz1 = t.size();
int sz2 = size();
for(int i = 0 ; i < sz1 ; i++)
{
st.insert(make_pair(t.x[i], t.y[i]));
}
for(int i = 0 ; i < sz2 ; i++)
{
if(st.find(make_pair(x[i], y[i]))!= st.end())
return true;
}
return false;
}
/*
This function creates a new object of type ch
*/
Shape * Shape::makeShape(char ch, int posx, int posy)
{
if(ch == 'O')
return new O(posx, posy);
else if(ch == 'I')
return new I(posx, posy);
else if(ch == 'L')
return new L(posx, posy);
else if(ch == 'S')
return new S(posx, posy);
else if(ch == 'X')
return new X(posx, posy);
else if(ch == 'U')
return new U(posx, posy);
else
throw std::invalid_argument("invalid type:");
}
// base class virtual destructor
Shape::~Shape()
{
delete [] x;
delete [] y;
}
#endif
//END OF FILE
//
// testShape.cpp
//
#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 << "overlap" << endl;
else
cout << "no overlap" << endl;
delete t1;
delete t2;
}
catch ( invalid_argument &exc )
{
cout << exc.what() << ": " << ch << " " << x << " " << y << endl;
}
}
//
// Shape.h
//
#ifndef SHAPE_H
#define SHAPE_H
class Shape
{
public:
virtual ~Shape(void);
virtual char name(void) const = 0;
virtual int size(void) const = 0;
void print(void) const;
void move (int dx, int dy);
bool overlap(const Shape &t) const;
static Shape *makeShape(char ch,int posx,int posy);
protected:
int *x, *y;
};
class O: public Shape
{
public:
O(int posx, int posy);
virtual char name(void) const;
virtual int size(void) const;
};
class I: public Shape
{
public:
I(int posx, int posy);
virtual char name(void) const;
virtual int size(void) const;
};
class L: public Shape
{
public:
L(int posx, int posy);
virtual char name(void) const;
virtual int size(void) const;
};
class S: public Shape
{
public:
S(int posx, int posy);
virtual char name(void) const;
virtual int size(void) const;
};
class X: public Shape
{
public:
X(int posx, int posy);
virtual char name(void) const;
virtual int size(void) const;
};
class U: public Shape
{
public:
U(int posx, int posy);
virtual char name(void) const;
virtual int size(void) const;
};
#endif
Solution
#ifndef SHAPE_CPP
#define SHAPE_CPP
#include
#include
#include "Shape.h"
using namespace std;
// Constructor for O
O::O(int posx, int posy)
{
x = new int[1];
y = new int[1];
x[0] = posx;
y[0] = posy;
}
char O::name() const
{
return 'O';
}
int O::size() const
{
return 1;
}
// Constructor for I
I::I(int posx, int posy)
{
x = new int[2];
y = new int[2];
x[0] = x[1] = posx;
y[0] = posy;
y[1] = posy+1;
}
char I::name() const
{
return 'I';
}
int I::size() const
{
return 2;
}
// Constructor for L
L::L(int posx, int posy)
{
x = new int[3];
y = new int[3];
x[0] = x[2] = posx;
y[0] = y[1] = posy;
x[1] = posx+1;
y[2] = posy+1;
}
char L::name() const
{
return 'L';
}
int L::size() const
{
return 3;
}
// Constructor for S
S::S(int posx, int posy)
{
x = new int[4];
y = new int[4];
x[0] = posx;
x[1] = posx+1;
x[2] = posx+1;
x[3] = posx+2;
y[0] = y[1] = posy;
y[2] = y[3] = posy+1;
}
char S::name() const
{
return 'S';
}
int S::size() const
{
return 4;
}
/*
Constructor for X
the constructor initialises the cell co-ordinates
X is spread across 5 cells
*
* * *
*
The Numbering of cells is done from bottom-top and left to right
(x[0], y[0]) is the position of bottom most cell
(x[1], y[1]) is the position of left most cell of the 2nd row from bottom
(x[2], y[2]) is the position of the middle cell in the 2nd row from bottom
....
*/
X::X(int posx, int posy)
{
x = new int[5];
y = new int[5];
x[0] = x[2] = x[4] =posx;
x[1] = posx-1;
x[3] = posx+1;
y[0] = posy;
y[1] = y[2] = y[3] = posy+1;
y[4] = posy+2;
}
/*
This function returns the name of type of object i.e it is a X, or L, or U ...
*/
char X::name() const
{
return 'X';
}
int X::size() const
{
return 5;
}
// Constructor for U
U::U(int posx, int posy)
{
x = new int[7];
y = new int[7];
x[0] = x[3] = x[5] = posx;
x[1] = posx+1;
x[2] = x[4] = x[6] = posx+2;
y[0] = y[1] = y[2] = posy;
y[3] = y[4] = posy+1;
y[5] = y[6] = posy+2;
}
char U::name() const
{
return 'U';
}
int U::size() const
{
return 7;
}
void Shape::print() const
{
//get the size of the object i.e no of cells across which this is spread
int sz = size();
// get the type of object i.e O, L, X...
char n = name();
cout< > st;
int sz1 = t.size();
int sz2 = size();
for(int i = 0 ; i < sz1 ; i++)
{
st.insert(make_pair(t.x[i], t.y[i]));
}
for(int i = 0 ; i < sz2 ; i++)
{
if(st.find(make_pair(x[i], y[i]))!= st.end())
return true;
}
return false;
}
/*
This function creates a new object of type ch
*/
Shape * Shape::makeShape(char ch, int posx, int posy)
{
if(ch == 'O')
return new O(posx, posy);
else if(ch == 'I')
return new I(posx, posy);
else if(ch == 'L')
return new L(posx, posy);
else if(ch == 'S')
return new S(posx, posy);
else if(ch == 'X')
return new X(posx, posy);
else if(ch == 'U')
return new U(posx, posy);
else
throw std::invalid_argument("invalid type:");
}
// base class virtual destructor
Shape::~Shape()
{
delete [] x;
delete [] y;
}
#endif

More Related Content

Similar to I am writing a program that places bolcks on a grid the the sape of .pdf

C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdffqerwqdfad
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.pdfkurimaru1
 
Lecture 4: Data Types
Lecture 4: Data TypesLecture 4: Data Types
Lecture 4: Data TypesEelco Visser
 
#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And ReferencesHadziq Fabroyir
 
Kotlin for Android Developers
Kotlin for Android DevelopersKotlin for Android Developers
Kotlin for Android DevelopersHassan Abid
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMDdhaval10690
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfarjuncorner565
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Paulo Morgado
 
The java language cheat sheet
The java language cheat sheetThe java language cheat sheet
The java language cheat sheetanand_study
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016Manoj Kumar
 
The following code is based on the Josephus problem, the code does c.pdf
The following code is based on the Josephus problem, the code does c.pdfThe following code is based on the Josephus problem, the code does c.pdf
The following code is based on the Josephus problem, the code does c.pdfezhilvizhiyan
 
Les nouveautés de C# 6
Les nouveautés de C# 6Les nouveautés de C# 6
Les nouveautés de C# 6Microsoft
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systemsleague
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Codemotion
 

Similar to I am writing a program that places bolcks on a grid the the sape of .pdf (20)

C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdf
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.pdf
 
Lecture 4: Data Types
Lecture 4: Data TypesLecture 4: Data Types
Lecture 4: Data Types
 
#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References#OOP_D_ITS - 3rd - Pointer And References
#OOP_D_ITS - 3rd - Pointer And References
 
Kotlin for Android Developers
Kotlin for Android DevelopersKotlin for Android Developers
Kotlin for Android Developers
 
ES6 and AngularAMD
ES6 and AngularAMDES6 and AngularAMD
ES6 and AngularAMD
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
 
The java language cheat sheet
The java language cheat sheetThe java language cheat sheet
The java language cheat sheet
 
662305 10
662305 10662305 10
662305 10
 
ES6 PPT FOR 2016
ES6 PPT FOR 2016ES6 PPT FOR 2016
ES6 PPT FOR 2016
 
EcmaScript 6
EcmaScript 6 EcmaScript 6
EcmaScript 6
 
Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6Workshop 10: ECMAScript 6
Workshop 10: ECMAScript 6
 
The following code is based on the Josephus problem, the code does c.pdf
The following code is based on the Josephus problem, the code does c.pdfThe following code is based on the Josephus problem, the code does c.pdf
The following code is based on the Josephus problem, the code does c.pdf
 
Les nouveautés de C# 6
Les nouveautés de C# 6Les nouveautés de C# 6
Les nouveautés de C# 6
 
Op ps
Op psOp ps
Op ps
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
 
Functional JS+ ES6.pptx
Functional JS+ ES6.pptxFunctional JS+ ES6.pptx
Functional JS+ ES6.pptx
 
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
Functional Programming You Already Know - Kevlin Henney - Codemotion Rome 2015
 

More from eyewaregallery

in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfeyewaregallery
 
In addition to the fossil record, what other kinds of evidence reinfo.pdf
In addition to the fossil record, what other kinds of evidence reinfo.pdfIn addition to the fossil record, what other kinds of evidence reinfo.pdf
In addition to the fossil record, what other kinds of evidence reinfo.pdfeyewaregallery
 
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdfHow much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdfeyewaregallery
 
How do teams bring value to an organizationHow are high performin.pdf
How do teams bring value to an organizationHow are high performin.pdfHow do teams bring value to an organizationHow are high performin.pdf
How do teams bring value to an organizationHow are high performin.pdfeyewaregallery
 
how can we use empricism to figure out if a fact is trueSolutio.pdf
how can we use empricism to figure out if a fact is trueSolutio.pdfhow can we use empricism to figure out if a fact is trueSolutio.pdf
how can we use empricism to figure out if a fact is trueSolutio.pdfeyewaregallery
 
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdf
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdfGene RegulationFunction of transcription factor domains, i.e. DNA.pdf
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdfeyewaregallery
 
For each step of DNA replication, predict the outcome ifconcentra.pdf
For each step of DNA replication, predict the outcome ifconcentra.pdfFor each step of DNA replication, predict the outcome ifconcentra.pdf
For each step of DNA replication, predict the outcome ifconcentra.pdfeyewaregallery
 
Explain THREE unique characteristics of fungi.SolutionThree un.pdf
Explain THREE unique characteristics of fungi.SolutionThree un.pdfExplain THREE unique characteristics of fungi.SolutionThree un.pdf
Explain THREE unique characteristics of fungi.SolutionThree un.pdfeyewaregallery
 
Explain the basic relationship between humans and microorganisms.pdf
Explain the basic relationship between humans and microorganisms.pdfExplain the basic relationship between humans and microorganisms.pdf
Explain the basic relationship between humans and microorganisms.pdfeyewaregallery
 
discuss the rationale for the global harmonization of financial repo.pdf
discuss the rationale for the global harmonization of financial repo.pdfdiscuss the rationale for the global harmonization of financial repo.pdf
discuss the rationale for the global harmonization of financial repo.pdfeyewaregallery
 
Describe the need to multitask in BBC (behavior-based control) syste.pdf
Describe the need to multitask in BBC (behavior-based control) syste.pdfDescribe the need to multitask in BBC (behavior-based control) syste.pdf
Describe the need to multitask in BBC (behavior-based control) syste.pdfeyewaregallery
 
A spinner with 7 equally sized slices is shown below. The dial is spu.pdf
A spinner with 7 equally sized slices is shown below. The dial is spu.pdfA spinner with 7 equally sized slices is shown below. The dial is spu.pdf
A spinner with 7 equally sized slices is shown below. The dial is spu.pdfeyewaregallery
 
ble below to calculate the Gross Domestic Product uning the ral Gro.pdf
ble below to calculate the Gross Domestic Product uning the ral Gro.pdfble below to calculate the Gross Domestic Product uning the ral Gro.pdf
ble below to calculate the Gross Domestic Product uning the ral Gro.pdfeyewaregallery
 
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
1.The limbic systemA. matures before the prefrontal cortexB. is.pdfeyewaregallery
 
Why is leadership a critical factor in implementing change and qua.pdf
Why is leadership a critical factor in implementing change and qua.pdfWhy is leadership a critical factor in implementing change and qua.pdf
Why is leadership a critical factor in implementing change and qua.pdfeyewaregallery
 
Why are there bubbles in beer and champagneSolution Bubbles of .pdf
Why are there bubbles in beer and champagneSolution  Bubbles of .pdfWhy are there bubbles in beer and champagneSolution  Bubbles of .pdf
Why are there bubbles in beer and champagneSolution Bubbles of .pdfeyewaregallery
 
Which of the following is true of a traditional master budget a. It.pdf
Which of the following is true of a traditional master budget a. It.pdfWhich of the following is true of a traditional master budget a. It.pdf
Which of the following is true of a traditional master budget a. It.pdfeyewaregallery
 
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdf
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdfWhich ethnic groups were a part of the former YugoslaviaCroats, S.pdf
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdfeyewaregallery
 
What would the components of the development be in an early learning.pdf
What would the components of the development be in an early learning.pdfWhat would the components of the development be in an early learning.pdf
What would the components of the development be in an early learning.pdfeyewaregallery
 
What is true of all fungi They area. eukaryotic, heterotrophic pl.pdf
What is true of all fungi They area. eukaryotic, heterotrophic pl.pdfWhat is true of all fungi They area. eukaryotic, heterotrophic pl.pdf
What is true of all fungi They area. eukaryotic, heterotrophic pl.pdfeyewaregallery
 

More from eyewaregallery (20)

in C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdfin C++ , Design a linked list class named IntegerList to hold a seri.pdf
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
 
In addition to the fossil record, what other kinds of evidence reinfo.pdf
In addition to the fossil record, what other kinds of evidence reinfo.pdfIn addition to the fossil record, what other kinds of evidence reinfo.pdf
In addition to the fossil record, what other kinds of evidence reinfo.pdf
 
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdfHow much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
How much 0.521 M NaOH will be needed to raise the pH of 0.161 L of 4.pdf
 
How do teams bring value to an organizationHow are high performin.pdf
How do teams bring value to an organizationHow are high performin.pdfHow do teams bring value to an organizationHow are high performin.pdf
How do teams bring value to an organizationHow are high performin.pdf
 
how can we use empricism to figure out if a fact is trueSolutio.pdf
how can we use empricism to figure out if a fact is trueSolutio.pdfhow can we use empricism to figure out if a fact is trueSolutio.pdf
how can we use empricism to figure out if a fact is trueSolutio.pdf
 
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdf
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdfGene RegulationFunction of transcription factor domains, i.e. DNA.pdf
Gene RegulationFunction of transcription factor domains, i.e. DNA.pdf
 
For each step of DNA replication, predict the outcome ifconcentra.pdf
For each step of DNA replication, predict the outcome ifconcentra.pdfFor each step of DNA replication, predict the outcome ifconcentra.pdf
For each step of DNA replication, predict the outcome ifconcentra.pdf
 
Explain THREE unique characteristics of fungi.SolutionThree un.pdf
Explain THREE unique characteristics of fungi.SolutionThree un.pdfExplain THREE unique characteristics of fungi.SolutionThree un.pdf
Explain THREE unique characteristics of fungi.SolutionThree un.pdf
 
Explain the basic relationship between humans and microorganisms.pdf
Explain the basic relationship between humans and microorganisms.pdfExplain the basic relationship between humans and microorganisms.pdf
Explain the basic relationship between humans and microorganisms.pdf
 
discuss the rationale for the global harmonization of financial repo.pdf
discuss the rationale for the global harmonization of financial repo.pdfdiscuss the rationale for the global harmonization of financial repo.pdf
discuss the rationale for the global harmonization of financial repo.pdf
 
Describe the need to multitask in BBC (behavior-based control) syste.pdf
Describe the need to multitask in BBC (behavior-based control) syste.pdfDescribe the need to multitask in BBC (behavior-based control) syste.pdf
Describe the need to multitask in BBC (behavior-based control) syste.pdf
 
A spinner with 7 equally sized slices is shown below. The dial is spu.pdf
A spinner with 7 equally sized slices is shown below. The dial is spu.pdfA spinner with 7 equally sized slices is shown below. The dial is spu.pdf
A spinner with 7 equally sized slices is shown below. The dial is spu.pdf
 
ble below to calculate the Gross Domestic Product uning the ral Gro.pdf
ble below to calculate the Gross Domestic Product uning the ral Gro.pdfble below to calculate the Gross Domestic Product uning the ral Gro.pdf
ble below to calculate the Gross Domestic Product uning the ral Gro.pdf
 
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
1.The limbic systemA. matures before the prefrontal cortexB. is.pdf
 
Why is leadership a critical factor in implementing change and qua.pdf
Why is leadership a critical factor in implementing change and qua.pdfWhy is leadership a critical factor in implementing change and qua.pdf
Why is leadership a critical factor in implementing change and qua.pdf
 
Why are there bubbles in beer and champagneSolution Bubbles of .pdf
Why are there bubbles in beer and champagneSolution  Bubbles of .pdfWhy are there bubbles in beer and champagneSolution  Bubbles of .pdf
Why are there bubbles in beer and champagneSolution Bubbles of .pdf
 
Which of the following is true of a traditional master budget a. It.pdf
Which of the following is true of a traditional master budget a. It.pdfWhich of the following is true of a traditional master budget a. It.pdf
Which of the following is true of a traditional master budget a. It.pdf
 
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdf
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdfWhich ethnic groups were a part of the former YugoslaviaCroats, S.pdf
Which ethnic groups were a part of the former YugoslaviaCroats, S.pdf
 
What would the components of the development be in an early learning.pdf
What would the components of the development be in an early learning.pdfWhat would the components of the development be in an early learning.pdf
What would the components of the development be in an early learning.pdf
 
What is true of all fungi They area. eukaryotic, heterotrophic pl.pdf
What is true of all fungi They area. eukaryotic, heterotrophic pl.pdfWhat is true of all fungi They area. eukaryotic, heterotrophic pl.pdf
What is true of all fungi They area. eukaryotic, heterotrophic pl.pdf
 

Recently uploaded

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Recently uploaded (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

I am writing a program that places bolcks on a grid the the sape of .pdf

  • 1. I am writing a program that places bolcks on a grid the the sape of different letters. It can also move the blocks and checks if they overlap. I have most of the test cases figured out except for four. Can someone help me out? Thanks in advance. output: input: output: input: output: I CAN ONLY MODIFY ONE FILE SHAPE.CPP #ifndef SHAPE_CPP #define SHAPE_CPP #include #include #include "Shape.h" using namespace std; // Constructor for O O::O(int posx, int posy) { x = new int[1]; y = new int[1]; x[0] = posx; y[0] = posy; } char O::name() const { return 'O'; } int O::size() const { return 1; } // Constructor for I I::I(int posx, int posy) {
  • 2. x = new int[2]; y = new int[2]; x[0] = x[1] = posx; y[0] = posy; y[1] = posy+1; } char I::name() const { return 'I'; } int I::size() const { return 2; } // Constructor for L L::L(int posx, int posy) { x = new int[3]; y = new int[3]; x[0] = x[2] = posx; y[0] = y[1] = posy; x[1] = posx+1; y[2] = posy+1; } char L::name() const { return 'L'; } int L::size() const { return 3; } // Constructor for S S::S(int posx, int posy) {
  • 3. x = new int[4]; y = new int[4]; x[0] = posx; x[1] = posx+1; x[2] = posx+1; x[3] = posx+2; y[0] = y[1] = posy; y[2] = y[3] = posy+1; } char S::name() const { return 'S'; } int S::size() const { return 4; } /* Constructor for X the constructor initialises the cell co-ordinates X is spread across 5 cells * * * * * The Numbering of cells is done from bottom-top and left to right (x[0], y[0]) is the position of bottom most cell (x[1], y[1]) is the position of left most cell of the 2nd row from bottom (x[2], y[2]) is the position of the middle cell in the 2nd row from bottom .... */ X::X(int posx, int posy) { x = new int[5]; y = new int[5]; x[0] = x[2] = x[4] =posx; x[1] = posx-1;
  • 4. x[3] = posx+1; y[0] = posy; y[1] = y[2] = y[3] = posy+1; y[4] = posy+2; } /* This function returns the name of type of object i.e it is a X, or L, or U ... */ char X::name() const { return 'X'; } int X::size() const { return 5; } // Constructor for U U::U(int posx, int posy) { x = new int[7]; y = new int[7]; x[0] = x[3] = x[5] = posx; x[1] = posx+1; x[2] = x[4] = x[6] = posx+2; y[0] = y[1] = y[2] = posy; y[3] = y[4] = posy+1; y[5] = y[6] = posy+2; } char U::name() const { return 'U'; } int U::size() const { return 7; }
  • 5. void Shape::print() const { //get the size of the object i.e no of cells across which this is spread int sz = size(); // get the type of object i.e O, L, X... char n = name(); cout< > st; int sz1 = t.size(); int sz2 = size(); for(int i = 0 ; i < sz1 ; i++) { st.insert(make_pair(t.x[i], t.y[i])); } for(int i = 0 ; i < sz2 ; i++) { if(st.find(make_pair(x[i], y[i]))!= st.end()) return true; } return false; } /* This function creates a new object of type ch */ Shape * Shape::makeShape(char ch, int posx, int posy) { if(ch == 'O') return new O(posx, posy); else if(ch == 'I') return new I(posx, posy); else if(ch == 'L') return new L(posx, posy); else if(ch == 'S') return new S(posx, posy); else if(ch == 'X') return new X(posx, posy); else if(ch == 'U')
  • 6. return new U(posx, posy); else throw std::invalid_argument("invalid type:"); } // base class virtual destructor Shape::~Shape() { delete [] x; delete [] y; } #endif //END OF FILE // // testShape.cpp // #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 << "overlap" << endl;
  • 7. else cout << "no overlap" << endl; delete t1; delete t2; } catch ( invalid_argument &exc ) { cout << exc.what() << ": " << ch << " " << x << " " << y << endl; } } // // Shape.h // #ifndef SHAPE_H #define SHAPE_H class Shape { public: virtual ~Shape(void); virtual char name(void) const = 0; virtual int size(void) const = 0; void print(void) const; void move (int dx, int dy); bool overlap(const Shape &t) const; static Shape *makeShape(char ch,int posx,int posy); protected: int *x, *y; }; class O: public Shape { public: O(int posx, int posy); virtual char name(void) const; virtual int size(void) const; }; class I: public Shape
  • 8. { public: I(int posx, int posy); virtual char name(void) const; virtual int size(void) const; }; class L: public Shape { public: L(int posx, int posy); virtual char name(void) const; virtual int size(void) const; }; class S: public Shape { public: S(int posx, int posy); virtual char name(void) const; virtual int size(void) const; }; class X: public Shape { public: X(int posx, int posy); virtual char name(void) const; virtual int size(void) const; }; class U: public Shape { public: U(int posx, int posy); virtual char name(void) const; virtual int size(void) const; }; #endif
  • 9. Solution #ifndef SHAPE_CPP #define SHAPE_CPP #include #include #include "Shape.h" using namespace std; // Constructor for O O::O(int posx, int posy) { x = new int[1]; y = new int[1]; x[0] = posx; y[0] = posy; } char O::name() const { return 'O'; } int O::size() const { return 1; } // Constructor for I I::I(int posx, int posy) { x = new int[2]; y = new int[2]; x[0] = x[1] = posx; y[0] = posy; y[1] = posy+1; } char I::name() const { return 'I';
  • 10. } int I::size() const { return 2; } // Constructor for L L::L(int posx, int posy) { x = new int[3]; y = new int[3]; x[0] = x[2] = posx; y[0] = y[1] = posy; x[1] = posx+1; y[2] = posy+1; } char L::name() const { return 'L'; } int L::size() const { return 3; } // Constructor for S S::S(int posx, int posy) { x = new int[4]; y = new int[4]; x[0] = posx; x[1] = posx+1; x[2] = posx+1; x[3] = posx+2; y[0] = y[1] = posy; y[2] = y[3] = posy+1; }
  • 11. char S::name() const { return 'S'; } int S::size() const { return 4; } /* Constructor for X the constructor initialises the cell co-ordinates X is spread across 5 cells * * * * * The Numbering of cells is done from bottom-top and left to right (x[0], y[0]) is the position of bottom most cell (x[1], y[1]) is the position of left most cell of the 2nd row from bottom (x[2], y[2]) is the position of the middle cell in the 2nd row from bottom .... */ X::X(int posx, int posy) { x = new int[5]; y = new int[5]; x[0] = x[2] = x[4] =posx; x[1] = posx-1; x[3] = posx+1; y[0] = posy; y[1] = y[2] = y[3] = posy+1; y[4] = posy+2; } /* This function returns the name of type of object i.e it is a X, or L, or U ... */ char X::name() const
  • 12. { return 'X'; } int X::size() const { return 5; } // Constructor for U U::U(int posx, int posy) { x = new int[7]; y = new int[7]; x[0] = x[3] = x[5] = posx; x[1] = posx+1; x[2] = x[4] = x[6] = posx+2; y[0] = y[1] = y[2] = posy; y[3] = y[4] = posy+1; y[5] = y[6] = posy+2; } char U::name() const { return 'U'; } int U::size() const { return 7; } void Shape::print() const { //get the size of the object i.e no of cells across which this is spread int sz = size(); // get the type of object i.e O, L, X... char n = name(); cout< > st; int sz1 = t.size(); int sz2 = size();
  • 13. for(int i = 0 ; i < sz1 ; i++) { st.insert(make_pair(t.x[i], t.y[i])); } for(int i = 0 ; i < sz2 ; i++) { if(st.find(make_pair(x[i], y[i]))!= st.end()) return true; } return false; } /* This function creates a new object of type ch */ Shape * Shape::makeShape(char ch, int posx, int posy) { if(ch == 'O') return new O(posx, posy); else if(ch == 'I') return new I(posx, posy); else if(ch == 'L') return new L(posx, posy); else if(ch == 'S') return new S(posx, posy); else if(ch == 'X') return new X(posx, posy); else if(ch == 'U') return new U(posx, posy); else throw std::invalid_argument("invalid type:"); } // base class virtual destructor Shape::~Shape() { delete [] x; delete [] y;