Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program that performs the given diamond images of output 1 and 2. Th

ID: 3911034 • Letter: W

Question

Write a C++ program that performs the given diamond images of output 1 and 2.
Thanks.

Assignment Reuse the asterisk diamond program and create a funcon diamond (.... that takes two values, an integer for the side of the diamond and a char value for the character printed and outputs the corresponding diamond shape. The funcon has default values, 5 for the side and for the character The user can choose to use the default values or specify new values Output Sample 1 Do you want to t e the default values? (Y/N): y *8ses 9*3 Output Sample 2 Do you want to use the default values? (Y/N):n Enter an integer for the side of the diamond: 3 Enter a char value for the character printed: Note: The output should look exactly as shown the example above

Explanation / Answer

#include<iostream>

using namespace std;

int main()

{

//variable declaration

int n;

char c;

cout<<"Do you want use the default values? (Y/N):";

cin>>c;

if(c=='y')

{

n=5;

c='*';

}

else

{

cout<<"Enter an integer for the side of the diamond: ";

cin>>n;//reading input

cout<<"Enter a char value for the character printed: ";

cin>>c;

}

int k=1,i=0,j=n,ii;

//printing diamond

while(i<n)

{

//printing space

ii=0;

while(ii<j)

{

cout<<" ";

ii++;

}

ii=0;

while(ii<k)

{

cout<<c;//printing character

ii++;

}

k+=2;

j--;

i++;

cout<<" ";

}

i--;k-=4;j+=2;

while(i>0)

{

ii=0;

while(ii<j)

{

cout<<" ";

ii++;

}

ii=0;

while(ii<k)

{

cout<<c;//printing character

ii++;

}

i--;

k-=2;

j++;

cout<<" ";

}

return 0;

}

output:

Do you want use the default values? (Y/N):n
Enter an integer for the side of the diamond: 3
Enter a char value for the character printed: #
#
###
#####
###
#


Process exited normally.
Press any key to continue . . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote