Question

Input a number [1-50] representing the size of the shape and then a character [x,b,f] which represents the shape i.e. x->cros

0 0
Add a comment Improve this question Transcribed image text
Answer #1

pattern.cpp

#include<iostream>

using namespace std;

void printCross(int n)

{

int i,j,k;

if(n%2) //odd number of lines

{

for(int i=n;i>=1;i--)

{

for(int j=n;j>=1;j--)

{

if(j==i || j==(n-i+1))

cout<<j;

else

cout<<" ";

}

cout<<"\n";

}

}

else //even number of lines

{

for(int i=1;i<=n;i++)

{

for(int j=1;j<=n;j++)

{

if(j==i || j==(n-i+1))

{

cout<<" "<<j<<" ";

}

else

cout<<" ";

}

cout<<"\n";

}

}

}

void printForwardSlash(int n)

{

if(n%2)

{

for(int i=n;i>=1;i--)

{

for(int j=n;j>=1;j--)

{

if(j==n-i+1)

{

cout<<j;

}

else

cout<<" ";

}

cout<<"\n";

}

}

else

{

for(int i=1;i<=n;i++)

{

for(int j=1;j<=n;j++)

{

if(j==(n-i+1))

{

cout<<j;

}

else

cout<<" ";

}

cout<<"\n";

}

}

}

void printBackwardSlash(int n)

{

if(n%2) // odd number of lines

{

for(int i=n;i>=1;i--)

{

for(int j=n;j>=1;j--)

{

if(j==i)

{

cout<<j;

}

else

cout<<" ";

}

cout<<"\n";

}

}

else //even number of lines

{

for(int i=1;i<=n;i++)

{

for(int j=1;j<=n;j++)

{

if(j==i)

{

cout<<j;

}

else

cout<<" ";

}

cout<<"\n";

}

}

}

int main()

{

int num;

char ch;

cout<<"Create a numberes shape that can be sized."<<endl;

cout<<"Input an integer [1,50] and a character [x,b,f]."<<endl;

cin>>num>>ch;

if(ch=='x' || ch=='X')

printCross(num);

else if(ch=='f' || ch=='F')

printForwardSlash(num);

else if(ch=='b' || ch=='B')

printBackwardSlash(num);

else

cout<<"\nWrong input"<<endl;

return 0;

}

OUTPUT

- 5 X TE: HOMEWORK\pattern.exe Create a numberes shape that can be sized. Input an integer (1,50) and a character [x,b,f]. 20- 5 X TE: HOMEWORK\pattern.exe Create a numberes shape that can be sized. Input an integer (1,50] and a character [x,b,f]. 10- 5 X TE: HOMEWORK\pattern.exe Create a numberes shape that can be sized. Input an integer (1,50] and a character [x,b,f]. 13

Add a comment
Know the answer?
Add Answer to:
Input a number [1-50] representing the size of the shape and then a character [x,b,f] which...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT