Provide a loop with a menu. Repeat until the user selects Quit. Prompt the user to select one of the menu items. Test for numbers that are not in the menu, provide an error message, and then continue. The menu shall contain: 1. Square pattern 2. Triangle pattern 3. Diagonal pattern 4. Reverse diagonal pattern 5. Quit

Respuesta :

Answer:

#include<iostream>

using namespace std;

int main()

{

int i,j,k,n,ch;

do{

cout<<"\nMenu";

cout<<"\n1. Square pattern";

cout<<"\n2. Triangle pattern";

cout<<"\n3. Diaginal pattern";

cout<<"\n4. Reverse diaginal pattern";

cout<<"\n5. Quit";

cin>>ch;

switch(ch)

{

case 1: a1:

cout<<"\nEnter Size:";

cin>>n;

if(n>=1 && n<=9)

{

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{ cout<<n; }

cout<<"\n";

}

}

else

{

cout<<"\nYour Size is Out of range!!";

goto a1;}

break;

case 2:a2:

cout<<"\nEnter Size:";

cin>>n;

if(n>=1 && n<=9)

{

for(i=0;i<n;i++)

{

for(j=0;j<=i;j++)

{ cout<<n; }

}

}

else

{

cout<<"\nYour Size is Out of range!!";

goto a2;}

break;

case 3:a3:

cout<<"\nEnter Size:";

cin>>n;

if(n>=1 && n<=9)

{

for(i=0;i<n;i++)

{

for(j=0;j<i;j++)

{

cout<<"*";

}

cout<<n;

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

{

cout<<"*";

}

cout<<"\n";

}

}

else

{

cout<<"\nYour Size is Out of range!!";

goto a3;}

break;

case 4:a4:

cout<<"\nEnter Size:";

cin>>n;

if(n>=1 && n<=9)

{

for(i=0;i<n;i++)

{

for(j=1;j<n-i;j++)

{

cout<<"*";

}

cout<<n;

for(j=0;j<i;j++)

{

cout<<"*";

}

cout<<"\n";

}

}

else

{

cout<<"\nYour Size is Out of range!!";

goto a4;}

break;

case 5:

return 0;

break;

default: return 0;

}

}while(ch>0 && ch< 5);

return 0;

}

Explanation: