Xavistian

FigurasConMenu

Jun 9th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <conio.h>
  3. #include <iostream>
  4. using namespace std;
  5. using namespace System;
  6. void ImprimirMenu(int &opc)
  7. {
  8.     do {
  9.         cout << "MENU: " << endl << "1. Cuadrado. " << endl << "2. Rectangulo. " << endl << "3. Rombo. " << endl;
  10.         cin >> opc;
  11.     } while (opc != 1 && opc != 2 && opc != 3);
  12. }
  13. void ImprimirCuadrado(int a)
  14. {
  15.     do
  16.     {
  17.         cout << "Ingrese el lado del cuadrado. " << endl;
  18.         cin >> a;
  19.     } while (a <= 0);
  20.     for (int i = 0; i < a; i++)
  21.     {
  22.         for (int j = 0; j < a; j++)
  23.             cout << "* ";
  24.         cout << endl;
  25.     }
  26. }
  27. void ImprimirRectangulo(int a, int b)
  28. {
  29.     do
  30.     {
  31.     cout << "Ingrese el alto del rectangulo. " << endl;
  32.     cin >> a;
  33.     } while (a <= 0);
  34.     do
  35.     {
  36.         cout << "Ingrese el ancho del rectangulo. " << endl;
  37.         cin >> b;
  38.     } while (b <= 0);
  39.     for (int i = 0; i < a; i++)
  40.     {
  41.         for (int j = 0; j < b; j++)
  42.             cout << "* ";
  43.         cout << endl;
  44.     }
  45. }
  46. void ImprimirRombo(int a)
  47. {
  48.     do {
  49.         cout << "Ingrese la diagonal del rombo. " << endl;
  50.         cin >> a;
  51.     } while (a < 1 && a>11);
  52.     for (int i = 0; i < 2*a-1; i++)
  53.     {
  54.         for (int j = 0; j < 2*a-1; j++)
  55.         {
  56.             if (j + 2 > a - i&&j<a + i&&j>i - a&&j < 3 * a - i - 2)
  57.             {
  58.                 if (i % 2 == 0 && j % 2 == 0 || i % 2 == 1 && j % 2 == 1)
  59.                     if (a % 2 == 1)cout << '*';
  60.                     else cout << ' ';
  61.                 else
  62.                     if (a % 2 == 1) cout << ' ';
  63.                     else cout << '*';
  64.             }
  65.             else cout << ' ';
  66.         }cout << endl;
  67.     }
  68. }
  69. int main()
  70. {
  71.     int lado = 0, alto = 0, ancho = 0, diago = 0;
  72.     int opc = 0;
  73.     do {
  74.         ImprimirMenu(opc);
  75.         switch (opc)
  76.         {
  77.         case 1:ImprimirCuadrado(lado); break;
  78.         case 2:ImprimirRectangulo(alto, ancho); break;
  79.         case 3:ImprimirRombo(diago); break;
  80.         }
  81.     } while (opc != 4);
  82.     _getch();
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment