SlideShare a Scribd company logo
1 of 4
Download to read offline
Part I:
/*****************************************************************************
***
* DIAMONDS
* author(s):
* adapted from:
* other citations:
*
* goal: Output a diamond of user determined size must use a 2D array.
* example: for input of 5 ..*.. or 6 ../..
* .***. .//.
* ***** ///
* .***. ///
* ..*.. .//.
* ../..
* overview: (1) get user input & validate (i.e. less than screen size)
* (2) determine even/odd and how to proceed
* (3) create & fill array accordingly
* (4) output to screen
*
*
* stages: (1) hard-coded 5x5 diamond - output to screen
* must use given function def - passes in one row at a time
* (2) Do odd number case only in this stage - subtract 1 from any even #
* get width of diamond from user (use same number for height)
* create a 2D array of that size and fill with the background char
* must use given function defs - passes in one row at a time
* (3) Now we overload fillArray - don't duplicate code. If the same code
* is being run then one fillArray function should call the other
* Add in the diamond forming character (the MAIN_CHAR)
* This stage should complete the odd case
* (4) Using the same functions as the previous case, do the even case
*
*
*****************************************************************************
***/
#include
using namespace std;
const unsigned int max_width = 120;
char background_char = '.';
char main_char = '*';
char main_char_left = '/';
char main_char_right = '';
/* function prototype declarations (defined below in same file) */
void printArray (const char chArray[], const unsigned int width) {
for (unsigned int i = 0; i < width; i++) {
cout << chArray[i];
}
}
int main()
{
/* variables */
/* declare and initialize an array */
char diamond[5][5] = {{background_char, background_char, main_char,background_char,
background_char},
{background_char,main_char, main_char, main_char, background_char},
{main_char, main_char, main_char, main_char, main_char},
{background_char,main_char, main_char, main_char, background_char},
{background_char, background_char, main_char,background_char,
background_char}};
/* output array */
for (int i = 0; i < 5; i++) {
printArray(diamond[i], 5);
cout << endl;
}
When input 10:
When input 40:
When input 4000:
In this stage we will complete the odd-number input case, adding stars to create the diamond. So
if the user enters 15 , the program should output: To do this, we will overload the fillarray()
function. The following function definition is required: void fillarray (char fill, char chArray[],
unsigned int start, unsigned int end); where fillArray would fill the indices from start to end-1
(not including end). When overloading, we should not be duplicating code. It is likely that the
efficient way to overload is for one of the fillArray () functions to call the other. Everything else
would work the same as in Part II.
Expected output Enter width of diamond: Error! Max width is 120 . Exiting.
Enter width of diamond: ...***... .. kk. . . . . .
Part IV Finally, we will complete the even number case. This case will use the same fillArray ()
and printArray () functions written for the previous part. There are constant variables given for
the characters in the original Part I template: char background_char = '.'; char main_char = '*';
char main_char_left =1/; char main_char_right =; char background_char = '.'; char main_char =
'*'; char main_char_left =1/; char main_char_right = '; For example, for an input of 16 we
would get:
Enterwidthofdiamond:16,//////////////////.////////////////////////////////
///////////, Everything else would work the same as in Part III.
begin{tabular}{|c|c|} hline Expected output &
Enterwidthofdiamond:./////.//////////////////////  hline end{tabular}
In this part, we will add getting the size input from the user and writing a function to fill the
array. For this stage, we will only fill the array with the background character, and we will only
work on the odd number case. So if the user enters an even number, subtract one to get the array
width. It is a requirement to use the given definition of the fillArray function, with these exact
parameters, which is: void fillArray (char fill, char charray[], unsigned int width); So for
example, if the user enters 10 , the program should output the following grid (which is 9
characters wide): where 10 is the user input and "Enter width of diamond: "is the prompt given
to the user by the program.

More Related Content

Similar to Part I.pdf

Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfmohdjakirfb
 
#include iostream #include string #include fstream std.docx
#include iostream #include string #include fstream  std.docx#include iostream #include string #include fstream  std.docx
#include iostream #include string #include fstream std.docxajoy21
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014Supriya Radhakrishna
 
Problem Implement a FIFO program in which a client sends the server.pdf
Problem Implement a FIFO program in which a client sends the server.pdfProblem Implement a FIFO program in which a client sends the server.pdf
Problem Implement a FIFO program in which a client sends the server.pdffeelinggift
 
WHAT TO DOUpdate the comment boxes at the top of each function in.pdf
WHAT TO DOUpdate the comment boxes at the top of each function in.pdfWHAT TO DOUpdate the comment boxes at the top of each function in.pdf
WHAT TO DOUpdate the comment boxes at the top of each function in.pdfadityavision1
 
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
 
2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt2. Data, Operators, IO.ppt
2. Data, Operators, IO.pptswateerawat06
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 Lab 2 Histrogram generation   Author Naga Kandasamy  .docx Lab 2 Histrogram generation   Author Naga Kandasamy  .docx
Lab 2 Histrogram generation Author Naga Kandasamy .docxaryan532920
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfARCHANASTOREKOTA
 
Error correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-cError correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-cMd Nazmul Hossain Mir
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questionsSrikanth
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3Srikanth
 
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfAssignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfsktambifortune
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxssuser454af01
 
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docxThere are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docxAustinIKkNorthy
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineMatt Provost
 

Similar to Part I.pdf (20)

Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
Write a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdfWrite a program that converts an infix expression into an equivalent.pdf
Write a program that converts an infix expression into an equivalent.pdf
 
#include iostream #include string #include fstream std.docx
#include iostream #include string #include fstream  std.docx#include iostream #include string #include fstream  std.docx
#include iostream #include string #include fstream std.docx
 
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
M.TECH 1ST SEM COMPUTER SCIENCE AOS LAB PRGMS 2014
 
Circular queue
Circular queueCircular queue
Circular queue
 
Problem Implement a FIFO program in which a client sends the server.pdf
Problem Implement a FIFO program in which a client sends the server.pdfProblem Implement a FIFO program in which a client sends the server.pdf
Problem Implement a FIFO program in which a client sends the server.pdf
 
WHAT TO DOUpdate the comment boxes at the top of each function in.pdf
WHAT TO DOUpdate the comment boxes at the top of each function in.pdfWHAT TO DOUpdate the comment boxes at the top of each function in.pdf
WHAT TO DOUpdate the comment boxes at the top of each function in.pdf
 
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)
 
09 Jo P Sep 07
09 Jo P Sep 0709 Jo P Sep 07
09 Jo P Sep 07
 
2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt2. Data, Operators, IO.ppt
2. Data, Operators, IO.ppt
 
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 Lab 2 Histrogram generation   Author Naga Kandasamy  .docx Lab 2 Histrogram generation   Author Naga Kandasamy  .docx
Lab 2 Histrogram generation Author Naga Kandasamy .docx
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Error correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-cError correction-and-type-of-error-in-c
Error correction-and-type-of-error-in-c
 
C aptitude questions
C aptitude questionsC aptitude questions
C aptitude questions
 
C - aptitude3
C - aptitude3C - aptitude3
C - aptitude3
 
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdfAssignment of SOS operating systemThe file lmemman.c has one incom.pdf
Assignment of SOS operating systemThe file lmemman.c has one incom.pdf
 
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docxfilesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
filesHeap.h#ifndef HEAP_H#define HEAP_H#includ.docx
 
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docxThere are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
There are 5 C++ files below- Card-h- Card-cpp- Deck-h- Deck-cpp- Main-.docx
 
#include deck.h .pdf
#include deck.h .pdf#include deck.h .pdf
#include deck.h .pdf
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command Line
 

More from support58

Please show me your output. Andrew Kelly has been employed by the We.pdf
Please show me your output. Andrew Kelly has been employed by the We.pdfPlease show me your output. Andrew Kelly has been employed by the We.pdf
Please show me your output. Andrew Kelly has been employed by the We.pdfsupport58
 
Please show me how to do every part of this. Also could you show me .pdf
Please show me how to do every part of this. Also could you show me .pdfPlease show me how to do every part of this. Also could you show me .pdf
Please show me how to do every part of this. Also could you show me .pdfsupport58
 
Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdfsupport58
 
please help! Carmen Company has the following projected costs for .pdf
please help! Carmen Company has the following projected costs for .pdfplease help! Carmen Company has the following projected costs for .pdf
please help! Carmen Company has the following projected costs for .pdfsupport58
 
Please help will upvote. I have a heuristic function that outputs th.pdf
Please help will upvote. I have a heuristic function that outputs th.pdfPlease help will upvote. I have a heuristic function that outputs th.pdf
Please help will upvote. I have a heuristic function that outputs th.pdfsupport58
 
Please create a simple flowchart of this programtell me the necess.pdf
Please create a simple flowchart of this programtell me the necess.pdfPlease create a simple flowchart of this programtell me the necess.pdf
Please create a simple flowchart of this programtell me the necess.pdfsupport58
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfsupport58
 
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdf
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdfPlease answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdf
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdfsupport58
 
Plan production for a four-month period (February through May). .pdf
Plan production for a four-month period (February through May). .pdfPlan production for a four-month period (February through May). .pdf
Plan production for a four-month period (February through May). .pdfsupport58
 
Part 1 During the most recent economic crisis in the state of Arizo.pdf
Part 1 During the most recent economic crisis in the state of Arizo.pdfPart 1 During the most recent economic crisis in the state of Arizo.pdf
Part 1 During the most recent economic crisis in the state of Arizo.pdfsupport58
 

More from support58 (10)

Please show me your output. Andrew Kelly has been employed by the We.pdf
Please show me your output. Andrew Kelly has been employed by the We.pdfPlease show me your output. Andrew Kelly has been employed by the We.pdf
Please show me your output. Andrew Kelly has been employed by the We.pdf
 
Please show me how to do every part of this. Also could you show me .pdf
Please show me how to do every part of this. Also could you show me .pdfPlease show me how to do every part of this. Also could you show me .pdf
Please show me how to do every part of this. Also could you show me .pdf
 
Please help with the below 3 questions, the python script is at the.pdf
Please help with the below 3  questions, the python script is at the.pdfPlease help with the below 3  questions, the python script is at the.pdf
Please help with the below 3 questions, the python script is at the.pdf
 
please help! Carmen Company has the following projected costs for .pdf
please help! Carmen Company has the following projected costs for .pdfplease help! Carmen Company has the following projected costs for .pdf
please help! Carmen Company has the following projected costs for .pdf
 
Please help will upvote. I have a heuristic function that outputs th.pdf
Please help will upvote. I have a heuristic function that outputs th.pdfPlease help will upvote. I have a heuristic function that outputs th.pdf
Please help will upvote. I have a heuristic function that outputs th.pdf
 
Please create a simple flowchart of this programtell me the necess.pdf
Please create a simple flowchart of this programtell me the necess.pdfPlease create a simple flowchart of this programtell me the necess.pdf
Please create a simple flowchart of this programtell me the necess.pdf
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
 
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdf
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdfPlease answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdf
Please answer ASAP!!!Research Topic Ransomware attack on k-12 sch.pdf
 
Plan production for a four-month period (February through May). .pdf
Plan production for a four-month period (February through May). .pdfPlan production for a four-month period (February through May). .pdf
Plan production for a four-month period (February through May). .pdf
 
Part 1 During the most recent economic crisis in the state of Arizo.pdf
Part 1 During the most recent economic crisis in the state of Arizo.pdfPart 1 During the most recent economic crisis in the state of Arizo.pdf
Part 1 During the most recent economic crisis in the state of Arizo.pdf
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 

Recently uploaded (20)

9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 

Part I.pdf

  • 1. Part I: /***************************************************************************** *** * DIAMONDS * author(s): * adapted from: * other citations: * * goal: Output a diamond of user determined size must use a 2D array. * example: for input of 5 ..*.. or 6 ../.. * .***. .//. * ***** /// * .***. /// * ..*.. .//. * ../.. * overview: (1) get user input & validate (i.e. less than screen size) * (2) determine even/odd and how to proceed * (3) create & fill array accordingly * (4) output to screen * * * stages: (1) hard-coded 5x5 diamond - output to screen * must use given function def - passes in one row at a time * (2) Do odd number case only in this stage - subtract 1 from any even # * get width of diamond from user (use same number for height) * create a 2D array of that size and fill with the background char * must use given function defs - passes in one row at a time * (3) Now we overload fillArray - don't duplicate code. If the same code * is being run then one fillArray function should call the other * Add in the diamond forming character (the MAIN_CHAR) * This stage should complete the odd case * (4) Using the same functions as the previous case, do the even case * * *****************************************************************************
  • 2. ***/ #include using namespace std; const unsigned int max_width = 120; char background_char = '.'; char main_char = '*'; char main_char_left = '/'; char main_char_right = ''; /* function prototype declarations (defined below in same file) */ void printArray (const char chArray[], const unsigned int width) { for (unsigned int i = 0; i < width; i++) { cout << chArray[i]; } } int main() { /* variables */ /* declare and initialize an array */ char diamond[5][5] = {{background_char, background_char, main_char,background_char, background_char}, {background_char,main_char, main_char, main_char, background_char}, {main_char, main_char, main_char, main_char, main_char}, {background_char,main_char, main_char, main_char, background_char}, {background_char, background_char, main_char,background_char, background_char}}; /* output array */ for (int i = 0; i < 5; i++) { printArray(diamond[i], 5); cout << endl; } When input 10:
  • 3. When input 40: When input 4000: In this stage we will complete the odd-number input case, adding stars to create the diamond. So if the user enters 15 , the program should output: To do this, we will overload the fillarray() function. The following function definition is required: void fillarray (char fill, char chArray[], unsigned int start, unsigned int end); where fillArray would fill the indices from start to end-1 (not including end). When overloading, we should not be duplicating code. It is likely that the efficient way to overload is for one of the fillArray () functions to call the other. Everything else would work the same as in Part II. Expected output Enter width of diamond: Error! Max width is 120 . Exiting. Enter width of diamond: ...***... .. kk. . . . . . Part IV Finally, we will complete the even number case. This case will use the same fillArray () and printArray () functions written for the previous part. There are constant variables given for the characters in the original Part I template: char background_char = '.'; char main_char = '*'; char main_char_left =1/; char main_char_right =; char background_char = '.'; char main_char = '*'; char main_char_left =1/; char main_char_right = '; For example, for an input of 16 we would get: Enterwidthofdiamond:16,//////////////////.//////////////////////////////// ///////////, Everything else would work the same as in Part III. begin{tabular}{|c|c|} hline Expected output & Enterwidthofdiamond:./////.////////////////////// hline end{tabular}
  • 4. In this part, we will add getting the size input from the user and writing a function to fill the array. For this stage, we will only fill the array with the background character, and we will only work on the odd number case. So if the user enters an even number, subtract one to get the array width. It is a requirement to use the given definition of the fillArray function, with these exact parameters, which is: void fillArray (char fill, char charray[], unsigned int width); So for example, if the user enters 10 , the program should output the following grid (which is 9 characters wide): where 10 is the user input and "Enter width of diamond: "is the prompt given to the user by the program.