SlideShare a Scribd company logo
1 of 5
C++ Programming!
Make sure to divide the program into 3 files the header (carpet.hh) the cpp (carpet.cpp) and
main.cpp ALL THREE FILES ARE REQUIRED IN THE ANSWER.
Assignment:
Your task is to implement a mystery carpet, which applies pattern matching as shown in the
figure below.
The program receives a carpet and a pattern as its input. As its output it tells, in which positions
the pattern was found and the number of pattern instances. However, the program only has a
textual user interface (not a graphical one), so the input and output uses only ASCII characters.
Your task is to implement a mystery carpet applying pattern matching in a way described below.
The program uses five colors: R (red), G (green), B (blue), Y (yellow), and W (white). The user
can give a pattern consisting of four colors e.g. in a form as BRYG, or bryg, or Bryg. (So upper
and lower case letters can be used equally and mixed.) The colors of the carpet can be given in
the same way, but as a longer string.
For declaring colors, you must use an enum type, for example, like this:
The program starts by asking for the width and height of the carpet:
It should be asked by giving two numbers separated by an empty space. Width (the input number
given first) is a horizontal measurement, and height (the latter one) is a vertical one, which can
be seen unlogical in the case of a carpet. (To save space, it is better to draw a carpet horizontally,
and typically a horizontal measurement is called width, and a vertical one is called height.
Moreover, instead of a carpet, we could use a more general term as grid or rectangle.) Anyway,
the carpet in the figure shown at the beginning has 7 as its width and 3 as its height.
Since the size of the pattern is 2 x 2, the size of the carpet cannot be smaller than that. If one of
the given numbers is smaller than two, the program prints the following error message and
terminates with the return value EXIT_FAILURE:
If the user gave an acceptable size for the carpet, the program continues by asking a starting way
(drawing color squares randomly or reading them from the user input):
The question is repeated until the user gives either string R or I. Note that both upper-case and
lower-case letters are accepted equally.
If the user selects a way, where the carpet is created with randomly drawn colors, the program
asks next a seed value for the random number generator. After giving a seed value the program
prints the carpet of desired size, filled with random colors in a way shown above. (Each color,
also the first in line, is preceded by an empty space.)
If the user choses a non-random creation way, the program asks for the colors of the carpet and
checks if the correct amount of acceptable colors was given:
If the user gave an incorrect number of colors, the program prints the error message shown
above: Error: Wrong amount of colors. If one of the colors the user gave is not a code for an
acceptable color, the program prints the error message shown above: Error: Unknown color.
If the user input is incorrect in two ways: it has an incorrect number of colors and it contains an
unknown color, the program informs only of the first mentioned error, as can be seen in the
example above (input XYZ).
The example above shows also that after an erroneuos input, the user has the possibility to
choose the starting way again.
After giving an acceptable input, the program prints the carpet in the same way as in the starting
way with random colors: as many colors are taken from the input as is the width of the carpet,
and these colors are printed in the first line, then the same amount of colors are taken and printed
in the second line and so on.
Now, the program proceeding does not depend on the creation way any more.
Next the program asks for a pattern consisting of four colors. If the input is something else than a
color series consisting of four acceptable colors, the program prints the same error messages as
before:
Besides the acceptable color series, the user can always give the quitting command "Q" or "q",
which makes the program terminate without any prints with the return value EXIT_SUCCESS.
Let us next consider the actual going of the game:
The program prints first the coordinates, where the pattern was found (the left upper corner of
the pattern), and after that the amount of occurrences. Occurrences can be overlapping, as wywy
and rrww above.
When searching for a pattern, the carpet is gone through line by line, whereupon the program
prints first the occurrence, the line number or y-coordinate of which is the smallest (see the input
ryyy). If there are several occurrences in the same line (the same y-coordinate), the program
program prints first the occurrence, the column number or x-coordinate of which is the smallest
(see the input rrww).
The shape of the pattern is 2 x 2, but a pattern is given by listing four consecutive colors. For
example, the input BRYG means the pattern:
i.e. the first two characters are the colors of the upper line, and the latter two characters are the
colors of the lower line of the pattern. The same thing is shown in the figure below, where the
pattern can be seen on the left, and the corresponding input can be seen on the right.
Assignment
Your task is to implement a mystery carpet applying pattern matching in a way described below.
The program uses five colors: R (red), G (green), B (blue), Y (yellow), and W (white). The user
can give a pattern consisting of four colors e.g. in a form as BRYG, or bryg, or Bryg. (So upper
and lower case letters can be used equally and mixed.) The colors of the carpet can be given in
the same way, but as a longer string.
For declaring colors, you must use an enum type, for example, like this:
The program starts by asking for the width and height of the carpet:
It should be asked by giving two numbers separated by an empty space. Width (the input number
given first) is a horizontal measurement, and height (the latter one) is a vertical one, which can
be seen unlogical in the case of a carpet. (To save space, it is better to draw a carpet horizontally,
and typically a horizontal measurement is called width, and a vertical one is called height.
Moreover, instead of a carpet, we could use a more general term as grid or rectangle.) Anyway,
the carpet in the figure shown at the beginning has 7 as its width and 3 as its height.
Since the size of the pattern is 2 x 2, the size of the carpet cannot be smaller than that. If one of
the given numbers is smaller than two, the program prints the following error message and
terminates with the return value EXIT_FAILURE:
If the user gave an acceptable size for the carpet, the program continues by asking a starting way
(drawing color squares randomly or reading them from the user input):
The question is repeated until the user gives either string R or I. Note that both upper-case and
lower-case letters are accepted equally.
If the user selects a way, where the carpet is created with randomly drawn colors, the program
asks next a seed value for the random number generator. After giving a seed value the program
prints the carpet of desired size, filled with random colors in a way shown above. (Each color,
also the first in line, is preceded by an empty space.)
If the user choses a non-random creation way, the program asks for the colors of the carpet and
checks if the correct amount of acceptable colors was given:
If the user gave an incorrect number of colors, the program prints the error message shown
above: Error: Wrong amount of colors. If one of the colors the user gave is not a code for an
acceptable color, the program prints the error message shown above: Error: Unknown color.
If the user input is incorrect in two ways: it has an incorrect number of colors and it contains an
unknown color, the program informs only of the first mentioned error, as can be seen in the
example above (input XYZ).
The example above shows also that after an erroneuos input, the user has the possibility to
choose the starting way again.
After giving an acceptable input, the program prints the carpet in the same way as in the starting
way with random colors: as many colors are taken from the input as is the width of the carpet,
and these colors are printed in the first line, then the same amount of colors are taken and printed
in the second line and so on.
Now, the program proceeding does not depend on the creation way any more.
Next the program asks for a pattern consisting of four colors. If the input is something else than a
color series consisting of four acceptable colors, the program prints the same error messages as
before:
Besides the acceptable color series, the user can always give the quitting command "Q" or "q",
which makes the program terminate without any prints with the return value EXIT_SUCCESS.
Let us next consider the actual going of the game:
The program prints first the coordinates, where the pattern was found (the left upper corner of
the pattern), and after that the amount of occurrences. Occurrences can be overlapping, as wywy
and rrww above.
When searching for a pattern, the carpet is gone through line by line, whereupon the program
prints first the occurrence, the line number or y-coordinate of which is the smallest (see the input
ryyy). If there are several occurrences in the same line (the same y-coordinate), the program
program prints first the occurrence, the column number or x-coordinate of which is the smallest
(see the input rrww).
The shape of the pattern is 2 x 2, but a pattern is given by listing four consecutive colors. For
example, the input BRYG means the pattern:
i.e. the first two characters are the colors of the upper line, and the latter two characters are the
colors of the lower line of the pattern. The same thing is shown in the figure below, where the
pattern can be seen on the left, and the corresponding input can be seen on the right.
Special requirements
You must an enum type for declaring colors, for example, a type like this:
The above type can be used as an element of a vector.
C++ Programming! Make sure to divide the program into 3 files the head.docx

More Related Content

Similar to C++ Programming! Make sure to divide the program into 3 files the head.docx

Taller número 1 de informática ll
Taller número 1 de informática llTaller número 1 de informática ll
Taller número 1 de informática llramivides
 
Please help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdfPlease help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdffsenterprises
 
Assignment Poblems
Assignment Poblems Assignment Poblems
Assignment Poblems vkabre
 
Western Oregon University Page 1 of 2 CS-161.docx
 Western Oregon University            Page 1 of 2 CS-161.docx Western Oregon University            Page 1 of 2 CS-161.docx
Western Oregon University Page 1 of 2 CS-161.docxaryan532920
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments rajni kaushal
 
Create a Java non-GUI stand-alone application that displays a histog
Create a Java non-GUI stand-alone application that displays a histogCreate a Java non-GUI stand-alone application that displays a histog
Create a Java non-GUI stand-alone application that displays a histogkedsliemichal
 

Similar to C++ Programming! Make sure to divide the program into 3 files the head.docx (7)

Taller número 1 de informática ll
Taller número 1 de informática llTaller número 1 de informática ll
Taller número 1 de informática ll
 
Please help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdfPlease help. C++ The program is an interactive program th.pdf
Please help. C++ The program is an interactive program th.pdf
 
Assignment Poblems
Assignment Poblems Assignment Poblems
Assignment Poblems
 
Western Oregon University Page 1 of 2 CS-161.docx
 Western Oregon University            Page 1 of 2 CS-161.docx Western Oregon University            Page 1 of 2 CS-161.docx
Western Oregon University Page 1 of 2 CS-161.docx
 
MATLAB
MATLABMATLAB
MATLAB
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
 
Create a Java non-GUI stand-alone application that displays a histog
Create a Java non-GUI stand-alone application that displays a histogCreate a Java non-GUI stand-alone application that displays a histog
Create a Java non-GUI stand-alone application that displays a histog
 

More from BrianGHiNewmanv

Cai Corporation uses a job-order costing system and has provided the f.docx
Cai Corporation uses a job-order costing system and has provided the f.docxCai Corporation uses a job-order costing system and has provided the f.docx
Cai Corporation uses a job-order costing system and has provided the f.docxBrianGHiNewmanv
 
Cabana Cruise Line uses a combination of debt and equity to fund opera.docx
Cabana Cruise Line uses a combination of debt and equity to fund opera.docxCabana Cruise Line uses a combination of debt and equity to fund opera.docx
Cabana Cruise Line uses a combination of debt and equity to fund opera.docxBrianGHiNewmanv
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
 
C++ 10-25 LAB- Artwork label (classes-constructors) Given main()- comp.docx
C++ 10-25 LAB- Artwork label (classes-constructors) Given main()- comp.docxC++ 10-25 LAB- Artwork label (classes-constructors) Given main()- comp.docx
C++ 10-25 LAB- Artwork label (classes-constructors) Given main()- comp.docxBrianGHiNewmanv
 
By researching online find information about 2 malware samples that we.docx
By researching online find information about 2 malware samples that we.docxBy researching online find information about 2 malware samples that we.docx
By researching online find information about 2 malware samples that we.docxBrianGHiNewmanv
 
By which of the following processes are bacteria known to produce-acqu.docx
By which of the following processes are bacteria known to produce-acqu.docxBy which of the following processes are bacteria known to produce-acqu.docx
By which of the following processes are bacteria known to produce-acqu.docxBrianGHiNewmanv
 
BONUS PROBLEM ( 3 points) Ed owns 1-200 shares of ABC Corp- The compan.docx
BONUS PROBLEM ( 3 points) Ed owns 1-200 shares of ABC Corp- The compan.docxBONUS PROBLEM ( 3 points) Ed owns 1-200 shares of ABC Corp- The compan.docx
BONUS PROBLEM ( 3 points) Ed owns 1-200 shares of ABC Corp- The compan.docxBrianGHiNewmanv
 
Business ethics- 12- Introduce the abuse of official position concept.docx
Business ethics- 12- Introduce  the abuse of official position concept.docxBusiness ethics- 12- Introduce  the abuse of official position concept.docx
Business ethics- 12- Introduce the abuse of official position concept.docxBrianGHiNewmanv
 
Building a strong and ethical IT policy requires the cooperation of al.docx
Building a strong and ethical IT policy requires the cooperation of al.docxBuilding a strong and ethical IT policy requires the cooperation of al.docx
Building a strong and ethical IT policy requires the cooperation of al.docxBrianGHiNewmanv
 
Building a Project WBS and Schedule in MS Project Define Toy Requireme.docx
Building a Project WBS and Schedule in MS Project Define Toy Requireme.docxBuilding a Project WBS and Schedule in MS Project Define Toy Requireme.docx
Building a Project WBS and Schedule in MS Project Define Toy Requireme.docxBrianGHiNewmanv
 
Briefly compare-contrast right cerebral hemisphere versus left cerebra.docx
Briefly compare-contrast right cerebral hemisphere versus left cerebra.docxBriefly compare-contrast right cerebral hemisphere versus left cerebra.docx
Briefly compare-contrast right cerebral hemisphere versus left cerebra.docxBrianGHiNewmanv
 
Briefly compare-contrast resting potential versus action potential- In.docx
Briefly compare-contrast resting potential versus action potential- In.docxBriefly compare-contrast resting potential versus action potential- In.docx
Briefly compare-contrast resting potential versus action potential- In.docxBrianGHiNewmanv
 
Brite Toothbrushes has gathered the following information to complete.docx
Brite Toothbrushes has gathered the following information to complete.docxBrite Toothbrushes has gathered the following information to complete.docx
Brite Toothbrushes has gathered the following information to complete.docxBrianGHiNewmanv
 
Bridgeport Corporation engaged in the following cash transactions duri.docx
Bridgeport Corporation engaged in the following cash transactions duri.docxBridgeport Corporation engaged in the following cash transactions duri.docx
Bridgeport Corporation engaged in the following cash transactions duri.docxBrianGHiNewmanv
 
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env.docx
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env.docxBONUS- If you removed calcium (Ca2+) from a tissue's extracellular env.docx
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env.docxBrianGHiNewmanv
 
BONUS- If you rmoved calcium (Ca2+) from a tissue's extracellular envi.docx
BONUS- If you rmoved calcium (Ca2+) from a tissue's extracellular envi.docxBONUS- If you rmoved calcium (Ca2+) from a tissue's extracellular envi.docx
BONUS- If you rmoved calcium (Ca2+) from a tissue's extracellular envi.docxBrianGHiNewmanv
 
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env (1).docx
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env (1).docxBONUS- If you removed calcium (Ca2+) from a tissue's extracellular env (1).docx
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env (1).docxBrianGHiNewmanv
 
Bob paid $100 for a utility bill- Which of the following accounts will.docx
Bob paid $100 for a utility bill- Which of the following accounts will.docxBob paid $100 for a utility bill- Which of the following accounts will.docx
Bob paid $100 for a utility bill- Which of the following accounts will.docxBrianGHiNewmanv
 
Blood Circulation Across 1- supply blood to the upper limbs Down 3- ca.docx
Blood Circulation Across 1- supply blood to the upper limbs Down 3- ca.docxBlood Circulation Across 1- supply blood to the upper limbs Down 3- ca.docx
Blood Circulation Across 1- supply blood to the upper limbs Down 3- ca.docxBrianGHiNewmanv
 

More from BrianGHiNewmanv (20)

Cai Corporation uses a job-order costing system and has provided the f.docx
Cai Corporation uses a job-order costing system and has provided the f.docxCai Corporation uses a job-order costing system and has provided the f.docx
Cai Corporation uses a job-order costing system and has provided the f.docx
 
Cabana Cruise Line uses a combination of debt and equity to fund opera.docx
Cabana Cruise Line uses a combination of debt and equity to fund opera.docxCabana Cruise Line uses a combination of debt and equity to fund opera.docx
Cabana Cruise Line uses a combination of debt and equity to fund opera.docx
 
C-{2-8-10}.docx
C-{2-8-10}.docxC-{2-8-10}.docx
C-{2-8-10}.docx
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
C++ 10-25 LAB- Artwork label (classes-constructors) Given main()- comp.docx
C++ 10-25 LAB- Artwork label (classes-constructors) Given main()- comp.docxC++ 10-25 LAB- Artwork label (classes-constructors) Given main()- comp.docx
C++ 10-25 LAB- Artwork label (classes-constructors) Given main()- comp.docx
 
By researching online find information about 2 malware samples that we.docx
By researching online find information about 2 malware samples that we.docxBy researching online find information about 2 malware samples that we.docx
By researching online find information about 2 malware samples that we.docx
 
By which of the following processes are bacteria known to produce-acqu.docx
By which of the following processes are bacteria known to produce-acqu.docxBy which of the following processes are bacteria known to produce-acqu.docx
By which of the following processes are bacteria known to produce-acqu.docx
 
BONUS PROBLEM ( 3 points) Ed owns 1-200 shares of ABC Corp- The compan.docx
BONUS PROBLEM ( 3 points) Ed owns 1-200 shares of ABC Corp- The compan.docxBONUS PROBLEM ( 3 points) Ed owns 1-200 shares of ABC Corp- The compan.docx
BONUS PROBLEM ( 3 points) Ed owns 1-200 shares of ABC Corp- The compan.docx
 
Business ethics- 12- Introduce the abuse of official position concept.docx
Business ethics- 12- Introduce  the abuse of official position concept.docxBusiness ethics- 12- Introduce  the abuse of official position concept.docx
Business ethics- 12- Introduce the abuse of official position concept.docx
 
Building a strong and ethical IT policy requires the cooperation of al.docx
Building a strong and ethical IT policy requires the cooperation of al.docxBuilding a strong and ethical IT policy requires the cooperation of al.docx
Building a strong and ethical IT policy requires the cooperation of al.docx
 
Building a Project WBS and Schedule in MS Project Define Toy Requireme.docx
Building a Project WBS and Schedule in MS Project Define Toy Requireme.docxBuilding a Project WBS and Schedule in MS Project Define Toy Requireme.docx
Building a Project WBS and Schedule in MS Project Define Toy Requireme.docx
 
Briefly compare-contrast right cerebral hemisphere versus left cerebra.docx
Briefly compare-contrast right cerebral hemisphere versus left cerebra.docxBriefly compare-contrast right cerebral hemisphere versus left cerebra.docx
Briefly compare-contrast right cerebral hemisphere versus left cerebra.docx
 
Briefly compare-contrast resting potential versus action potential- In.docx
Briefly compare-contrast resting potential versus action potential- In.docxBriefly compare-contrast resting potential versus action potential- In.docx
Briefly compare-contrast resting potential versus action potential- In.docx
 
Brite Toothbrushes has gathered the following information to complete.docx
Brite Toothbrushes has gathered the following information to complete.docxBrite Toothbrushes has gathered the following information to complete.docx
Brite Toothbrushes has gathered the following information to complete.docx
 
Bridgeport Corporation engaged in the following cash transactions duri.docx
Bridgeport Corporation engaged in the following cash transactions duri.docxBridgeport Corporation engaged in the following cash transactions duri.docx
Bridgeport Corporation engaged in the following cash transactions duri.docx
 
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env.docx
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env.docxBONUS- If you removed calcium (Ca2+) from a tissue's extracellular env.docx
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env.docx
 
BONUS- If you rmoved calcium (Ca2+) from a tissue's extracellular envi.docx
BONUS- If you rmoved calcium (Ca2+) from a tissue's extracellular envi.docxBONUS- If you rmoved calcium (Ca2+) from a tissue's extracellular envi.docx
BONUS- If you rmoved calcium (Ca2+) from a tissue's extracellular envi.docx
 
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env (1).docx
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env (1).docxBONUS- If you removed calcium (Ca2+) from a tissue's extracellular env (1).docx
BONUS- If you removed calcium (Ca2+) from a tissue's extracellular env (1).docx
 
Bob paid $100 for a utility bill- Which of the following accounts will.docx
Bob paid $100 for a utility bill- Which of the following accounts will.docxBob paid $100 for a utility bill- Which of the following accounts will.docx
Bob paid $100 for a utility bill- Which of the following accounts will.docx
 
Blood Circulation Across 1- supply blood to the upper limbs Down 3- ca.docx
Blood Circulation Across 1- supply blood to the upper limbs Down 3- ca.docxBlood Circulation Across 1- supply blood to the upper limbs Down 3- ca.docx
Blood Circulation Across 1- supply blood to the upper limbs Down 3- ca.docx
 

Recently uploaded

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfChris Hunter
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.MateoGardella
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
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
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxnegromaestrong
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
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
 

Recently uploaded (20)

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
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
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
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"
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
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"
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
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
 

C++ Programming! Make sure to divide the program into 3 files the head.docx

  • 1. C++ Programming! Make sure to divide the program into 3 files the header (carpet.hh) the cpp (carpet.cpp) and main.cpp ALL THREE FILES ARE REQUIRED IN THE ANSWER. Assignment: Your task is to implement a mystery carpet, which applies pattern matching as shown in the figure below. The program receives a carpet and a pattern as its input. As its output it tells, in which positions the pattern was found and the number of pattern instances. However, the program only has a textual user interface (not a graphical one), so the input and output uses only ASCII characters. Your task is to implement a mystery carpet applying pattern matching in a way described below. The program uses five colors: R (red), G (green), B (blue), Y (yellow), and W (white). The user can give a pattern consisting of four colors e.g. in a form as BRYG, or bryg, or Bryg. (So upper and lower case letters can be used equally and mixed.) The colors of the carpet can be given in the same way, but as a longer string. For declaring colors, you must use an enum type, for example, like this: The program starts by asking for the width and height of the carpet: It should be asked by giving two numbers separated by an empty space. Width (the input number given first) is a horizontal measurement, and height (the latter one) is a vertical one, which can be seen unlogical in the case of a carpet. (To save space, it is better to draw a carpet horizontally, and typically a horizontal measurement is called width, and a vertical one is called height. Moreover, instead of a carpet, we could use a more general term as grid or rectangle.) Anyway, the carpet in the figure shown at the beginning has 7 as its width and 3 as its height. Since the size of the pattern is 2 x 2, the size of the carpet cannot be smaller than that. If one of the given numbers is smaller than two, the program prints the following error message and terminates with the return value EXIT_FAILURE: If the user gave an acceptable size for the carpet, the program continues by asking a starting way (drawing color squares randomly or reading them from the user input): The question is repeated until the user gives either string R or I. Note that both upper-case and lower-case letters are accepted equally. If the user selects a way, where the carpet is created with randomly drawn colors, the program asks next a seed value for the random number generator. After giving a seed value the program prints the carpet of desired size, filled with random colors in a way shown above. (Each color, also the first in line, is preceded by an empty space.)
  • 2. If the user choses a non-random creation way, the program asks for the colors of the carpet and checks if the correct amount of acceptable colors was given: If the user gave an incorrect number of colors, the program prints the error message shown above: Error: Wrong amount of colors. If one of the colors the user gave is not a code for an acceptable color, the program prints the error message shown above: Error: Unknown color. If the user input is incorrect in two ways: it has an incorrect number of colors and it contains an unknown color, the program informs only of the first mentioned error, as can be seen in the example above (input XYZ). The example above shows also that after an erroneuos input, the user has the possibility to choose the starting way again. After giving an acceptable input, the program prints the carpet in the same way as in the starting way with random colors: as many colors are taken from the input as is the width of the carpet, and these colors are printed in the first line, then the same amount of colors are taken and printed in the second line and so on. Now, the program proceeding does not depend on the creation way any more. Next the program asks for a pattern consisting of four colors. If the input is something else than a color series consisting of four acceptable colors, the program prints the same error messages as before: Besides the acceptable color series, the user can always give the quitting command "Q" or "q", which makes the program terminate without any prints with the return value EXIT_SUCCESS. Let us next consider the actual going of the game: The program prints first the coordinates, where the pattern was found (the left upper corner of the pattern), and after that the amount of occurrences. Occurrences can be overlapping, as wywy and rrww above. When searching for a pattern, the carpet is gone through line by line, whereupon the program prints first the occurrence, the line number or y-coordinate of which is the smallest (see the input ryyy). If there are several occurrences in the same line (the same y-coordinate), the program program prints first the occurrence, the column number or x-coordinate of which is the smallest (see the input rrww). The shape of the pattern is 2 x 2, but a pattern is given by listing four consecutive colors. For example, the input BRYG means the pattern: i.e. the first two characters are the colors of the upper line, and the latter two characters are the colors of the lower line of the pattern. The same thing is shown in the figure below, where the pattern can be seen on the left, and the corresponding input can be seen on the right.
  • 3. Assignment Your task is to implement a mystery carpet applying pattern matching in a way described below. The program uses five colors: R (red), G (green), B (blue), Y (yellow), and W (white). The user can give a pattern consisting of four colors e.g. in a form as BRYG, or bryg, or Bryg. (So upper and lower case letters can be used equally and mixed.) The colors of the carpet can be given in the same way, but as a longer string. For declaring colors, you must use an enum type, for example, like this: The program starts by asking for the width and height of the carpet: It should be asked by giving two numbers separated by an empty space. Width (the input number given first) is a horizontal measurement, and height (the latter one) is a vertical one, which can be seen unlogical in the case of a carpet. (To save space, it is better to draw a carpet horizontally, and typically a horizontal measurement is called width, and a vertical one is called height. Moreover, instead of a carpet, we could use a more general term as grid or rectangle.) Anyway, the carpet in the figure shown at the beginning has 7 as its width and 3 as its height. Since the size of the pattern is 2 x 2, the size of the carpet cannot be smaller than that. If one of the given numbers is smaller than two, the program prints the following error message and terminates with the return value EXIT_FAILURE: If the user gave an acceptable size for the carpet, the program continues by asking a starting way (drawing color squares randomly or reading them from the user input): The question is repeated until the user gives either string R or I. Note that both upper-case and lower-case letters are accepted equally. If the user selects a way, where the carpet is created with randomly drawn colors, the program asks next a seed value for the random number generator. After giving a seed value the program prints the carpet of desired size, filled with random colors in a way shown above. (Each color, also the first in line, is preceded by an empty space.) If the user choses a non-random creation way, the program asks for the colors of the carpet and checks if the correct amount of acceptable colors was given: If the user gave an incorrect number of colors, the program prints the error message shown above: Error: Wrong amount of colors. If one of the colors the user gave is not a code for an acceptable color, the program prints the error message shown above: Error: Unknown color. If the user input is incorrect in two ways: it has an incorrect number of colors and it contains an unknown color, the program informs only of the first mentioned error, as can be seen in the example above (input XYZ).
  • 4. The example above shows also that after an erroneuos input, the user has the possibility to choose the starting way again. After giving an acceptable input, the program prints the carpet in the same way as in the starting way with random colors: as many colors are taken from the input as is the width of the carpet, and these colors are printed in the first line, then the same amount of colors are taken and printed in the second line and so on. Now, the program proceeding does not depend on the creation way any more. Next the program asks for a pattern consisting of four colors. If the input is something else than a color series consisting of four acceptable colors, the program prints the same error messages as before: Besides the acceptable color series, the user can always give the quitting command "Q" or "q", which makes the program terminate without any prints with the return value EXIT_SUCCESS. Let us next consider the actual going of the game: The program prints first the coordinates, where the pattern was found (the left upper corner of the pattern), and after that the amount of occurrences. Occurrences can be overlapping, as wywy and rrww above. When searching for a pattern, the carpet is gone through line by line, whereupon the program prints first the occurrence, the line number or y-coordinate of which is the smallest (see the input ryyy). If there are several occurrences in the same line (the same y-coordinate), the program program prints first the occurrence, the column number or x-coordinate of which is the smallest (see the input rrww). The shape of the pattern is 2 x 2, but a pattern is given by listing four consecutive colors. For example, the input BRYG means the pattern: i.e. the first two characters are the colors of the upper line, and the latter two characters are the colors of the lower line of the pattern. The same thing is shown in the figure below, where the pattern can be seen on the left, and the corresponding input can be seen on the right. Special requirements You must an enum type for declaring colors, for example, a type like this: The above type can be used as an element of a vector.