/* * Programador: Julio Cesar Hernandez Hernandez * Materia: Divercion * Fecha: 30/06/2011 Escuela: ITSDZapopan * Carrera: Ing. En Sistemas Computacionales * Descripcion: Recreacion de los Giros en el * Cubo de Rubik en 3 Dimensiones */ #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int cubo[3][3][3]; int mtem[3][3][3]; int t; void guarda(); void imprime_cubo(); void menu(); void gira_frente_izquierda(); void gira_frente_derecha(); void gira_izquierda_arriba(); void gira_izquierda_abajo(); void gira_derecha_arriba(); void gira_derecha_abajo(); void gira_arriba_izquierda(); void gira_arriba_derecha(); void gira_abajo_izquierda(); void gira_abajo_derecha(); void gira_fondo_izquierda(); void gira_fondo_derecha(); int main(){ int i = 1; for(int f = 0; f < 3; f++){ for(int l = 0; l < 3; l++){ for(int a = 0; a < 3; a++){ cubo[f][l][a] = i; mtem[f][l][a] = i; i++; } } } menu(); return EXIT_SUCCESS; } void guarda(){ for(int f = 0; f < 3; f++){ for(int l = 0; l < 3; l++){ for(int a = 0; a < 3; a++){ cubo[f][l][a] = mtem[f][l][a]; } } } } void imprime_cubo(){ for(int f = 0; f < 3; f++){ for(int l = 0; l < 3; l++){ for(int a = 0; a < 3; a++){ cout<<setw(4)<<cubo[f][l][a]; } cout<<endl; } cout<<endl; } } void menu(){ int opc = 0; while(opc != 14){ system("cls"); cout << "Cubo de 3 dimenciones (:Selecciona una opcion) :"<<endl << " 1) Mostrar Cubo"<<endl << " 2) Girar Frente Izquierda"<<endl << " 3) Girar Frente Derecha"<<endl << " 4) Girar Fondo Izquierda"<<endl << " 5) Girar Fondo Derecha"<<endl << " 6) Girar Izquierda Arriba"<<endl << " 7) Girar Izquierda Abajo"<<endl << " 8) Girar Derecha Arriba"<<endl << " 9) Girar Derecha Abajo"<<endl << " 10) Girar Arriba Izquierda"<<endl << " 11) Girar Arriba Derecha"<<endl << " 12) Girar Abajo Izquierda"<<endl << " 13) Girar Abajo Derecha"<<endl << " 14) Salir"<<endl; cin>>opc; switch(opc){ case 1: imprime_cubo(); system("Pause>nul"); break; case 2: gira_frente_izquierda(); break; case 3: gira_frente_derecha(); break; case 4: gira_fondo_izquierda(); break; case 5: gira_fondo_derecha(); break; case 6: gira_izquierda_arriba(); break; case 7: gira_izquierda_abajo(); break; case 8: gira_derecha_arriba(); break; case 9: gira_derecha_abajo(); break; case 10: gira_arriba_izquierda(); break; case 11: gira_arriba_derecha(); break; case 12: gira_abajo_izquierda(); break; case 13: gira_abajo_derecha(); break; case 14: cout<<"Programa Hecho Por Julio Cesar Hernandez Hernandez"; break; default: cout<<"Error de seleccion"; system("Pause>nul"); break; } } } void gira_frente_izquierda(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[0][t][x] = cubo[0][x][y]; } t++; } guarda(); } void gira_frente_derecha(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[0][x][t] = cubo[0][y][x]; } t++; } guarda(); } void gira_izquierda_arriba(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[0][t][x] = cubo[0][x][y]; } t++; } guarda(); } void gira_izquierda_abajo(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[x][t][0] = cubo[y][x][0]; } t++; } guarda(); } void gira_derecha_arriba(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[t][x][2] = cubo[x][y][2]; } t++; } guarda(); } void gira_derecha_abajo(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[x][t][2] = cubo[y][x][2]; } t++; } guarda(); } void gira_arriba_izquierda(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[t][0][x] = cubo[x][0][y]; } t++; } guarda(); } void gira_arriba_derecha(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[x][0][t] = cubo[y][0][x]; } t++; } guarda(); } void gira_abajo_izquierda(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[t][2][x] = cubo[x][2][y]; } t++; } guarda(); } void gira_abajo_derecha(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[x][2][t] = cubo[y][2][x]; } t++; } guarda(); } void gira_fondo_izquierda(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[2][t][x] = cubo[2][x][y]; } t++; } guarda(); } void gira_fondo_derecha(){ t = 0; for(int y = 2; y >= 0; --y){ for(int x = 0; x < 3; x++){ mtem[2][x][t] = cubo[2][y][x]; } t++; } guarda(); }
Páginas
NIMADRES
Mostrando entradas con la etiqueta una. Mostrar todas las entradas
Mostrando entradas con la etiqueta una. Mostrar todas las entradas
Girar Una Matriz De Tres dimensiones [Cubo de Rukbi] En C++
Agenda Archivos Grafica en Java
import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.JButton; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Agenda extends JFrame implements ActionListener { private JLabel lbl1, lbl3, lbl4; private JTextField edtbienvenida, edtnombre, edtedad, edtdireccion; private JButton btnlimpiar, btnsalir, btnguardar, btnconsultar; private String texto; public Scanner stdIn = new Scanner (System.in); private JMenuBar bar; private JMenu menu1,menu2,menu3,menu5,menu4; private JMenuItem submenu1,submenu2,submenu3,submenu5; private char archivo; private String hospotal; public Agenda() { setTitle("Agenda"); bar = new JMenuBar(); bar.setBounds(0,0,185,20); menu1 = new JMenu ("Archivo"); menu2 = new JMenu("Acciones"); menu3 = new JMenu("Edición"); bar.add(menu1); bar.add(menu2); bar.add(menu3); submenu1 = new JMenuItem("Salir"); submenu2 = new JMenuItem("Limpiar"); submenu3 = new JMenuItem("Consultar"); menu1.add(submenu1); menu2.add(submenu2); menu2.add(submenu3); edtbienvenida = new JTextField(" Agenda*"); edtbienvenida.setBounds(0,20,185,20); edtbienvenida.setEditable(false); lbl1 = new JLabel("Nombre:"); lbl1.setBounds(10,40,80,20); edtnombre = new JTextField(""); edtnombre.setBounds(100,40,80,20); edtnombre.setEditable(true); lbl3 = new JLabel("Edad:"); lbl3.setBounds(10,60,80,20); edtedad = new JTextField(""); edtedad.setBounds(100,60,80,20); lbl4 = new JLabel("Direccion:"); lbl4.setBounds(10,80,80,20); edtdireccion = new JTextField(""); edtdireccion.setBounds(100,80,80,20); btnlimpiar = new JButton("Limpiar"); btnlimpiar.setBounds(10,100,80,30); btnguardar = new JButton("Guardar"); btnguardar.setBounds(100,100,80,30); btnsalir = new JButton("Salir"); btnsalir.setBounds(100,135,80,30); btnconsultar = new JButton("Consultar"); btnconsultar.setBounds(10,135,80,30); btnlimpiar.addActionListener(this); btnsalir.addActionListener(this); btnguardar.addActionListener(this); btnconsultar.addActionListener(this); submenu1.addActionListener(this); submenu2.addActionListener(this); submenu3.addActionListener(this); getContentPane().add(btnlimpiar); getContentPane().add(btnconsultar); getContentPane().add(btnsalir); getContentPane().add(btnguardar); getContentPane().add(lbl1); getContentPane().add(lbl3); getContentPane().add(lbl4); getContentPane().add(edtbienvenida); getContentPane().add(edtnombre); getContentPane().add(edtedad); getContentPane().add(edtdireccion); getContentPane().add(bar); setSize(200,210); setLayout(null); setVisible(true); } public void consultar()throws IOException { Scanner fileIn; String line; try{ fileIn = new Scanner(new FileReader("Agenda.CSV")); while(fileIn.hasNextLine()){ line = fileIn.nextLine(); JOptionPane.showMessageDialog(null,line + "\n"); } fileIn.close(); } catch(FileNotFoundException e){ System.out.println("Error : " + e.getMessage()); } } public void Guardar()throws IOException { try{ PrintWriter fileOut; fileOut = new PrintWriter(new FileWriter("Agenda.CSV",true)); String line = (edtnombre.getText()+","+edtedad.getText()+","+ ""+edtdireccion.getText()); fileOut.println(line); fileOut.close(); } catch(IOException e){ System.err.println("Error : " + e.getMessage()); } } public void actionPerformed (ActionEvent e) { if (e.getSource().equals(submenu1)) { System.exit(0); } if (e.getSource().equals(submenu3)) { try { consultar(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } if (e.getSource().equals(btnconsultar)) { try { consultar(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } if (e.getSource().equals(submenu2)) { edtnombre.setText(""); edtedad.setText(""); edtdireccion.setText(""); } if(e.getSource().equals(btnsalir)) { System.exit(0); } if(e.getSource().equals(btnlimpiar)) { edtnombre.setText(""); edtedad.setText(""); edtdireccion.setText(""); } if(e.getSource().equals(btnguardar)) { try { Guardar(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } /** * @param args */ public static void main(String[] args) { Agenda x = new Agenda(); // TODO Auto-generated method stub } }
Suscribirse a:
Entradas (Atom)