public struct Metodologia {
public Planteamiento planteamiento;
public Analisis analisis;
public struct Planteamiento {
public string parametros;
public string[] acciones;
public string expresionRetorno;
int cant = acciones.Length + 2, i = 1;
flujo = new string[cant][];
string cabecera = nombre + "(" + parametros +" )";
string retorno = "Retornar " + expresionRetorno;
if(nombre=="Main") { cabecera ="INICIO";retorno="FIN";}
flujo[0] = Terminal(cabecera);
for (i = 0; i < acciones.Length;i++ ) {
orden = "" + acciones[i][0].ToString();
flujo[i+1] = Rectangulo(acciones[i].Substring(3));
flujo[i+1] = Rectangulo(acciones[i].Substring(3));
flujo[i+1] = Lectura(acciones[i].Substring(3));
flujo[i+1] = Mostrar(acciones[i].Substring(3));
flujo[i+1] = Mostrar(acciones[i].Substring(3));
flujo[i+1] = SubProceso(acciones[i].Substring(3));
flujo[cant - 1] = Terminal(retorno);
public void DibujarFlujo()
Console.WriteLine("\n"+new string(' ',42)+"Modulo: "+nombre+" Estático: si Público: si");
foreach (string[] figura in flujo) {
Console.WriteLine(new string(' ',62)+vertical);
foreach (string linea in figura) {
int len = linea.Length / 2;
Console.WriteLine(new string(' ', 62 - len) + linea);
public static string[] Terminal(string contenido)
const int BORDE_SUP=0,BORDE_INF=2, CENTRO=1;
string paralela = (contenido == "INICIO" || contenido == "FIN") ? " " : "|";
string[] figura = new string[3];
figura[BORDE_SUP] = "" + new string('_', contenido.Length + 4);
figura[CENTRO] = string.Format("({1} {0} {1})", contenido, paralela);
figura[BORDE_INF] = "" + new string('¯', contenido.Length + 4);
public static string[] Rectangulo(string contenido)
string[] figura = new string[5] { "", "", "", "", "" };
const int BORDE_SUP=0,BORDE_INF=4,CENTRO=2,ESPACIO_SUP=1,ESPACION_INF=3;
for (int linea = BORDE_SUP; linea <= BORDE_INF; linea++) {
if (linea > BORDE_SUP && linea < BORDE_INF)
else if (linea == BORDE_SUP)
for (int col = 2; col < contenido.Length + 4; col++) {
if (linea == BORDE_SUP || linea == BORDE_INF)
if (linea != CENTRO && linea != BORDE_SUP && linea != BORDE_INF)
figura[linea] += string.Format(" {0} ", contenido);
if (linea > BORDE_SUP && linea < BORDE_INF)
else if (linea == BORDE_SUP)
public static string[] Lectura(string contenido)
{ const int BORDE_SUP=0,BORDE_INF=4, CENTRO =2, ESP_SUP=1,ESP_INF=3;
string[] figura = new string[5];
int ancho = contenido.Length;
figura[BORDE_SUP] = " " + new string('_', ancho + 4) + "_";
figura[ESP_SUP] = " /" + new string(' ', ancho + 4) + "/";
figura[CENTRO] = " / " + contenido + " / ";
figura[ESP_INF] = " /" + new string(' ', ancho + 4) + "/ ";
figura[BORDE_INF] = "/" + new string('_', ancho + 4) + "/ ";
public static string[] Mostrar(string contenido)
const int BORDE_SUP=0,BORDE_INF=4, CENTRO =2, ESP_SUP=1,ESP_INF=3;
string[] figura = new string[5];
int ancho = contenido.Length;
figura[BORDE_SUP] = " " + new string('_', ancho + 4) + " ";
figura[ESP_SUP] = " /" + new string(' ', ancho + 4) + "|";
figura[CENTRO] = " / " + contenido + " |";
figura[ESP_INF] = " \\ " + new string(' ', ancho + 4) + "|";
figura[BORDE_INF] = " \\" + new string('_', ancho + 4) + "| ";
public static string[] SubProceso(string contenido)
string[] figura = new string[5] { "", "", "", "", "" };
const int BORDE_SUP=0,BORDE_INF=4,CENTRO=2,ESPACIO_SUP=1,ESPACION_INF=3;
for (int linea = BORDE_SUP; linea <= BORDE_INF; linea++) {
if (linea > BORDE_SUP && linea < BORDE_INF)
else if (linea == BORDE_SUP)
for (int col = 2; col < contenido.Length + 4; col++) {
if (linea == BORDE_SUP || linea == BORDE_INF)
if (linea != CENTRO && linea != BORDE_SUP && linea != BORDE_INF)
figura[linea] += string.Format(" {0} ", contenido);
if (linea > BORDE_SUP && linea < BORDE_INF)
else if (linea == BORDE_SUP)
public string[][] topDown;
public void CrearTopDown() {
int cant = modulo.Length+2;
topDown= new string[cant][];
topDown[0]=Modulo.Rectangulo(paquete);
topDown[1]=Modulo.Rectangulo(clase);
for(int i = 0;i<modulo.Length;i++)
topDown[i+2]=Modulo.Rectangulo(modulo[i].nombre);
public void DibujarTopDown() {
string[] nivel3=new string[5]{"","","","",""};
foreach(string[] figura in topDown) {
if(vertical!="") Console.WriteLine(new string(' ',62)+vertical);
foreach (string linea in figura) {
len = linea.Length / 2;vertical="|";
Console.WriteLine(new string(' ', 62 - len) + linea);
nivel3[j++]+=linea+" ";vertical="";}
len = nivel3[0].Length/2;
Console.WriteLine(new string(' ', 62 - len+6) +"┌"+new string('-', len-7)+"|"+ new string('-', len-10)+"┐");
foreach(string n in nivel3)
Console.WriteLine(new string(' ', 62 - len) + n);
public void DibujarFlujo() {
foreach(Modulo m in modulo) {
public static void Main(string[] args)
Console.ForegroundColor=ConsoleColor.Green;
Console.BackgroundColor=ConsoleColor.Black;
Solucion solucion = new Solucion();
solucion.paquete="BalmoreGT07EjStruct";
solucion.clase="Program";
solucion.modulo = new Modulo[5];
solucion.modulo[0].nombre = "Main";
solucion.modulo[0].parametros = "";
solucion.modulo[0].acciones = new string[6];
solucion.modulo[0].acciones[0] = "A::PI=3.141592";
solucion.modulo[0].acciones[1] = "M::'SOLUCION: Area y Volumen dado el Radio'";
solucion.modulo[0].acciones[2] = "A::radio=LeerRadio()";
solucion.modulo[0].acciones[3] = "A::area=CalcularArea(radio)";
solucion.modulo[0].acciones[4] = "A::volumen=CalcularVolumen(radio)";
solucion.modulo[0].acciones[5] = "S::Imprimir(radio,area,volumen)";
solucion.modulo[0].expresionRetorno = "";
solucion.modulo[1].nombre = "LeerRadio";
solucion.modulo[1].parametros="";
solucion.modulo[1].acciones = new string[2];
solucion.modulo[1].acciones[0] = "M::'Ingrese radio>0'";
solucion.modulo[1].acciones[1] = "L::radio";
solucion.modulo[1].expresionRetorno = "radio";
solucion.modulo[2].nombre = "CalcularArea";
solucion.modulo[2].parametros="radio";
solucion.modulo[2].acciones = new string[1];
solucion.modulo[2].acciones[0] = "A::area = PI * radio * radio";
solucion.modulo[2].expresionRetorno = "area";
solucion.modulo[3].nombre = "CalcularVolumen";
solucion.modulo[3].parametros="radio";
solucion.modulo[3].acciones = new string[1];
solucion.modulo[3].acciones[0] = "A::volumen = 4/3.0 * radio * CalcularArea(radio)";
solucion.modulo[3].expresionRetorno = "volumen";
solucion.modulo[4].nombre = "Imprimir";
solucion.modulo[4].parametros="radio,area,volumen";
solucion.modulo[4].acciones = new string[3];
solucion.modulo[4].acciones[0] = "I::'RESULTADOS. para radio=',radio";
solucion.modulo[4].acciones[1] = "I::'Area = ',area,' u2'";
solucion.modulo[4].acciones[2] = "I::'Volumen = ',volumen,' u3'";
solucion.modulo[3].expresionRetorno = "volumen";
solucion.DibujarTopDown();
Console.Write("Press any key to continue . . . ");