SlideShare a Scribd company logo
ECS40 Winter 2017 Homework 3
To Purchase This Material Click below Link
http://www.tutorialoutlet.com/all-miscellaneous/ecs-
40-winter-2017-homework-3/
FOR MORE CLASSES VISIT
www.tutorialoutlet.com
ECS40 Winter 2017 2017-02-22 Homework 3 due Fri 2017-03-03 at
20:00
Use the handin directory hw3 to submit your work Filling a
rectangular domain with random shapes
Description This assignment builds on the Shape class designed in
HW2. In this assignment (HW3), you
will modify the implementation of the Shape class that was developed
in HW2, and implement
a class Domain representing a rectangular area in the x-y plane, with
functions that draw a
visual representation of the domain as a scalable vector graphics (svg)
file. The svg file can be
visualized using a browser such as Firefox, Safari, Chrome or Internet
Explorer.
The domain is a rectangular array of cells that can be occupied by
shapes. The goal of the
assignment is to implement a program that places randomly selected
shapes at random positions
on an arbitrary rectangular domain until the domain is full, and
creates a graphical representation
of the domain. Figure 1: Rendering of ansvg file obtained with a
10x12 filled domain
HW3 Assignment In HW3, you are given the files fill.cpp (which
contains the main function) and the files
Shape.h and Domain.h. You should not modify these files. Your task
is to implement the
class Domain by writing the file Domain.cpp and by writing a new
file Shape.cpp that
implements the additional specifications given in HW3. Note that the
file Shape.h is different
from the one given in HW2.
All source files should compile without warning. You should provide
a Makefile in order to
be able to build the executable fill using the command
$ make Input Input for the fill program is provided on the command
line. It does not read input from any
file.
The command line arguments of the fill program are: size_xsize_y
seed
size_x: size of the domain (number of cells) in the x direction
size_y: size of the domain (number of cells) in the y direction
seed: an integer used as a seed for the random number generator
rand() used in fill.cpp
The program is run, for example, using the following command line:
$ ./fill 12 10 1234 > 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
I
L
S
X
U cyan
yellow
purple
blue
orange
red intgetX(int i) const
Returns the x coordinate of cell i of the shape. It is assumed that the
value of the argument is
valid. intgetY(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:
<rect
<rect
<rect
<rect fill="blue" fill="blue"
fill="blue"
fill="blue" stroke="black"
stroke="black"
stroke="black"
stroke="black" x="160"
x="200"
x="200"
x="240" y="80" width="40"
height="40"/>
y="80" width="40"
height="40"/>
y="120" width="40"
height="40"/>
y="120" width="40"
height="40"/> 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(intsize_x, intsize_y)
Constructor taking as arguments the horizontal and vertical size of the
domain, expressed as the
number of cells in each direction.
voidaddShape(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<size_x, y>=0,
y<size_y) and false otherwise.
bool full(void) const
A function that returns true if the domain is full, (i.e. the sum of the
sizes of all shapes present
in the domain is equal to the total number of cells), and false
otherwise. void draw(void) const
This function draws the current state of the domain by printing a
complete svg document on
stdout. It should first print the following svg header:
<?xml version="1.0" encoding="utf-8"
standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG
1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
>
<svg width="670" height="670"
viewBox="0 0 650 650"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink" >
<g transform="matrix(1,0,0,-1,50,650)"> Note that
this header is fixed, i.e. it is independent of the domain size.
It should then draw a frame with white background defining the
domain area. For example, for a
domain of 8x5 cells, the frame is drawn by printing
<rect fill="white" stroke="black"
x="0" y="0" width="320"
height="200"/> Note that the width and height
attributes depend on the size of the domain.
It should then draw each shape on the domain by calling the shapes’
draw functions.
Finally it should print the following svg trailer:
</g>
</svg> The resulting svg file can be visualized by opening it
with a browser such as Firefox, Safari,
Chrome or Internet Explorer.
private members of the Domain class constintsize_x, size_y
The dimensions of the domain measured in number of cells in each
direction.
vector<Shape*> 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.hShape.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

More Related Content

What's hot

Cs practical file
Cs practical fileCs practical file
Cs practical file
Shailendra Garg
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
Sabik T S
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
Aditya Vaishampayan
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Managing console input
Managing console inputManaging console input
Managing console input
rajshreemuthiah
 
Memory management of datatypes
Memory management of datatypesMemory management of datatypes
Memory management of datatypes
Monika Sanghani
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
guestf0562b
 
C++ Language
C++ LanguageC++ Language
C++ Language
Vidyacenter
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Hive function-cheat-sheet
Hive function-cheat-sheetHive function-cheat-sheet
Hive function-cheat-sheet
Dr. Volkan OBAN
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
kelleyc3
 
Input Output Management In C Programming
Input Output Management In C ProgrammingInput Output Management In C Programming
Input Output Management In C Programming
Kamal Acharya
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
Abhishek Sinha
 
T03 b basicioscanf
T03 b basicioscanfT03 b basicioscanf
T03 b basicioscanf
teach4uin
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
Steve Johnson
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
SURBHI SAROHA
 
Intake 38 7
Intake 38 7Intake 38 7
Intake 38 7
Mahmoud Ouf
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
SURBHI SAROHA
 
Input And Output
 Input And Output Input And Output
Input And Output
Ghaffar Khan
 

What's hot (20)

Cs practical file
Cs practical fileCs practical file
Cs practical file
 
Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Managing console input
Managing console inputManaging console input
Managing console input
 
Memory management of datatypes
Memory management of datatypesMemory management of datatypes
Memory management of datatypes
 
Advanced Programming C++
Advanced Programming C++Advanced Programming C++
Advanced Programming C++
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
 
Hive function-cheat-sheet
Hive function-cheat-sheetHive function-cheat-sheet
Hive function-cheat-sheet
 
C++ Overview
C++ OverviewC++ Overview
C++ Overview
 
Input Output Management In C Programming
Input Output Management In C ProgrammingInput Output Management In C Programming
Input Output Management In C Programming
 
Programming in C [Module One]
Programming in C [Module One]Programming in C [Module One]
Programming in C [Module One]
 
T03 b basicioscanf
T03 b basicioscanfT03 b basicioscanf
T03 b basicioscanf
 
Learn c++ Programming Language
Learn c++ Programming LanguageLearn c++ Programming Language
Learn c++ Programming Language
 
C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
Intake 38 7
Intake 38 7Intake 38 7
Intake 38 7
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Input And Output
 Input And Output Input And Output
Input And Output
 

Viewers also liked

Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
JenniferBall44
 
Metal fabrication – canada – february 2017
Metal fabrication – canada – february 2017Metal fabrication – canada – february 2017
Metal fabrication – canada – february 2017
paul young cpa, cga
 
Los reinos cristianos medievales en la península ibérica
Los reinos cristianos medievales en la península ibérica Los reinos cristianos medievales en la península ibérica
Los reinos cristianos medievales en la península ibérica
Àngels Rotger
 
Editing Functionality - Apollo Workshop
Editing Functionality - Apollo WorkshopEditing Functionality - Apollo Workshop
Editing Functionality - Apollo Workshop
Monica Munoz-Torres
 
Brochure mbaip 2017
Brochure mbaip 2017 Brochure mbaip 2017
Slide dengue
Slide dengueSlide dengue
Slide dengue
Neuma_neves
 
Locating Facts Devices in Optimized manner in Power System by Means of Sensit...
Locating Facts Devices in Optimized manner in Power System by Means of Sensit...Locating Facts Devices in Optimized manner in Power System by Means of Sensit...
Locating Facts Devices in Optimized manner in Power System by Means of Sensit...
IJERA Editor
 
Compresores de archivos (1)
Compresores de  archivos (1)Compresores de  archivos (1)
Compresores de archivos (1)
Alex Lopez
 
A Singular Spectrum Analysis Technique to Electricity Consumption Forecasting
A Singular Spectrum Analysis Technique to Electricity Consumption ForecastingA Singular Spectrum Analysis Technique to Electricity Consumption Forecasting
A Singular Spectrum Analysis Technique to Electricity Consumption Forecasting
IJERA Editor
 
A study of Heavy Metal Pollution in Groundwater of Malwa Region of Punjab, In...
A study of Heavy Metal Pollution in Groundwater of Malwa Region of Punjab, In...A study of Heavy Metal Pollution in Groundwater of Malwa Region of Punjab, In...
A study of Heavy Metal Pollution in Groundwater of Malwa Region of Punjab, In...
IJERA Editor
 
Problemasfisica2
Problemasfisica2Problemasfisica2
Problemasfisica2
alejandro amado
 
Proekt prezentacija (7)
Proekt prezentacija (7)Proekt prezentacija (7)
Proekt prezentacija (7)
seredukhina
 
Entd 313 you will be required to write an 3 5 page technical design
Entd 313 you will be required to write an 3 5 page technical designEntd 313 you will be required to write an 3 5 page technical design
Entd 313 you will be required to write an 3 5 page technical design
JenniferBall45
 
Java. Интерфейс Set - наборы (множества) и его реализации.
Java. Интерфейс Set - наборы (множества) и его реализации.Java. Интерфейс Set - наборы (множества) и его реализации.
Java. Интерфейс Set - наборы (множества) и его реализации.
Unguryan Vitaliy
 

Viewers also liked (14)

Ecs 10 programming assignment 4 loopapalooza
Ecs 10 programming assignment 4   loopapaloozaEcs 10 programming assignment 4   loopapalooza
Ecs 10 programming assignment 4 loopapalooza
 
Metal fabrication – canada – february 2017
Metal fabrication – canada – february 2017Metal fabrication – canada – february 2017
Metal fabrication – canada – february 2017
 
Los reinos cristianos medievales en la península ibérica
Los reinos cristianos medievales en la península ibérica Los reinos cristianos medievales en la península ibérica
Los reinos cristianos medievales en la península ibérica
 
Editing Functionality - Apollo Workshop
Editing Functionality - Apollo WorkshopEditing Functionality - Apollo Workshop
Editing Functionality - Apollo Workshop
 
Brochure mbaip 2017
Brochure mbaip 2017 Brochure mbaip 2017
Brochure mbaip 2017
 
Slide dengue
Slide dengueSlide dengue
Slide dengue
 
Locating Facts Devices in Optimized manner in Power System by Means of Sensit...
Locating Facts Devices in Optimized manner in Power System by Means of Sensit...Locating Facts Devices in Optimized manner in Power System by Means of Sensit...
Locating Facts Devices in Optimized manner in Power System by Means of Sensit...
 
Compresores de archivos (1)
Compresores de  archivos (1)Compresores de  archivos (1)
Compresores de archivos (1)
 
A Singular Spectrum Analysis Technique to Electricity Consumption Forecasting
A Singular Spectrum Analysis Technique to Electricity Consumption ForecastingA Singular Spectrum Analysis Technique to Electricity Consumption Forecasting
A Singular Spectrum Analysis Technique to Electricity Consumption Forecasting
 
A study of Heavy Metal Pollution in Groundwater of Malwa Region of Punjab, In...
A study of Heavy Metal Pollution in Groundwater of Malwa Region of Punjab, In...A study of Heavy Metal Pollution in Groundwater of Malwa Region of Punjab, In...
A study of Heavy Metal Pollution in Groundwater of Malwa Region of Punjab, In...
 
Problemasfisica2
Problemasfisica2Problemasfisica2
Problemasfisica2
 
Proekt prezentacija (7)
Proekt prezentacija (7)Proekt prezentacija (7)
Proekt prezentacija (7)
 
Entd 313 you will be required to write an 3 5 page technical design
Entd 313 you will be required to write an 3 5 page technical designEntd 313 you will be required to write an 3 5 page technical design
Entd 313 you will be required to write an 3 5 page technical design
 
Java. Интерфейс Set - наборы (множества) и его реализации.
Java. Интерфейс Set - наборы (множества) и его реализации.Java. Интерфейс Set - наборы (множества) и его реализации.
Java. Интерфейс Set - наборы (множества) и его реализации.
 

Similar to Ecs40 winter 2017 homework 3

C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
Syed Zaid Irshad
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Haripritha
 
Csharp_Chap06
Csharp_Chap06Csharp_Chap06
Csharp_Chap06
Mohamed Krar
 
Ch 4
Ch 4Ch 4
Ch 4
AMIT JAIN
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Chris Adamson
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Introduction to r
Introduction to rIntroduction to r
Introduction to r
Golden Julie Jesus
 
7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
RiazAhmad521284
 
PROG3040 Assignment 1 – Fall 2013 Glenn Paulley – 2A605, x25.docx
PROG3040 Assignment 1 – Fall 2013    Glenn Paulley – 2A605, x25.docxPROG3040 Assignment 1 – Fall 2013    Glenn Paulley – 2A605, x25.docx
PROG3040 Assignment 1 – Fall 2013 Glenn Paulley – 2A605, x25.docx
wkyra78
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
Umer Azeem
 
C++ Homework Help
C++ Homework HelpC++ Homework Help
C++ Homework Help
C++ Homework Help
 
C tutorials
C tutorialsC tutorials
C tutorials
Amit Kapoor
 
Basic c
Basic cBasic c
Basic c
Veera Karthi
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
Jitendra Ahir
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
Vaishnavee Sharma
 
Basics1
Basics1Basics1
Basics1
phanleson
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
Jesmin Akhter
 
Background This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docxBackground This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docx
rosemaryralphs52525
 
Intake 37 6
Intake 37 6Intake 37 6
Intake 37 6
Mahmoud Ouf
 

Similar to Ecs40 winter 2017 homework 3 (20)

C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)C cheat sheet for varsity (extreme edition)
C cheat sheet for varsity (extreme edition)
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
 
Csharp_Chap06
Csharp_Chap06Csharp_Chap06
Csharp_Chap06
 
Ch 4
Ch 4Ch 4
Ch 4
 
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
7986-lect 7.pdf
7986-lect 7.pdf7986-lect 7.pdf
7986-lect 7.pdf
 
PROG3040 Assignment 1 – Fall 2013 Glenn Paulley – 2A605, x25.docx
PROG3040 Assignment 1 – Fall 2013    Glenn Paulley – 2A605, x25.docxPROG3040 Assignment 1 – Fall 2013    Glenn Paulley – 2A605, x25.docx
PROG3040 Assignment 1 – Fall 2013 Glenn Paulley – 2A605, x25.docx
 
Matlab Functions
Matlab FunctionsMatlab Functions
Matlab Functions
 
C++ Homework Help
C++ Homework HelpC++ Homework Help
C++ Homework Help
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Basic c
Basic cBasic c
Basic c
 
C language tutorial
C language tutorialC language tutorial
C language tutorial
 
C standard library functions
C standard library functionsC standard library functions
C standard library functions
 
Basics1
Basics1Basics1
Basics1
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
 
Background This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docxBackground This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docx
 
Intake 37 6
Intake 37 6Intake 37 6
Intake 37 6
 

Recently uploaded

How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 

Recently uploaded (20)

How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 

Ecs40 winter 2017 homework 3

  • 1. ECS40 Winter 2017 Homework 3 To Purchase This Material Click below Link http://www.tutorialoutlet.com/all-miscellaneous/ecs- 40-winter-2017-homework-3/ FOR MORE CLASSES VISIT www.tutorialoutlet.com ECS40 Winter 2017 2017-02-22 Homework 3 due Fri 2017-03-03 at 20:00 Use the handin directory hw3 to submit your work Filling a rectangular domain with random shapes Description This assignment builds on the Shape class designed in HW2. In this assignment (HW3), you will modify the implementation of the Shape class that was developed in HW2, and implement a class Domain representing a rectangular area in the x-y plane, with functions that draw a visual representation of the domain as a scalable vector graphics (svg) file. The svg file can be visualized using a browser such as Firefox, Safari, Chrome or Internet Explorer. The domain is a rectangular array of cells that can be occupied by shapes. The goal of the assignment is to implement a program that places randomly selected shapes at random positions
  • 2. on an arbitrary rectangular domain until the domain is full, and creates a graphical representation of the domain. Figure 1: Rendering of ansvg file obtained with a 10x12 filled domain HW3 Assignment In HW3, you are given the files fill.cpp (which contains the main function) and the files Shape.h and Domain.h. You should not modify these files. Your task is to implement the class Domain by writing the file Domain.cpp and by writing a new file Shape.cpp that implements the additional specifications given in HW3. Note that the file Shape.h is different from the one given in HW2. All source files should compile without warning. You should provide a Makefile in order to be able to build the executable fill using the command $ make Input Input for the fill program is provided on the command line. It does not read input from any file. The command line arguments of the fill program are: size_xsize_y seed size_x: size of the domain (number of cells) in the x direction size_y: size of the domain (number of cells) in the y direction seed: an integer used as a seed for the random number generator rand() used in fill.cpp The program is run, for example, using the following command line:
  • 3. $ ./fill 12 10 1234 > 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
  • 4. 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 I L S X U cyan yellow purple blue orange red intgetX(int i) const Returns the x coordinate of cell i of the shape. It is assumed that the value of the argument is valid. intgetY(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
  • 5. 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: <rect <rect <rect <rect fill="blue" fill="blue" fill="blue" fill="blue" stroke="black" stroke="black" stroke="black" stroke="black" x="160" x="200" x="200" x="240" y="80" width="40" height="40"/> y="80" width="40" height="40"/> y="120" width="40" height="40"/>
  • 6. y="120" width="40" height="40"/> 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(intsize_x, intsize_y) Constructor taking as arguments the horizontal and vertical size of the domain, expressed as the number of cells in each direction. voidaddShape(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
  • 7. 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<size_x, y>=0, y<size_y) and false otherwise. bool full(void) const A function that returns true if the domain is full, (i.e. the sum of the sizes of all shapes present in the domain is equal to the total number of cells), and false otherwise. void draw(void) const This function draws the current state of the domain by printing a complete svg document on stdout. It should first print the following svg header: <?xml version="1.0" encoding="utf-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" > <svg width="670" height="670" viewBox="0 0 650 650" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" > <g transform="matrix(1,0,0,-1,50,650)"> Note that this header is fixed, i.e. it is independent of the domain size. It should then draw a frame with white background defining the domain area. For example, for a
  • 8. domain of 8x5 cells, the frame is drawn by printing <rect fill="white" stroke="black" x="0" y="0" width="320" height="200"/> Note that the width and height attributes depend on the size of the domain. It should then draw each shape on the domain by calling the shapes’ draw functions. Finally it should print the following svg trailer: </g> </svg> The resulting svg file can be visualized by opening it with a browser such as Firefox, Safari, Chrome or Internet Explorer. private members of the Domain class constintsize_x, size_y The dimensions of the domain measured in number of cells in each direction. vector<Shape*> 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.hShape.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
  • 9. 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