• Sábado 20 de Abril de 2024, 14:09

Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Temas - luchojimenez

Páginas: [1]
1
C/C++ / curvas bezier y ecuaciones polinomianles en c++
« en: Viernes 22 de Junio de 2012, 20:50 »
le adjunto  este codigo  que modela  las curvas bezier en c++ las cuales  tienen  detras  un fuerte  conceptoi matematico como polinomios  y ecuaciones parametricas
 
Código: [Seleccionar]

#include<graphics.h>
#include<math.h>
#include<conio.h>

#include<dos.h>
#include<stdio.h>
int b3p(int x0,int y0,int x1,int y1,int x2,int y2);

void main()
{
   
    int gd=DETECT,gm;// define  los controladores  de tarjeta grafica en borland c++
   
   
   
   
   
   
    initgraph(&gd,&gm,"");//inicializa el modo grafico
   
     b3p(80,280,180,0,280,280);
   
   
   
    getch();
    closegraph();
}
int b3p(int x0,int y0,int x1,int y1,int x2,int y2)
{
    double x,y,xx,yy,t=0;
    line(x0,y0,x1,y1);
   
    line(x1,y1,x2,y2);
 
       do{
    x=x0*pow(1-t,2)+ x1*2*t*(1-t)+ x2*pow(t,2);//ecuacion parametrica polinomial de grado dos
    y=y0*pow(1-t,2)+ y1*2*t*(1-t)+ y2*pow(t,2);//ecuacion parametrica para el eje Y
    putpixel(x,y,3);//dibuja  un pixel en la cordenadas x,y y color 3
   
        t=t+0.001;//incremento mediante  el cual se dibujaran  los pixeles
   
        }while(t<=2);limite por el cual se dibujan los pixeles
return 0;
}
si alguien puede hacerles  corecciones o aportes  algo  se  agradece

2
C/C++ / girasol en c++ con borland c++ 5.5
« en: Viernes 22 de Junio de 2012, 20:42 »
bueno estoy  tratando de modelar  un girasol en  c++ con  borlannd c++ 5.5  ya logre  modelar lo de adentro  con unas ecuaciones parametricas  que  me consegui  en la web  que modelan perfectamente  los granos del centro de girasol
Código: [Seleccionar]
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>


void main()
{
float x,y,ang,a,r;//xx,yy,ang1,k;
a=2.55;
//k=3.5;
int gdriver = DETECT, gmode,n;   
cout<<"dame el orden del centro del girasol un valor entre 1 a 1500"<<endl;
cin>>n;

initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
   
    //ang1=0;
    if(n<=1500)
    {
       do{
          // do{
        ang=n*137.7;
           r=a*sqrt(n);
        x=380+ r*cos(ang);
        y=290 + r*sin(ang);
        //xx=380+ r*sin(k*ang1)*cos(ang1);
           //yy=290+r*sin(k*ang1)*sin(ang1);
        putpixel(x,y,14);
           
           
       
       
         n++;
           //ang1=ang1+0.0005;               
           //}while(ang1<=70);               
       }while(n<=1700);
       
   }
   

system("pause");
   
closegraph();
}



de repente  alguien pueda  ehcarme una mano  con mi trabajo , el cual es muy autodidsacta  sobre computacion  grafica

3
C/C++ / curva de koch en c++
« en: Viernes 22 de Junio de 2012, 20:35 »
bueno estoy trabajando en codigo sobre las curvas de koch en c++  y borland c++ 5.5 todavia no he  logrado resultados  validos mas  sin embargos  les adjunto lo que he trabajado ahsta  ahora para    a ver  si alguien por  hay  puede hacerme  una correcion  de lo estoy  haciendo
Código: [Seleccionar]
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#define pi 3.141516

class tortuga{
    private:
    double x;
    double y;
    double ang;
    public:
    void tortuga(double x,double y,double ang)
{
    tortuga.x=x;
    tortuga.y=y;
    tortuga.ang=ang*pi/180;
}
void salta(double distancia)
{
double xx=x+distancia*cos(ang);
double yy=y-distancia*sin(ang);
salta(xx, yy);
}
void salta(double x, double y)
    {
this.x=x;
this.y=y;
}
 void gira(double ang)
{
    this.angulo+=angulo*pi/180;

}
void traza(double distancia){
double xx=x+distancia*Math.cos(angulo);
double yy=y-distancia*Math.sin(angulo);
Line(xx, yy, x,y);
salta(xx, yy);
}
   
};
void generaKoch(int nivel, double distancia){
if(nivel==0){
tortuga.traza(distancia);
}else{
generaKoch(nivel-1, distancia/3);
tortuga::gira(60.0);
generaKoch(nivel-1, distancia/3);
tortuga::gira(-120.0);
generaKoch(nivel-1, distancia/3);
tortuga:gira(60);
generaKoch(nivel-1, distancia/3);
}
}

void main()
{
int gdriver = DETECT, gmode,n=6;
    double d=50;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");
   
    generaKoch(n,d);
    system("pause");
closegraph();
}




4
bueno estoy explorando j2me me gustaria crear un proyectico para el colegio donde doy clases de quimica, el modelo consistiria en un formulario con las letras a,b,c y d y que ese formulario se pueda enviar por el bluetooth  a un servidor que me representen esos datos  creando curvas  que me muestren informacion de los conceptos previos de los estudiantes,en netbeans he hecho cosas pero  hasta el momento no  he probado  con el bluetooth el cual se implemta en java me  mediante  jsr 082, sera que alguien me colabora con ese proyectico

5
C/C++ / colaborar con esta idea en sdl c++
« en: Miércoles 15 de Diciembre de 2010, 20:25 »
lo  quiero  es  hacer es   es  un  interrruptor  en OFF junto  a un bombillo y  que  cuando  se presione  una tecla se ponga  en ON  y  se  encienda  el bombillo, por favor  orientacion en sdl c++, no estoy pidiendo  codigo he  adui  my  gameloop
Código: C++
  1.  
  2.  
  3. while( gameIsRunning ) { //Events //Logic //Rendering }
  4. //Game Loop while( quit == false ) { //Start the frame timer fps.start();
  5. //Events while( SDL_PollEvent( &event ) ) { myDot.handle_input(); if( event.type == SDL_QUIT ) { quit = true; } }
  6. //Logic myDot.move();
  7. //Rendering SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) ); myDot.show(); if( SDL_Flip( screen ) == -1 ) { return 1; }
  8. while( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ){} }
  9.  
  10. void Dot::handle_input() { if( event.type == SDL_KEYDOWN ) { switch( event.key.keysym.sym ) { case SDLK_UP: yVel -= DOT_HEIGHT / 2; break; case SDLK_DOWN: yVel += DOT_HEIGHT / 2; break; case SDLK_LEFT: xVel -= DOT_WIDTH / 2; break; case SDLK_RIGHT: xVel += DOT_WIDTH / 2; break; } } else if( event.type == SDL_KEYUP ) { switch( event.key.keysym.sym ) { case SDLK_UP: yVel += DOT_HEIGHT / 2; break; case SDLK_DOWN: yVel -= DOT_HEIGHT / 2; break; case SDLK_LEFT: xVel += DOT_WIDTH / 2; break; case SDLK_RIGHT: xVel -= DOT_WIDTH / 2; break; } } x += xVel; if( ( x < 0 ) || ( x + DOT_WIDTH > SCREEN_WIDTH ) ) { x -= xVel; } y += yVel; if( ( y < 0 ) || ( y + DOT_HEIGHT > SCREEN_HEIGHT ) ) { y -= yVel; } }
  11.  
  12.  
  13.  
  14.  

6
C/C++ / manejo de sprite a partir de hojas de sprite en sdl en c++
« en: Miércoles 15 de Diciembre de 2010, 04:38 »
este ejemplo  lo consegui de la pagina lazy foo  el jemplo tomaron  unos dibujos para  la  animacion  una hoja sprite , a esta animacion se llama  sprite me gustaria  que  una alma  caritativa  me explicase  mucho para poder  impplementar  el codigo  en mis propias  hojas de sprite

Código: C++
  1.  
  2. //The headers
  3. #include "SDL/SDL.h"
  4. #include "SDL/SDL_image.h"
  5. #include <string>
  6.  
  7. //Screen attributes
  8. const int SCREEN_WIDTH = 640;
  9. const int SCREEN_HEIGHT = 480;
  10. const int SCREEN_BPP = 32;
  11.  
  12. //The frames per second
  13. const int FRAMES_PER_SECOND = 10;
  14.  
  15. //The dimenstions of the stick figure
  16. const int FOO_WIDTH = 64;
  17. const int FOO_HEIGHT = 205;
  18.  
  19. //The direction status of the stick figure
  20. const int FOO_RIGHT = 0;
  21. const int FOO_LEFT = 1;
  22.  
  23. //The surfaces
  24. SDL_Surface *foo = NULL;
  25. SDL_Surface *screen = NULL;
  26.  
  27. //The event structure
  28. SDL_Event event;
  29.  
  30. //The areas of the sprite sheet
  31. SDL_Rect clipsRight[ 4 ];
  32. SDL_Rect clipsLeft[ 4 ];
  33.  
  34. //The stick figure
  35. class Foo
  36. {
  37.     private:
  38.     //The offset
  39.     int offSet;
  40.  
  41.     //Its rate of movement
  42.     int velocity;
  43.  
  44.     //Its current frame
  45.     int frame;
  46.  
  47.     //Its animation status
  48.     int status;
  49.  
  50.     public:
  51.     //Initializes the variables
  52.     Foo();
  53.  
  54.     //Handles input
  55.     void handle_events();
  56.  
  57.     //Moves the stick figure
  58.     void move();
  59.  
  60.     //Shows the stick figure
  61.     void show();
  62. };
  63.  
  64. //The timer
  65. class Timer
  66. {
  67.     private:
  68.     //The clock time when the timer started
  69.     int startTicks;
  70.  
  71.     //The ticks stored when the timer was paused
  72.     int pausedTicks;
  73.  
  74.     //The timer status
  75.     bool paused;
  76.     bool started;
  77.  
  78.     public:
  79.     //Initializes variables
  80.     Timer();
  81.  
  82.     //The various clock actions
  83.     void start();
  84.     void stop();
  85.     void pause();
  86.     void unpause();
  87.  
  88.     //Gets the timer's time
  89.     int get_ticks();
  90.  
  91.     //Checks the status of the timer
  92.     bool is_started();
  93.     bool is_paused();
  94. };
  95.  
  96. SDL_Surface *load_image( std::string filename )
  97. {
  98.     //The image that's loaded
  99.     SDL_Surface* loadedImage = NULL;
  100.  
  101.     //The optimized surface that will be used
  102.     SDL_Surface* optimizedImage = NULL;
  103.  
  104.     //Load the image
  105.     loadedImage = IMG_Load( filename.c_str() );
  106.  
  107.     //If the image loaded
  108.     if( loadedImage != NULL )
  109.     {
  110.         //Create an optimized surface
  111.         optimizedImage = SDL_DisplayFormat( loadedImage );
  112.  
  113.         //Free the old surface
  114.         SDL_FreeSurface( loadedImage );
  115.  
  116.         //If the surface was optimized
  117.         if( optimizedImage != NULL )
  118.         {
  119.             //Color key surface
  120.             SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
  121.         }
  122.     }
  123.  
  124.     //Return the optimized surface
  125.     return optimizedImage;
  126. }
  127.  
  128. void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
  129. {
  130.     //Holds offsets
  131.     SDL_Rect offset;
  132.  
  133.     //Get offsets
  134.     offset.x = x;
  135.     offset.y = y;
  136.  
  137.     //Blit
  138.     SDL_BlitSurface( source, clip, destination, &offset );
  139. }
  140.  
  141. void set_clips()
  142. {
  143.     //Clip the sprites
  144.     clipsRight[ 0 ].x = 0;
  145.     clipsRight[ 0 ].y = 0;
  146.     clipsRight[ 0 ].w = FOO_WIDTH;
  147.     clipsRight[ 0 ].h = FOO_HEIGHT;
  148.  
  149.     clipsRight[ 1 ].x = FOO_WIDTH;
  150.     clipsRight[ 1 ].y = 0;
  151.     clipsRight[ 1 ].w = FOO_WIDTH;
  152.     clipsRight[ 1 ].h = FOO_HEIGHT;
  153.  
  154.     clipsRight[ 2 ].x = FOO_WIDTH * 2;
  155.     clipsRight[ 2 ].y = 0;
  156.     clipsRight[ 2 ].w = FOO_WIDTH;
  157.     clipsRight[ 2 ].h = FOO_HEIGHT;
  158.  
  159.     clipsRight[ 3 ].x = FOO_WIDTH * 3;
  160.     clipsRight[ 3 ].y = 0;
  161.     clipsRight[ 3 ].w = FOO_WIDTH;
  162.     clipsRight[ 3 ].h = FOO_HEIGHT;
  163.  
  164.     clipsLeft[ 0 ].x = 0;
  165.     clipsLeft[ 0 ].y = FOO_HEIGHT;
  166.     clipsLeft[ 0 ].w = FOO_WIDTH;
  167.     clipsLeft[ 0 ].h = FOO_HEIGHT;
  168.  
  169.     clipsLeft[ 1 ].x = FOO_WIDTH;
  170.     clipsLeft[ 1 ].y = FOO_HEIGHT;
  171.     clipsLeft[ 1 ].w = FOO_WIDTH;
  172.     clipsLeft[ 1 ].h = FOO_HEIGHT;
  173.  
  174.     clipsLeft[ 2 ].x = FOO_WIDTH * 2;
  175.     clipsLeft[ 2 ].y = FOO_HEIGHT;
  176.     clipsLeft[ 2 ].w = FOO_WIDTH;
  177.     clipsLeft[ 2 ].h = FOO_HEIGHT;
  178.  
  179.     clipsLeft[ 3 ].x = FOO_WIDTH * 3;
  180.     clipsLeft[ 3 ].y = FOO_HEIGHT;
  181.     clipsLeft[ 3 ].w = FOO_WIDTH;
  182.     clipsLeft[ 3 ].h = FOO_HEIGHT;
  183. }
  184.  
  185. bool init()
  186. {
  187.     //Initialize all SDL subsystems
  188.     if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
  189.     {
  190.         return false;
  191.     }
  192.  
  193.     //Set up the screen
  194.     screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
  195.  
  196.     //If there was an error in setting up the screen
  197.     if( screen == NULL )
  198.     {
  199.         return false;
  200.     }
  201.  
  202.     //Set the window caption
  203.     SDL_WM_SetCaption( "Animation Test", NULL );
  204.  
  205.     //If everything initialized fine
  206.     return true;
  207. }
  208.  
  209. bool load_files()
  210. {
  211.     //Load the sprite sheet
  212.     foo = load_image( "foo.png" );
  213.  
  214.     //If there was a problem in loading the sprite
  215.     if( foo == NULL )
  216.     {
  217.         return false;
  218.     }
  219.  
  220.     //If everything loaded fine
  221.     return true;
  222. }
  223.  
  224. void clean_up()
  225. {
  226.     //Free the surface
  227.     SDL_FreeSurface( foo );
  228.  
  229.     //Quit SDL
  230.     SDL_Quit();
  231. }
  232.  
  233. Foo::Foo()
  234. {
  235.     //Initialize movement variables
  236.     offSet = 0;
  237.     velocity = 0;
  238.  
  239.     //Initialize animation variables
  240.     frame = 0;
  241.     status = FOO_RIGHT;
  242. }
  243.  
  244. void Foo::handle_events()
  245. {
  246.     //If a key was pressed
  247.     if( event.type == SDL_KEYDOWN )
  248.     {
  249.         //Set the velocity
  250.         switch( event.key.keysym.sym )
  251.         {
  252.             case SDLK_RIGHT: velocity += FOO_WIDTH / 4; break;
  253.             case SDLK_LEFT: velocity -= FOO_WIDTH / 4; break;
  254.         }
  255.     }
  256.     //If a key was released
  257.     else if( event.type == SDL_KEYUP )
  258.     {
  259.         //Set the velocity
  260.         switch( event.key.keysym.sym )
  261.         {
  262.             case SDLK_RIGHT: velocity -= FOO_WIDTH / 4; break;
  263.             case SDLK_LEFT: velocity += FOO_WIDTH / 4; break;
  264.         }
  265.     }
  266. }
  267.  
  268. void Foo::move()
  269. {
  270.     //Move
  271.     offSet += velocity;
  272.  
  273.     //Keep the stick figure in bounds
  274.     if( ( offSet < 0 ) || ( offSet + FOO_WIDTH > SCREEN_WIDTH ) )
  275.     {
  276.         offSet -= velocity;
  277.     }
  278. }
  279.  
  280. void Foo::show()
  281. {
  282.     //If Foo is moving left
  283.     if( velocity < 0 )
  284.     {
  285.         //Set the animation to left
  286.         status = FOO_LEFT;
  287.  
  288.         //Move to the next frame in the animation
  289.         frame++;
  290.     }
  291.     //If Foo is moving right
  292.     else if( velocity > 0 )
  293.     {
  294.         //Set the animation to right
  295.         status = FOO_RIGHT;
  296.  
  297.         //Move to the next frame in the animation
  298.         frame++;
  299.     }
  300.     //If Foo standing
  301.     else
  302.     {
  303.         //Restart the animation
  304.         frame = 0;
  305.     }
  306.  
  307.     //Loop the animation
  308.     if( frame >= 4 )
  309.     {
  310.         frame = 0;
  311.     }
  312.  
  313.     //Show the stick figure
  314.     if( status == FOO_RIGHT )
  315.     {
  316.         apply_surface( offSet, SCREEN_HEIGHT - FOO_HEIGHT, foo, screen, &clipsRight[ frame ] );
  317.     }
  318.     else if( status == FOO_LEFT )
  319.     {
  320.         apply_surface( offSet, SCREEN_HEIGHT - FOO_HEIGHT, foo, screen, &clipsLeft[ frame ] );
  321.     }
  322. }
  323.  
  324. Timer::Timer()
  325. {
  326.     //Initialize the variables
  327.     startTicks = 0;
  328.     pausedTicks = 0;
  329.     paused = false;
  330.     started = false;
  331. }
  332.  
  333. void Timer::start()
  334. {
  335.     //Start the timer
  336.     started = true;
  337.  
  338.     //Unpause the timer
  339.     paused = false;
  340.  
  341.     //Get the current clock time
  342.     startTicks = SDL_GetTicks();
  343. }
  344.  
  345. void Timer::stop()
  346. {
  347.     //Stop the timer
  348.     started = false;
  349.  
  350.     //Unpause the timer
  351.     paused = false;
  352. }
  353.  
  354. void Timer::pause()
  355. {
  356.     //If the timer is running and isn't already paused
  357.     if( ( started == true ) && ( paused == false ) )
  358.     {
  359.         //Pause the timer
  360.         paused = true;
  361.  
  362.         //Calculate the paused ticks
  363.         pausedTicks = SDL_GetTicks() - startTicks;
  364.     }
  365. }
  366.  
  367. void Timer::unpause()
  368. {
  369.     //If the timer is paused
  370.     if( paused == true )
  371.     {
  372.         //Unpause the timer
  373.         paused = false;
  374.  
  375.         //Reset the starting ticks
  376.         startTicks = SDL_GetTicks() - pausedTicks;
  377.  
  378.         //Reset the paused ticks
  379.         pausedTicks = 0;
  380.     }
  381. }
  382.  
  383. int Timer::get_ticks()
  384. {
  385.     //If the timer is running
  386.     if( started == true )
  387.     {
  388.         //If the timer is paused
  389.         if( paused == true )
  390.         {
  391.             //Return the number of ticks when the timer was paused
  392.             return pausedTicks;
  393.         }
  394.         else
  395.         {
  396.             //Return the current time minus the start time
  397.             return SDL_GetTicks() - startTicks;
  398.         }
  399.     }
  400.  
  401.     //If the timer isn't running
  402.     return 0;
  403. }
  404.  
  405. bool Timer::is_started()
  406. {
  407.     return started;
  408. }
  409.  
  410. bool Timer::is_paused()
  411. {
  412.     return paused;
  413. }
  414.  
  415. int main( int argc, char* args[] )
  416. {
  417.     //Quit flag
  418.     bool quit = false;
  419.  
  420.     //Initialize
  421.     if( init() == false )
  422.     {
  423.         return 1;
  424.     }
  425.  
  426.     //Load the files
  427.     if( load_files() == false )
  428.     {
  429.         return 1;
  430.     }
  431.  
  432.     //Clip the sprite sheet
  433.     set_clips();
  434.  
  435.     //The frame rate regulator
  436.     Timer fps;
  437.  
  438.     //The stick figure
  439.     Foo walk;
  440.  
  441.     //While the user hasn't quit
  442.     while( quit == false )
  443.     {
  444.         //Start the frame timer
  445.         fps.start();
  446.  
  447.         //While there's events to handle
  448.         while( SDL_PollEvent( &event ) )
  449.         {
  450.             //Handle events for the stick figure
  451.             walk.handle_events();
  452.  
  453.             //If the user has Xed out the window
  454.             if( event.type == SDL_QUIT )
  455.             {
  456.                 //Quit the program
  457.                 quit = true;
  458.             }
  459.         }
  460.  
  461.         //Move the stick figure
  462.         walk.move();
  463.  
  464.         //Fill the screen white
  465.         SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
  466.  
  467.         //Show the stick figure on the screen
  468.         walk.show();
  469.  
  470.         //Update the screen
  471.         if( SDL_Flip( screen ) == -1 )
  472.         {
  473.             return 1;
  474.         }
  475.  
  476.         //Cap the frame rate
  477.         if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
  478.         {
  479.             SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
  480.         }
  481.     }
  482.  
  483.     //Clean up
  484.     clean_up();
  485.  
  486.     return 0;
  487. }
  488.  
  489.  
  490.  
  491.  
  492.  

este  es el sprite

lo que me  gustaria saber  es  como hace sdl para procesar el orden de las posiciones  en la hoja de  sprite

7
C/C++ / sobre cgi en c++
« en: Jueves 25 de Noviembre de 2010, 22:57 »
estuve  mirando  unos  tutoriales  sobre  en cgi  en linux, es  intersando  se pueden integrar codigos  c++  a  html , no si  laguien por  ahi  sabe  de  algun  tutorial , y  sobre servidores   gratis  que  soporten esta  opcion

8
C/C++ / funciones en gaphics.h
« en: Miércoles 17 de Noviembre de 2010, 17:16 »
como agregarle  un color por ejemplo rojo al interior del circulo y  fondo gris
 
Código: C++
  1.  
  2. #include <conio.h>
  3.  
  4. #include <stdlib.h>
  5. #include <dos.h>
  6. #include <graphics.h>
  7.  
  8. void main()
  9. {
  10. int monitor=DETECT,modo;
  11. initgraph(&monitor,&modo,"C:\tc\bgi");
  12. do
  13. {
  14. circle(150,240,80);
  15. }
  16. while(!kbhit());
  17. closegraph();
  18.  
  19. }
  20.  

9
C/C++ / representar un arbol binario en modo grafico
« en: Martes 16 de Noviembre de 2010, 04:27 »
nesesito representar  un  estructura tipo arbol binario  este  es mi codigo
Código: C++
  1.  
  2. #include <conio.h>  //De aquí utilizaremos la función kbhit()
  3. #include <stdlib.h> //De aquí sacaremos la función random()
  4. #include <dos.h> //Usaremos esta librería por la función delay(int valor) que nos permite            
  5.                  //establecer un retardo en milisegundos.
  6. #include <graphics.h> //Esta es la librería que nos permite usar gráficos.
  7.  
  8. void main()
  9. {
  10.  int gdriver=DETECT, gmode, contador=0;
  11.  initgraph(&gdriver,&gmode,"C:\BORLANDC\BGI");  //Iniciamos el modo gráfico.
  12. setbkcolor(11);
  13. do
  14. {
  15.  
  16. setbkcolor(11);
  17. setcolor(11);
  18. setlinestyle(0,0,2);
  19. circle(450, 240,20);
  20. line(290,120,445,220);
  21.  
  22.  
  23.  
  24.  
  25. setcolor(11);
  26. setlinestyle(0,0,2);
  27. circle(270, 120,20);
  28. line(270,125,150,240);
  29. setfillstyle(1,RED);
  30.  
  31. setcolor(11);
  32. setlinestyle(0,0,2);
  33. circle(150,240,20);
  34.  
  35. setfillstyle(1,RED);
  36.  
  37. setcolor(11);
  38. setlinestyle(0,0,2);
  39. circle(110, 290,20);
  40. line(150,240,110,290);
  41. setfillstyle(1,RED);
  42.  
  43. setcolor(11);
  44. setlinestyle(0,0,2);
  45. line(150,240,70,350);
  46. circle(70, 350,20);
  47. setfillstyle(1,RED);
  48.  
  49. setcolor(11);
  50. setlinestyle(0,0,2);
  51. circle(130, 350,20);
  52. line(110,290,130,350);
  53. setfillstyle(1,RED);
  54.  
  55. setcolor(11);
  56. setlinestyle(0,0,2);
  57. circle(190, 350,20);
  58. line(200,300,190,350);
  59. setfillstyle(1,RED);
  60.  
  61. line(150,240,200,300);
  62.  
  63. setcolor(11);
  64. setlinestyle(0,0,2);
  65. circle(250, 350,20);
  66. line(200,300,250,350);
  67. setfillstyle(1,RED);
  68.  
  69.  
  70. setcolor(11);
  71. setlinestyle(0,0,2);
  72. circle(200, 290,20);
  73. setfillstyle(1,RED);
  74.  
  75. setcolor(11);
  76. setlinestyle(0,0,2);
  77. circle(410, 290,20);
  78. line(410,290,445,240);
  79. setfillstyle(1,RED);
  80.  
  81. setcolor(11);
  82. setlinestyle(0,0,2);
  83. circle(490, 290,20);
  84. line(490,290,445,240);
  85. setfillstyle(1,RED);
  86.  
  87. }
  88. while(!kbhit());  //Si se pulsa alguna tecla, salimos del programa.
  89.  
  90.  closegraph();     //Cerramos el modo gráfico.
  91. }
  92.  
  93.  

por  favor  colabremem quw  hasta  aqui llegue  ahora nesesito  ingresarle  los  numeros  al interior  de  circuferencencias, rellenar  con color los circulos  tal  y como seria  en un arbol  binario , en los tres  recorridos , inorden,postorden y preorden

10
C/C++ / funcion lista para trbajar con ficheros
« en: Miércoles 20 de Octubre de 2010, 16:51 »
me  encantaria  que  esta funcion  guardara  el contenido de la memoria  dinamica   en un fichero de texto, no se por donde empezar


Código: C++
  1.  
  2. void ingresar(void)
  3. {
  4. struct libro *b;
  5. char n;
  6. system("cls");
  7.  
  8.  
  9. b = (struct libro *)malloc(sizeof(struct libro));
  10. do
  11.   {
  12. system("cls");
  13. if(!b)
  14. {
  15. cout<<endl <<"no hay memoria";
  16. return;
  17. }
  18.  
  19. leecad("nIntroduce el nombre del libro: ", b->nomlib, 50);
  20. if(!b->nomlib[0]) break; //parar el proceso
  21. leecad("Introduce el autor del libro: ", b->autlib, 50);
  22. leecad("Introduce la editorial del libro: ", b->editlib, 50);
  23. leecad("Introduce el codigo ISBN: ", b->cod,30);
  24. dl_insert(b, &ppio, &final);
  25. gotoxy(5,15);cout<<"Para introducir otro libro intro S/N"<<endl;
  26. gotoxy(5,16);cin>>n;
  27.  
  28. }
  29. while((n=='s')||(n=='S'));
  30. menu();
  31. clrscr();
  32. }
  33.  
  34.  

11
C/C++ / funcion de pila solo me muestra un elemento
« en: Miércoles 20 de Octubre de 2010, 04:39 »
como les  venia  diciendo esta  funcion hace parte  de  un progrma  de una pila , pero el problema  es que solo me muestra  el primer  elemento  de la pila  ingresada no importa  si la pila  tiene  mas  elementos, entoces me  gustaria  que me colaboraran  optimizandolo


Código: C++
  1.  
  2. void visualizar (void)// funcion de la pila que le permite visualizar datos
  3. {
  4. char n;
  5. p = (struct pila*) malloc(sizeof(struct pila));
  6. if (cima==NULL)//si c esta vacio
  7. {
  8. do
  9. {
  10. clrscr();
  11. cout<<"NO HAY ELEMENTOS A LISTAR";//entoces mostrar esto
  12. gotoxy(5,19);cout<<"Desea regresar al menu principal S/N"<<endl;
  13. gotoxy(5,20);cin>>n;
  14. }
  15. while((n=='n')||(n=='N'));
  16. menu();
  17. }
  18.  
  19. else// si no
  20. {
  21. clrscr();//limpiar pantalla
  22. do
  23. {
  24. p=cima;//asignas inicio a p
  25. while (p!=NULL)//mientras la p no este vacia
  26. {
  27.  
  28. printf("primer nombre : %sn", p->prinomb);
  29. printf("segundo nombre : %sn", p->segnomb);
  30. printf("primer apellido : %sn", p->priapel);
  31. printf("segundo apellido : %sn", p->segapel);
  32. printf("cedula : %dn", p->ced);
  33. printf("edad: %dn", p->edad);
  34. printf("tel : %dn", p->tel);
  35. printf("sexo : %sn", p->sex);
  36. printf("afiliacion: %sn",p->eps);
  37. printf("E_mail: %sn", p->mail);
  38.  
  39.  
  40. p=p->sig;
  41. free(cima);
  42. gotoxy(5,19);cout<<"Desea regresar al menu principal S/N"<<endl;
  43. gotoxy(5,20);cin>>n;
  44. }
  45. }
  46. while((n=='n')||(n=='N'));
  47. menu();
  48. }
  49.  
  50. getch();
  51. }
  52.  
  53.  

12
C/C++ / parar la iteracion en esta funcion
« en: Martes 12 de Octubre de 2010, 06:07 »
bueno  es  mi  funcion visualizar de  mi pila  el problema  es  que  nesesito parar la iteacion para decidir  visualizar o seguir con introduccion de datos
Código: C++
  1.  
  2. void visualizar (void)// funcion de la pila que le permite visualizar datos
  3. {
  4. char n;
  5. p = (struct pila*) malloc(sizeof(struct pila));
  6. if (cima==NULL)//si c esta vacio
  7. {
  8. do
  9. {
  10. clrscr();
  11. cout<<"NO HAY ELEMENTOS A LISTAR";//entoces mostrar esto
  12. gotoxy(5,19);cout<<"Desea regresar al menu principal S/N"<<endl;
  13. gotoxy(5,20);cin>>n;
  14. }
  15. while((n=='n')||(n=='N'));
  16. menu();
  17. }
  18.  
  19. else// si no
  20. {
  21. clrscr();//limpiar pantalla
  22. do
  23. {
  24. p=cima;//asignas inicio a p
  25. while (p!=NULL)//mientras inicio no este vacia
  26. {
  27. clrscr();
  28. printf("Nombre : %sn", p->nombre);
  29. printf("Edad : %dn", p->ced);
  30. printf("Edad : %dn", p->edad);
  31. printf("Edad : %dn", p->tel);
  32. printf("Nombre : %sn", p->sex);
  33. printf("Nombre : %sn",p->eps);
  34. printf("Nombre : %sn", p->mail);
  35.  
  36.  
  37. p=p->sig;
  38. free(cima);
  39. gotoxy(5,19);cout<<"Desea regresar al menu principal S/N"<<endl;
  40. gotoxy(5,20);cin>>n;
  41. }
  42. }
  43. while((n=='n')||(n=='N'));
  44. menu();
  45. }
  46.  
  47. getch();
  48. }
  49.  
  50.  

13
C/C++ / por favor examinar este codigo de una estructura tipo pila
« en: Lunes 11 de Octubre de 2010, 22:18 »
hasta el momento solo llevo esto pero  tengo problemas con la funcion insertar
Código: C++
  1.  
  2. #include<iostream.h>
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<conio.h>
  6. #include<dos.h>
  7. #include<string.h>
  8.  
  9.  
  10. struct pila
  11. {
  12. char nombre[40];
  13. int ced;
  14. int edad;
  15. int tel;
  16. char sex[10];
  17. char eps[50];
  18. char mail[50];
  19. struct pila *sig;
  20. }*cima=NULL,*p=NULL;
  21. void menu();
  22. void portada();
  23. void insertar();
  24. void extraer();
  25. void visualizar ();
  26. void main()
  27. {
  28. portada();
  29. clrscr();
  30. textcolor(8);
  31.  
  32. menu();
  33.  
  34. }
  35. void portada()
  36.  
  37. {
  38. system("color 13");
  39. gotoxy(10,2);cout<<"ESTRUCTURA DE DATOS"<<endl;
  40. gotoxy(10,6);cout<<"TRABAJO COLABORATIVO NO 2"<<endl;
  41. gotoxy(10,9);cout<<"PROFESOR HERMES MOSQUERA"<<endl;
  42. gotoxy(10,14);cout<<"Powered By YAIR JOSE DIAZ GONZALEZ"<<endl;
  43. gotoxy(10,15);cout<<"UNIVERSIDAD NACIONAL ABIERTA Y A DISTANCIA(UNAD)"<<endl;
  44. gotoxy(10,19);system("pause");
  45. }
  46. void insertar() // Funcion que inserta datos a la pila
  47. {
  48. char n;
  49. struct pila *p;
  50. p = (struct pila*) malloc(sizeof(struct pila)); // reservamos
  51. // espacio para el nodo (dato, sig)
  52. clrscr();
  53.  
  54. if(cima==NULL)
  55. {
  56.  
  57. do
  58.   {
  59. p->sig = NULL; // hacemos que el nuevo nodo apunte a NULL
  60. cima = p; // Ahora el tope es el nuevo nodo
  61. clrscr();
  62. gotoxy(5,5);printf("Escriba el nombre: ");
  63. gotoxy(5,6) ;scanf("%s",p->nombre);
  64. gotoxy(5,7);printf("Dame Edad: ");
  65. gotoxy(5,8);scanf("%d",&p->edad);
  66. gotoxy(5,9);printf("Dame su telefono: ");
  67. gotoxy(5,10);scanf("%d",&p->tel);
  68. gotoxy(5,11);printf("Dame el No de  Cedula: ");
  69. gotoxy(5,12);scanf("%d",&p->ced);
  70. gotoxy(5,13);printf("Dame el sexo: ");
  71. gotoxy(5,14);scanf("%s",&p->sex);
  72. gotoxy(5,15);printf("Afiliacion a EPS o ARS: ");
  73. gotoxy(5,16);scanf("%s",&p->eps);
  74. gotoxy(5,17);printf("Deme su Email: ");
  75. gotoxy(5,18);scanf("%s",&p->mail);
  76.  
  77. gotoxy(5,21);cout<<"Para introducir otro paciente intro S/N"<<endl;
  78. gotoxy(5,22);cin>>n;
  79.  
  80. }
  81. while((n=='s')||(n=='S'));
  82.  menu();
  83.  
  84. return;
  85. }
  86.  
  87. else// si no
  88. {
  89.  
  90.  
  91. p->sig = cima; // hacemos que el nuevo nodo apunte al tope
  92. cima = p; // ahora el tope es el nuevo nodo
  93. }
  94.  
  95.  
  96.  
  97. }
  98. void extraer()
  99. {
  100. if(cima == NULL)
  101. {
  102.  
  103. printf("PILA VACIAn");
  104. return;
  105. }
  106. struct pila *tmp; // temporal para almacenar la direccion del tope
  107. tmp = cima; // guardamos en tmp la ubicacion del tope
  108. cima = tmp->sig; // hacemos que el tope sea el anterior nodo ingresado
  109. // sacamos el dato del nodo que estaba como tope
  110. printf("Nombre : %sn", tmp->nombre);
  111. printf("Edad : %dn", tmp->ced);
  112. printf("Edad : %dn", tmp->edad);
  113. printf("Edad : %dn", tmp->tel);
  114. printf("Nombre : %sn", tmp->sex);
  115. printf("Nombre : %sn", tmp->eps);
  116. printf("Nombre : %sn", tmp->mail);
  117. free(tmp); // liberamos la memoria reservada para el tope
  118. }
  119. void visualizar (void)// funcion de la pila que le permite visualizar datos
  120. {
  121. char n;
  122. if (cima==NULL)//si c esta vacio
  123. {
  124. do
  125. {
  126. clrscr();
  127. cout<<"NO HAY ELEMENTOS A LISTAR";//entoces mostrar esto
  128. gotoxy(5,19);cout<<"Desea regresar al menu principal S/N"<<endl;
  129. gotoxy(5,20);cin>>n;
  130. }
  131. while((n=='n')||(n=='N'));
  132. menu();
  133. }
  134.  
  135. else// si no
  136. {
  137. clrscr();//limpiar pantalla
  138. do
  139. {
  140. p=cima;//asignas inicio a p
  141. while (p!=NULL)//mientras inicio no este vacia
  142. {
  143. clrscr();
  144. printf("Nombre : %sn", p->nombre);
  145. printf("Edad : %dn", p->ced);
  146. printf("Edad : %dn", p->edad);
  147. printf("Edad : %dn", p->tel);
  148. printf("Nombre : %sn", p->sex);
  149. printf("Nombre : %sn",p->eps);
  150. printf("Nombre : %sn", p->mail);
  151.  
  152. cima=p;
  153. p=p->sig;
  154. free(cima);
  155. gotoxy(5,19);cout<<"Desea regresar al menu principal S/N"<<endl;
  156. gotoxy(5,20);cin>>n;
  157. }
  158. }
  159. while((n=='n')||(n=='N'));
  160. menu();
  161. }
  162.  
  163. getch();
  164. }
  165. void menu()
  166. {
  167. int opc=0;
  168. do
  169. {
  170. clrscr();
  171. gotoxy(12,3);cout<<"ASIGNADOR DE CITAS ";
  172. gotoxy(15,7);cout<<"nnn";
  173. gotoxy(15,8);cout<<"1. Insertarn";
  174. gotoxy(15,9);cout<<"2. Extraern";
  175. gotoxy(15,10);cout<<"3. Visualizarn";
  176. gotoxy(15,11);cout<<"4. Salirnn";
  177. gotoxy(15,13);cout<<"Digite la opcion: ";
  178. cin >>opc;
  179. switch (opc)
  180. {
  181. case 1:
  182. insertar();
  183. break;
  184. case 2:
  185. extraer();
  186. break;
  187. case 3:
  188. visualizar();
  189. break;
  190. case 4:
  191. exit(1);
  192. }
  193. getch();
  194. }while (opc!=4);
  195. }
  196.  
  197.  
  198.  

14
C/C++ / no se pòr que este ejercicio no compila( memoria dinamica)
« en: Martes 14 de Septiembre de 2010, 16:35 »
mi solucion es  la siguiente
Código: C++
  1.  
  2. #include<iostream.h>
  3. #include<cstdio>
  4. #include<conio.h>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10.  
  11. {
  12. int n,i;
  13. struct computador
  14. {
  15. char marca[20];
  16. char modelo[20];
  17. int calma;// capacidad de alamcenamiento
  18. int ram;
  19. }
  20. cout<<"Datos del pc"<<endl;
  21. cout<<"cuantos  pc desea ingresar"<<endl;
  22. cin>>n;
  23.  
  24. computador*compu=new int;
  25. for(i=1;i<=n;i++)
  26. {
  27. cout<<"n Dame la marca"<<endl;
  28. cin>>compu[i].marca;
  29. cout<<"n dame el modelo"<<endl;
  30. cin>>compu[i].modelo;
  31. cout<<"n  dame la cpacidad de almacenamiento"<<endl;
  32. cin>>compu[i].calma;
  33. cout<<"n Dame  capacidad memoria  Ram"<<endl;
  34. cin>>compu[i].ram;
  35.  
  36.  
  37. }
  38. clrscr();
  39. cout<<"DATOS ALMACENADOS DE LOS PC"<<endl;
  40. for(i=1;i<=n;i++)
  41. {
  42. cout<<compu[i].marca<<endl;
  43. cout<<compu[i].modelo<<endl;
  44. cout<<compu[i].calma<<endl;
  45. cout<<compu[i].ram<<endl;
  46. }
  47. system("pause");
  48. return 0;
  49. }
  50.  
  51.  
  52.  

el ejercicio es  el siguiente

Implemente un programa en C++ usando memoria dinámica con los operadores New y Delete para que imprima los datos básicos de 5 marcas comerciales de computadores, es decir (Marca, modelo, capacidad de almacenamiento, capacidad de memoria RAM instalada) para lo cual se requiere hacer usando una estructura llamada computador,  incluya variables de tipo apuntador. Como resultado se espera el código fuente debidamente documentado cada línea y la captura de pantalla de la imagen del resultado despues de la ejecución.

15
C/C++ / libreria para progrmar puerto parelelo
« en: Martes 13 de Julio de 2010, 02:04 »
no se si este tema estara  un poco trillado, pero la documentacion que es visto por internetr  es mas amplia refrente a los lenguajes pesacl, visual basic, pero poco en c++, me gustaria saber   que funciones  y  que libreria me permiten utilizar el puerto parellelo tanto  en linux  como en windows, quiero prender  un led

16
C/C++ / tengo problemas en tiempo de ejecucion no comprendo que pasa
« en: Jueves 8 de Julio de 2010, 20:29 »
este  es mi codigo estoy  intentando  implentar  la funcion de la  burbuja pero todavia  no  me da resultados  , ya logre  que  no me diera  errores en tiempo de compilacion , pero en tiempo de ejecucion todavia los errores persiten
Código: C++
  1.  
  2. #include<iostream>
  3. #include<cstdio>
  4.  
  5. using namespace std;
  6.  
  7. int ordenar( int list[],int n);
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13. int p=3;    
  14. int vi[3],i;
  15.  
  16. for(i=1;i<=3;i++)
  17. {
  18. cout<<"introduce datos del vector"<<endl;
  19. cin>>vi[i];
  20.  
  21. }
  22. cout<<ordenar(vi,p)<<endl;
  23.  
  24. system("pause");
  25. return 0;
  26. }
  27. int ordenar(int list[],int n)
  28. {
  29.    
  30. int i=1,j,aux;
  31. while(i<n)
  32. {
  33. j=i;
  34. while(j<=n-i);
  35. {
  36. if( list[j]>list[j+1])
  37. {
  38. aux=list[j];
  39. list[j]=list[j+1];
  40. list[j+1]=aux;
  41. return list[j];
  42. }
  43. j=j+1;
  44. }
  45. i=i+1;
  46. }
  47.  
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  

17
C/C++ / como hacer que este acumulador funcione
« en: Martes 6 de Julio de 2010, 05:38 »
hay  un acumlador en la  funcion ingresar, que  he ppuesto apunto me  gustaria que me  explicaran donde  este  el error, por  que este acumulador  me guarda, datos erroneos, se  que tiene  que  ver  con el do/while, pero si le cambio a for entoces  las  entradads  de cadenas correspondiente al nombre no me funcionan,



Código: C++
  1.  
  2.  
  3. #include<iostream>
  4. #include<conio2.h>
  5. #include<cstdio>
  6. #include<string.h>
  7.  
  8. using namespace std;
  9. void ingresar();
  10. void portada();
  11. void rectangulo();
  12.  
  13. int h=0,n=0,j;
  14. struct empleado{
  15. char nombre[100];
  16. int up[30];
  17. }p[3];
  18.  
  19. int main()
  20. {
  21. int l=1;
  22. portada();
  23. rectangulo();
  24. do
  25. {
  26. l++;
  27.  
  28. ingresar();
  29. }while(l<=3);
  30. system("cls");
  31. gotoxy(17,2);cout<<"ESTADISTICAS GLOBALES"<<endl;
  32.  
  33. cout<<"total producido por todo los empleadosn"<<h<<"nn";
  34. system("pause");
  35. return 0;
  36. }
  37.  
  38. void ingresar()
  39. {
  40. system("cls");
  41. int i=0,k,j=0;
  42.  
  43.  
  44. system("color 70");
  45. gotoxy(15,2);cout<<"POWERED BY LUIS ALFONSO JIMENEZ MEJIA"<<endl;
  46. gotoxy(5,9);cout<<"Ingrese Su Nombre: ";
  47. do
  48. {
  49. j++;
  50. fgets(p[j].nombre,100,stdin);
  51. p[j].nombre[strlen(p[j].nombre)-1]='';
  52. fflush(stdin);
  53. while(i<4)
  54. {
  55. i++;
  56. cout<<"ningrese las unidades producidas/dias"<<endl;
  57. cin>>p[j].up[i];
  58. n=n + p[j].up[i];//este  acumulador me  ha dado dolores de cabeza
  59. }
  60.  
  61. system("cls");
  62.  
  63. k=n/4;
  64. h=h+n;
  65.  
  66. gotoxy(17,2);cout<<"ESTADISTICAS DEL EMPLEADO: "<<p[j].nombre<<endl;
  67.  
  68. gotoxy(17,5);cout<<"Producion total mes : "<<n<<endl;
  69. gotoxy(17,6);cout<<"Promedio produccion diaria: "<<k<<endl;
  70.  
  71. }while(j<3);
  72.  
  73. gotoxy(17,15);system("pause");
  74.  
  75. }
  76.  
  77. void portada()
  78. {
  79.      system("color 0a");
  80.      gotoxy(17,2);cout<<"PROGRAMA ACTIVIDAD 1 UNIDAD 2"<<endl;
  81.      gotoxy(17,3);cout<<"CURSO C++ NIVEL 2"<<endl;
  82.      gotoxy(17,4);cout<<"POWERED BY LUIS ALFONSO JIMENEZ MEJIA"<<endl;
  83.      gotoxy(17,8);cout<<"La fabrica de carton Ciudad de Paris desea obtener"<<endl;
  84.      gotoxy(17,9);cout<<"la informacion de sus n empleados del departamento"<<endl;
  85.      gotoxy(17,10);cout<<"de produccion para poder determinar al empleado mas"<<endl;
  86.      gotoxy(17,11);cout<<"sobresaliente del mes y darle un bono de productividad de $3000,"<<endl;
  87.      gotoxy(17,12);cout<<"Desarrollar un programa en C++ que lea el nombre del empleado y"<<endl;
  88.      gotoxy(17,13);cout<<"las unidades producidas durante el mes y calcular el promedio"<<endl;
  89.      gotoxy(17,14);cout<<"de produccion, total de dias arriba del promedio,"<<endl;
  90.      gotoxy(17,15);cout<<"cantidad producida mas alta y el dia mas productivo."<<endl;
  91.      gotoxy(17,16);cout<<"Mostrar en pantalla el nombre del empleado,"<<endl;
  92.      gotoxy(17,17);cout<<"la produccion por dia, el promedio de produccion,"<<endl;
  93.      gotoxy(17,18);cout<<"el total de días arriba del promedio,"<<endl;
  94.      gotoxy(17,19);cout<<"la cantidad producida mas alta y el dia mas productivo.nn"<<endl;
  95.      gotoxy(17,25);system("pause");
  96. }
  97. void rectangulo()
  98. {  
  99.     system("cls");
  100.     system("color 75");
  101.     int height, width, tmp, tmp2;
  102.      height=19;
  103.        
  104.      width=14;
  105.          
  106.      
  107.                                              
  108.       gotoxy(2,2);for(tmp=0; tmp!=(width+1); tmp++)cout << "***";          
  109.       gotoxy(0,2);for(tmp=0; tmp!=(height); tmp++) {cout << "nx*a";    
  110.       gotoxy(0,1);for(tmp2=0; tmp2!=(height+1); tmp2++) cout << "  ";    
  111.             cout << "x*a";}                                  
  112.       cout << "n|";                                      
  113.       for(tmp=0; tmp!=(width-5); tmp++) cout << "*l*u*";          
  114.      gotoxy(15,6);cout<<"FABRICA DE CARTON"<<endl;
  115.      gotoxy(18,7);cout<<"CIUDAD PARIS"<<endl;
  116.      gotoxy(19,9);cout<<"Powered by"<<endl;
  117.      gotoxy(12,15);cout<<"LUIS ALFONSO JIMENEZ MEJIA"<<endl;                                  
  118.      
  119.       cout << "nn";
  120.       gotoxy(17,26);system("PAUSE");
  121.      
  122. }
  123.  
  124.  
  125.  
  126.  

18
C/C++ / problemas con entradas de cadenas
« en: Martes 6 de Julio de 2010, 03:40 »
problemas en esta funcion a partir  del segunda iteracion, la entrada a partir de la segunda iteracion salta
Código: C++
  1.  
  2. void ingresar()
  3. {
  4. system("cls");
  5. system("color 70");
  6. int i=0,k;
  7. gotoxy(5,4);cout<<"Ingrese Su Nombre: ";//problema a patir de la segunda iteracion
  8. fgets(p[j].nombre,100,stdin);
  9. p[j].nombre[strlen(p[j].nombre)-1]='';
  10. fflush(stdin);
  11. while(i<3)
  12. {
  13. i=i+1;
  14. cout<<"ningrese las unidades producidas/dias"<<endl;
  15. cin>>p[j].up[i];
  16. if(p[j].up[i]>p[j].up[i+1])
  17. {
  18. int aux;
  19. aux=p[j].up[i];
  20. p[j].up[i]=p[j].up[i];
  21. aux=p[j].up[i+1];
  22. }
  23. n=n + p[j].up[i];
  24. }
  25.  
  26. system("cls");
  27.  
  28. k=n/5;
  29. h=h+n;
  30. gotoxy(17,2);cout<<"ESTADISTICAS DEL EMPLEADO: "<<p[j].nombre<<endl;
  31. gotoxy(17,5);cout<<"Producion total mes : "<<n<<endl;
  32. gotoxy(17,6);cout<<"Promedio produccion diaria: "<<k<<endl;
  33. gotoxy(17,15);system("pause");
  34. }
  35.  
  36.  
  37.  
  38.  

19
C/C++ / funcion algoritmo de la burbuja
« en: Lunes 5 de Julio de 2010, 01:11 »
que pasara  con este codigo,lo que quiero es definir el algoritmo de la burbuja en una funcion listo

Código: C++
  1.  
  2. int orden(int v[p])
  3. {
  4. int aux,i,p;
  5.  
  6. for(i=1;i<p;i++)
  7. {
  8. int aux;
  9. if(v[k]>v[k+1])
  10. {
  11. return
  12. aux=v[k];
  13. v[k]=v[k+1];
  14. v[k+1]=aux;
  15. }
  16. }
  17. }
  18.  
  19.  

20
C/C++ / funcion de entrada que no se cuelgue
« en: Sábado 3 de Julio de 2010, 19:54 »
estoy trabajndo  en un codigo con vectores , donde tengo  que introducir un  valor tipo cadena , el problema  es que la primera iteracion del ciclo for  anda bien , pero cuando voy  a introducir  la cadena de caracteres en la segunda iteracion del ciclo for, salta en esta parte , no dejandome ingresar los valores tipo cadena de caracteres mejor les pongo  el codigo  y juzguen ud mismos;
Código: C++
  1.  
  2.  
  3. #include<iostream>
  4. #include<conio2.h>
  5. #include<cstdio>
  6. #include<string.h>
  7.  
  8. using namespace std;
  9. void ingresar();
  10. int l,j;
  11. struct empleado{
  12. char nombre[25];
  13. int up[30];
  14. }p[30];
  15.  
  16. int main()
  17. {
  18.  
  19. for(j=1;j<=30;j++)
  20. {
  21. system("cls");
  22. ingresar();
  23. }
  24. system("pause");
  25. return 0;
  26. }
  27.  
  28. void ingresar()
  29. {
  30. int i=0,k,n=0;
  31. cout<<"nningrese su nombre: ";
  32. cin.getline(p[j].nombre,70);//me gustaria reemplazar esta funcion por otra
  33. //que se funcional en todo el ciclo for
  34. while(i<5)
  35. {
  36. i=i+1;
  37. cout<<"ningrese las unidades producidas/dias"<<endl;
  38. cin>>p[j].up[i];
  39.  
  40. n=n + p[j].up[i];
  41.  
  42. }
  43. system("cls");
  44. k=n/5;
  45. cout<<" producion total mes/empleado: "<<n<<endl;
  46. cout<<"promedio produccion dia/empleado: "<<k<<endl;
  47. system("pause");
  48. }
  49.  
  50.  
  51.  

21
C/C++ / problemas con clases en c++
« en: Jueves 1 de Julio de 2010, 21:40 »
aqui tengo este codigo , pero no se  que  puede estar mal, en realidad estoy comenzando a trabajr con clases ademas  del codigo si no es mucha molestia  le ruego  me expliquen  un poco
Código: C++
  1.  
  2.  
  3.  
  4. #include<iostream>
  5. #include<cstdio>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. class rect
  11. {
  12. public:
  13.        
  14. float calcarea();
  15. void setlargo(float largo);
  16. void setancho(float ancho);
  17. float getlargo();
  18. float getancho();
  19. private:
  20.          
  21. float ancho,largo;
  22. float rect::largo()
  23. {
  24. return ancho*largo;
  25. }
  26. void rect::setlargo( float la)
  27.      {
  28.           largo = la;
  29.      }
  30.      float rect::getlargo()
  31.      {
  32.           return largo;
  33.      }
  34.  void rect::setancho( float anc)
  35.      {
  36.           ancho = anc;
  37.      }
  38.      float rect::getancho()
  39.      {
  40.           return ancho;
  41.      }      // insert your code here
  42. }
  43. int main()
  44. {
  45. float lar,anch;
  46. cout<<"introduce el largo"<<endl;
  47. cin>>lar;
  48. cout<<"introduce el ancho"<<endl;
  49. cin>>anch;
  50. rect a;
  51. a.setancho(anch);
  52. a.setlargo(lar);
  53. cout<<"area del rectangulo "<<a.calcarea()<<endl;
  54. system("pause");
  55. return 0;
  56. }
  57.  
  58.  
  59.  

22
C/C++ / como asociar dos arreglos unidimensionales
« en: Jueves 1 de Julio de 2010, 18:03 »
tengo una  duda acerca de los arreglos  unidimensionales como enlazar dos  arreglos ejemplo arreglo nombre[] y sueldo[], yo conozco una forma  con estruct , pero me gustaria  emplearla, me gustaria que fueran solo  arreglos y que sean unidimensionales

23
C/C++ / optimizar este codigo
« en: Domingo 27 de Junio de 2010, 22:45 »
la verdad  que  navegando por  ahi  hice  un salpicon de  lo  que  encontre  en la web  sobre  el problema d e las  fechas ,este  codigo lo que trata  de  hacer  es decir la edad  en base  ala fecha d e nacimiento, yo utilice  la  fecha  del sistema  como referencia para  sacar la edad(utilice la libreria time.h) , pero  todavia tengo un inconveniente  cuando  la persona  tiene  menos  de  un año quiero que la edad  en meses  sea  limpia  pero todavia he  tenido dificultades , la verdad es  que  el problema  le  invertido bastante  tiempo, me gustaria que  me echaran una manito para darle  el toque  final
Código: C++
  1.  
  2.  
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include<time.h>
  6. #include<stdio.h>
  7. #include <iostream>
  8.  
  9. using namespace std;
  10.  
  11. struct Time
  12. {
  13.  int d,m,y;
  14. };
  15.  
  16. struct Time horalocal()
  17. {
  18.  struct Time mt;
  19.  struct tm *local;
  20.  time_t t;
  21.  t=time(NULL);
  22.  local=localtime(&t);
  23.  mt.d=local->tm_mday;
  24.  mt.m=local->tm_mon+1;
  25.  mt.y=local->tm_year+1900;
  26.  return mt;
  27. }
  28.  
  29.  
  30. float fechanac(struct Time t)
  31. {
  32.  struct Time h;
  33.  float year;
  34.  
  35.  
  36.  h=horalocal();
  37.  year=h.y-t.y;
  38.  if(h.y-t.y>1)
  39.  {
  40.  if(h.m < t.m)
  41.   year--;
  42.  
  43.  else if(h.m == t.m && h.d < t.d)
  44.   year--;
  45.    
  46. }
  47. else if((h.y-t.y>0)&&(h.y-t.y<=1))
  48. {
  49. if(h.m>t.m)
  50.  
  51. {year=h.m - t.m;
  52. cout<<"ntienes "<<year<<" mesesn";}
  53. else if(t.m>h.m)
  54.  
  55. {year=t.m-h.m;
  56. cout<<"ntienes "<<year<<" mesesn";
  57. }
  58.  
  59. }
  60.  return year;
  61.  
  62. }
  63. void nombre()
  64. {
  65.      system("color 75");
  66.      cout<<"nnn";
  67.      cout<<"                        ==========================="<<endl;
  68.      cout<<"                        =      Programa  Para     ="<<endl;
  69.      cout<<"                        =           Saber         ="<<endl;
  70.      cout<<"                        =          LA Edad        ="<<endl;
  71.      cout<<"                        ==========================="<<endl;
  72.      cout<<"                      By Powered Luis Alfonso Jimenez"<<"nnnn"<<endl;
  73.      system("PAUSE");
  74.      system("cls");    
  75.  }
  76. int main()
  77. {
  78.  char res;
  79.  do
  80.  {
  81.  nombre();
  82.  system("color 74");
  83.  struct Time fech;
  84.  cout<<"nnintroduce el dia en que naciste"<<endl;
  85.  cout<<"==================================="<<endl;    
  86.  cin>>fech.d ;
  87.  cout<<"ahora el mes   (un numero 1-12)"<<endl;
  88.  cout<<"==================================="<<endl;
  89.  cin>>fech.m ;
  90.  cout<<"ahora el anio"<<endl;
  91.  cout<<"==================================="<<endl;
  92.  cin>>fech.y;
  93.    if(fechanac(fech)<1)
  94.    {cout<<"nnTienes "<<fechanac(fech)<<"  meses........nnn"<<endl;}
  95.  if((fechanac(fech)>0)&&(fechanac(fech)<30))
  96.  {cout<<"nnTienes "<<fechanac(fech)<<"  años........nnn"<<endl;}
  97.  else if((fechanac(fech)>30)&&(fechanac(fech)<40))
  98.  {cout<<"nnTienes "<<fechanac(fech)<<"  años..... y estas en el tercer escalon picarooooon...nnn"<<endl;}
  99.  else if((fechanac(fech)>=40)&&(fechanac(fech)<=50))
  100.  {cout<<"nnTienes "<<fechanac(fech)<<"  anios..... y estas en el cuarto escalon picarooooon...n...Todo lo que sube tienen caer jajajajannn"<<endl;}
  101.  else if(fechanac(fech)>=50)
  102.  {cout<<"nnTienes "<<fechanac(fech)<<"  anios..... y estas en la tercera edad picarooooon...n...Perdona que te lo diga pero hueles  camajonnnn"<<endl;}
  103.  getchar();
  104.  cout<<"nnnnn Si deseas continuar into S/N"<<endl;
  105.  cin>>res;
  106.   system("pause");
  107.   system("cls");
  108. }
  109.  while((res=='s')||(res=='S'));
  110.  
  111.  
  112.  return 0;
  113. }
  114.  
  115.  
  116.  

Páginas: [1]