Expresión In-fija a Posfija en C/C++ explicando paso a paso como se llega a la Posfija y obteniendo el resultado de la función ingresada.
Echo en Dev C++,
Código:
#include <cstdlib>
#include <iostream>
#include <string>
#include <stack>
#include <cmath>
using namespace std;
/* Operadores matematicos */
#define N_operators 6
const string operators[N_operators] = {"+", "-", "*", "/", "%", "^"};
int precedences[N_operators] = {1, 1, 2, 2, 2, 3};
bool is_operator( const string );
int precedence( const string );
int main() {
string infix, postfix, token;
stack <string> standby;
stack <double> result;
size_t i;
char c;
double A, B;
system("color f9");
/* Cadena de entrada */
cout <<"\n\tGRUPO N 1 \n"<<endl;
cout <<"\t Programa para ingresar una exprecion Infija a posfija \n y resolver la exprecion Posfija. "<<endl;
cout << "\nEscriba la expresion infija: ">
getline( cin, infix );
cout << endl;
/*************************************************************
PRIMERA PARTE: Procesar la cadena infijo, y crear posfijo
*************************************************************/
for ( i = 0; i < infix.size(); i++ ) {
/* esto debe cambiar luego a un token o palabra devuelta por
* el analizador léxico */
c = infix[i];
token.clear();
token += c; /* parece burdo, pero no conozco mejor manera de
* crear un string a partir de un unico caracter */
/* es un espacio: despreciar */
if ( c == ' ' ) continue;
cout << " '" << c << "'" << endl;
/* es un carácter numérico: pasar al posfijo */
if ( c >= '0' && c <= '9' ) {
cout << "\tes numero: pasado a posfijo" << endl << endl;
postfix = postfix + " " + c;
continue;
}
/* si se lee un operador: sacar de la pila y pasar al postfijo
* todos los operadores con una precedencia mayor o igual a la
* suya, y depositar el mismo en la pila */
if ( is_operator( token ) ) {
cout << "\tes operador:" << endl;
while ( !standby.empty() && precedence( standby.top() )
>= precedence( token ) ) {
cout << "\tpasado operador '" + standby.top() +
"' de la pila a posfijo" << endl;
postfix = postfix + " " + standby.top();
standby.pop();
}
standby.push( token );
cout << "\tcolocar '" << token << "' en la pila" << endl << endl;
continue;
}
/* si se lee "(": colocar en la pila */
if ( token == "(" ) {
cout << "pasado a posfijo" << endl << endl;
standby.push( token );
continue;
}
/* si se lee ")": retirar de la pila hasta encontrar '(', y pasar
* los elementos retirados a posfijo, luego descartar el "(" */
if ( token == ")" ) {
while ( !standby.empty() && standby.top() != "(" ) {
cout << "\tpasado operador '" + standby.top() +
"' de la pila a posfijo" << endl << endl;
postfix = postfix + " " + standby.top();
standby.pop();
}
if ( !standby.empty() )
standby.pop(); /* descartar el "(" */
}
}
/* extraer de la pila cualquier operador restante y pasarlo a la cadena posfijo */
while ( !standby.empty() ) {
cout << "Pasado operador '" + standby.top() +
"' de la pila a posfijo" << endl << endl;
postfix = postfix + " " + standby.top();
standby.pop();
}
/* Imprimir el posfijo */
cout << "Posfijo es: \n\t" << postfix << endl << endl;
/****************************************************************
SEGUNDA PARTE: Procesar la cadena posfijo, y devolver resultado
****************************************************************/
A = 0;
cout << "Evaluando la expresion ..." << endl;
for ( i = 0; i < postfix.size(); i++ ) {
c = postfix[i];
token.clear();
token += c;
/* si se lee un operando (caracter numerico), depositar en la pila */
if ( c >= '0' && c <= '9' ) {
result.push( c - '0' );
continue;
}
/* si se lee un operador binario, poner en A y B los últimos dos argumentos
* de la pila y operarlos, guardando el resultado en la pila */
if ( is_operator( token ) ) {
if ( !result.empty() ) {
B = result.top();
result.pop();
}
else {
cout << "Argumentos insuficientes para '" << c << "'" << endl;
return -1;
}
if ( !result.empty() ) {
A = result.top();
result.pop();
}
else {
cout << "Argumentos insuficientes para '" << c << "'" << endl;
return -1;
}
cout << "\toperar " << A << token << B << " = ";
if ( token == "+" ) {
A += B;
result.push( A );
}
else if ( token == "-" ) {
A -= B;
result.push( A );
}
else if ( token == "*" ) {
A *= B;
result.push( A );
}
else if ( token == "/" ) {
A /= B;
result.push( A );
}
else if ( token == "%" ) {
A = (int )A % (int )B;
result.push( A );
}
else if ( token == "^" ) {
A = pow(A, B);
result.push( A );
}
cout << A << endl;
}
}
if ( !result.empty() )
cout << endl << "El resultado es: " << result.top() << endl;
return 0;
}
/* Verdadero si el token corresponde a un operador. */
bool is_operator( const string token ) {
for ( int i = 0; i < N_operators; i++ )
if ( operators[i] == token )
return true;
return false;
}
/* Devuelve la precedencia del operador descrito por el
* string token (-1 si no es un operador) */
int precedence( const string token ) {
for ( int i = 0; i < N_operators; i++ )
if ( operators[i] == token )
return precedences[i];
return -1;
}
Echo en Dev C++,
Código:
#include <cstdlib>
#include <iostream>
#include <string>
#include <stack>
#include <cmath>
using namespace std;
/* Operadores matematicos */
#define N_operators 6
const string operators[N_operators] = {"+", "-", "*", "/", "%", "^"};
int precedences[N_operators] = {1, 1, 2, 2, 2, 3};
bool is_operator( const string );
int precedence( const string );
int main() {
string infix, postfix, token;
stack <string> standby;
stack <double> result;
size_t i;
char c;
double A, B;
system("color f9");
/* Cadena de entrada */
cout <<"\n\tGRUPO N 1 \n"<<endl;
cout <<"\t Programa para ingresar una exprecion Infija a posfija \n y resolver la exprecion Posfija. "<<endl;
cout << "\nEscriba la expresion infija: ">
getline( cin, infix );
cout << endl;
/*************************************************************
PRIMERA PARTE: Procesar la cadena infijo, y crear posfijo
*************************************************************/
for ( i = 0; i < infix.size(); i++ ) {
/* esto debe cambiar luego a un token o palabra devuelta por
* el analizador léxico */
c = infix[i];
token.clear();
token += c; /* parece burdo, pero no conozco mejor manera de
* crear un string a partir de un unico caracter */
/* es un espacio: despreciar */
if ( c == ' ' ) continue;
cout << " '" << c << "'" << endl;
/* es un carácter numérico: pasar al posfijo */
if ( c >= '0' && c <= '9' ) {
cout << "\tes numero: pasado a posfijo" << endl << endl;
postfix = postfix + " " + c;
continue;
}
/* si se lee un operador: sacar de la pila y pasar al postfijo
* todos los operadores con una precedencia mayor o igual a la
* suya, y depositar el mismo en la pila */
if ( is_operator( token ) ) {
cout << "\tes operador:" << endl;
while ( !standby.empty() && precedence( standby.top() )
>= precedence( token ) ) {
cout << "\tpasado operador '" + standby.top() +
"' de la pila a posfijo" << endl;
postfix = postfix + " " + standby.top();
standby.pop();
}
standby.push( token );
cout << "\tcolocar '" << token << "' en la pila" << endl << endl;
continue;
}
/* si se lee "(": colocar en la pila */
if ( token == "(" ) {
cout << "pasado a posfijo" << endl << endl;
standby.push( token );
continue;
}
/* si se lee ")": retirar de la pila hasta encontrar '(', y pasar
* los elementos retirados a posfijo, luego descartar el "(" */
if ( token == ")" ) {
while ( !standby.empty() && standby.top() != "(" ) {
cout << "\tpasado operador '" + standby.top() +
"' de la pila a posfijo" << endl << endl;
postfix = postfix + " " + standby.top();
standby.pop();
}
if ( !standby.empty() )
standby.pop(); /* descartar el "(" */
}
}
/* extraer de la pila cualquier operador restante y pasarlo a la cadena posfijo */
while ( !standby.empty() ) {
cout << "Pasado operador '" + standby.top() +
"' de la pila a posfijo" << endl << endl;
postfix = postfix + " " + standby.top();
standby.pop();
}
/* Imprimir el posfijo */
cout << "Posfijo es: \n\t" << postfix << endl << endl;
/****************************************************************
SEGUNDA PARTE: Procesar la cadena posfijo, y devolver resultado
****************************************************************/
A = 0;
cout << "Evaluando la expresion ..." << endl;
for ( i = 0; i < postfix.size(); i++ ) {
c = postfix[i];
token.clear();
token += c;
/* si se lee un operando (caracter numerico), depositar en la pila */
if ( c >= '0' && c <= '9' ) {
result.push( c - '0' );
continue;
}
/* si se lee un operador binario, poner en A y B los últimos dos argumentos
* de la pila y operarlos, guardando el resultado en la pila */
if ( is_operator( token ) ) {
if ( !result.empty() ) {
B = result.top();
result.pop();
}
else {
cout << "Argumentos insuficientes para '" << c << "'" << endl;
return -1;
}
if ( !result.empty() ) {
A = result.top();
result.pop();
}
else {
cout << "Argumentos insuficientes para '" << c << "'" << endl;
return -1;
}
cout << "\toperar " << A << token << B << " = ";
if ( token == "+" ) {
A += B;
result.push( A );
}
else if ( token == "-" ) {
A -= B;
result.push( A );
}
else if ( token == "*" ) {
A *= B;
result.push( A );
}
else if ( token == "/" ) {
A /= B;
result.push( A );
}
else if ( token == "%" ) {
A = (int )A % (int )B;
result.push( A );
}
else if ( token == "^" ) {
A = pow(A, B);
result.push( A );
}
cout << A << endl;
}
}
if ( !result.empty() )
cout << endl << "El resultado es: " << result.top() << endl;
return 0;
}
/* Verdadero si el token corresponde a un operador. */
bool is_operator( const string token ) {
for ( int i = 0; i < N_operators; i++ )
if ( operators[i] == token )
return true;
return false;
}
/* Devuelve la precedencia del operador descrito por el
* string token (-1 si no es un operador) */
int precedence( const string token ) {
for ( int i = 0; i < N_operators; i++ )
if ( operators[i] == token )
return precedences[i];
return -1;
}
Infija a Posfija resolviendo la expresión con Resultado
En una PILA ingresaremos caracteres y números a una pila con las funciones Agregar, Eliminar, Mostrar y Destruir la pila.
Código:
#include<iostream>
#include<cstdlib>
using namespace std;
struct nodo{
char let;// usamos char para poder obtener los caractere para la pila
struct nodo *sgte;
};
typedef struct nodo *Puntero;
class Pila{
public:
Pila(void);
void Apilar(int );
int Desapilar(void );
void tope(void);
bool PilaVacia(void);
void MostrarPila(void);
void DestruirPila(void);
private:
Puntero Tope;
};
Pila::Pila(void){
Tope=NULL;
}
bool Pila::PilaVacia(void){
if(Tope==NULL)
return true;
else
return false;
}
void Pila::Apilar(int x){
Puntero p_aux;
p_aux=new(struct nodo);
p_aux->let=x;
p_aux->sgte=Tope;
Tope=p_aux;
}
//eliminara el elemento del tope de la pila ingresado
int Pila::Desapilar(void){
int x;
Puntero p_aux;
if(Tope==NULL)
cout<<"\n\n\tLa Pila esta Vacia.";
else{
p_aux=Tope;
x=p_aux->let;
Tope=Tope->sgte;
delete(p_aux);
}
return x;
}
//NOS MOSTRARA TOTODS LOS ELELMENTOS INGRESADOS ASI COMO LOS CARACTERES Y NUMEROS EN LA PILA
void Pila::MostrarPila(void){
Puntero p_aux;
p_aux=Tope;
while(p_aux!=NULL){
cout<<"\t\t\t "<<p_aux->let<<endl;
p_aux=p_aux->sgte;
}
}
//DESTRUYE LA PILA POR COMPLETAMENTE DEGANDOLA VACIA.
void Pila::DestruirPila(void){
Puntero p_aux;
while(Tope!=NULL){
p_aux=Tope;
Tope=Tope->sgte;
delete(p_aux);
}
}
void menu(void)
{
cout<<"\n\t PILA CON CARACTERES Y NUMERSO \n\n";
cout<<" \t 1. AGREGAR A LA PILA "<<endl;
cout<<" \t 2. ELIMINAR DE LA PILA "<<endl;
cout<<" \t 3. MOSTRAR PILA "<<endl;
cout<<" \t 4. DESTRUIR PILA "<<endl;
cout<<" \t 5. SALIR "<<endl;
cout<<"\t ESCOGA UNA OPCION: ";
}
int main(void ){
//clolor de pantalla
system("color f9");
Pila pila;
char x;
int op;
do
{
menu(); cin>> op;
switch(op)
{
case 1: cout<< "\n\t INGRESE NUMERO Para la PILA: "; cin>> x;
pila.Apilar(x);
cout<<"\n\n\t\tNumero ( " << x << " ) agregado en la pila.\n\n";
break;
case 2:
if(pila.PilaVacia()==true)
cout<<"\n\n\tLa Pila esta Vacia.";
else{
x = pila.Desapilar( );
cout<<"\n\n\tNumero ( "<<x<<" ) eliminado de la PILA\n";
}
break;
case 3:
cout << "\n\n\t\t MOSTRANDO LA PILA\n\n";
if(pila.PilaVacia()!=true)
pila.MostrarPila( );
else
cout<<"\n\n\tLa Pila esta Vacia."<<endl;
break;
case 4:
pila.DestruirPila( );
cout<<"\n\n\t\tPila ha DESTRUIDA\n\n";
break;
}
cout<<endl<<endl;
system("pause");
system("cls");
}while(op!=5);
return 0;
}
Código:
#include<iostream>
#include<cstdlib>
using namespace std;
struct nodo{
char let;// usamos char para poder obtener los caractere para la pila
struct nodo *sgte;
};
typedef struct nodo *Puntero;
class Pila{
public:
Pila(void);
void Apilar(int );
int Desapilar(void );
void tope(void);
bool PilaVacia(void);
void MostrarPila(void);
void DestruirPila(void);
private:
Puntero Tope;
};
Pila::Pila(void){
Tope=NULL;
}
bool Pila::PilaVacia(void){
if(Tope==NULL)
return true;
else
return false;
}
void Pila::Apilar(int x){
Puntero p_aux;
p_aux=new(struct nodo);
p_aux->let=x;
p_aux->sgte=Tope;
Tope=p_aux;
}
//eliminara el elemento del tope de la pila ingresado
int Pila::Desapilar(void){
int x;
Puntero p_aux;
if(Tope==NULL)
cout<<"\n\n\tLa Pila esta Vacia.";
else{
p_aux=Tope;
x=p_aux->let;
Tope=Tope->sgte;
delete(p_aux);
}
return x;
}
//NOS MOSTRARA TOTODS LOS ELELMENTOS INGRESADOS ASI COMO LOS CARACTERES Y NUMEROS EN LA PILA
void Pila::MostrarPila(void){
Puntero p_aux;
p_aux=Tope;
while(p_aux!=NULL){
cout<<"\t\t\t "<<p_aux->let<<endl;
p_aux=p_aux->sgte;
}
}
//DESTRUYE LA PILA POR COMPLETAMENTE DEGANDOLA VACIA.
void Pila::DestruirPila(void){
Puntero p_aux;
while(Tope!=NULL){
p_aux=Tope;
Tope=Tope->sgte;
delete(p_aux);
}
}
void menu(void)
{
cout<<"\n\t PILA CON CARACTERES Y NUMERSO \n\n";
cout<<" \t 1. AGREGAR A LA PILA "<<endl;
cout<<" \t 2. ELIMINAR DE LA PILA "<<endl;
cout<<" \t 3. MOSTRAR PILA "<<endl;
cout<<" \t 4. DESTRUIR PILA "<<endl;
cout<<" \t 5. SALIR "<<endl;
cout<<"\t ESCOGA UNA OPCION: ";
}
int main(void ){
//clolor de pantalla
system("color f9");
Pila pila;
char x;
int op;
do
{
menu(); cin>> op;
switch(op)
{
case 1: cout<< "\n\t INGRESE NUMERO Para la PILA: "; cin>> x;
pila.Apilar(x);
cout<<"\n\n\t\tNumero ( " << x << " ) agregado en la pila.\n\n";
break;
case 2:
if(pila.PilaVacia()==true)
cout<<"\n\n\tLa Pila esta Vacia.";
else{
x = pila.Desapilar( );
cout<<"\n\n\tNumero ( "<<x<<" ) eliminado de la PILA\n";
}
break;
case 3:
cout << "\n\n\t\t MOSTRANDO LA PILA\n\n";
if(pila.PilaVacia()!=true)
pila.MostrarPila( );
else
cout<<"\n\n\tLa Pila esta Vacia."<<endl;
break;
case 4:
pila.DestruirPila( );
cout<<"\n\n\t\tPila ha DESTRUIDA\n\n";
break;
}
cout<<endl<<endl;
system("pause");
system("cls");
}while(op!=5);
return 0;
}
Pilas C/C++ - Pila con caracteres
Mediante una matriz saber cual es el numero Mayor y Menor y mostrar la matriz de los elementos ingresados.
#include<iostream>
#include<iomanip>
#include<stdlib.h>
using namespace std;
void ingresar(float A[50][50],int n, int m);
void mostrar(float A[50][50],int n, int m);
void mayor(float A[50][50],int n, int m);
void menor(float A[50][50],int n, int m);
int main()
{
system("cls");
// system("color A0");
int n,m;
float A[50][50];
cout<<"\n\n\t- INGRESA FILAS : ";
cin>>n;
cout<<"\n\t- INGRESA COLUMNAS : ";
cin>>m;
ingresar(A,n,m);
mostrar(A,n,m);
mayor(A,n,m);
menor(A,n,m);
cout<<endl<<endl;
system("pause");
}
void ingresar(float A[50][50],int n, int m)
{
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
cout<<endl<<"\t\t\t\t - ["<<i<<"]"<<"["<<j<<"] =";
cin>>A[i][j];
}
}
void mostrar(float A[50][50],int n, int m)
{
cout<<"\n\n\t Matriz = \n";
for(int i=0;i<n;i++)
{
cout<<endl<<"\n\t\t";
for(int j=0;j<m;j++)
{
cout<<" "<<setw(4)<<A[i][j];
}
}
}
void mayor(float A[50][50],int n, int m)
{
float mayor=A[0][0];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(A[i][j]>mayor)
mayor=A[i][j];
}
cout<<"\n\n\n\t\t\tEL MAYOR = "<<mayor;
}
void menor(float A[50][50],int n, int m)
{
float menor=A[0][0];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(A[i][j]<menor)
menor=A[i][j];
}
cout<<"\n\n\t\t\tEL MENOR = "<<menor;
}
Código:
#include<iostream>
#include<iomanip>
#include<stdlib.h>
using namespace std;
void ingresar(float A[50][50],int n, int m);
void mostrar(float A[50][50],int n, int m);
void mayor(float A[50][50],int n, int m);
void menor(float A[50][50],int n, int m);
int main()
{
system("cls");
// system("color A0");
int n,m;
float A[50][50];
cout<<"\n\n\t- INGRESA FILAS : ";
cin>>n;
cout<<"\n\t- INGRESA COLUMNAS : ";
cin>>m;
ingresar(A,n,m);
mostrar(A,n,m);
mayor(A,n,m);
menor(A,n,m);
cout<<endl<<endl;
system("pause");
}
void ingresar(float A[50][50],int n, int m)
{
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
cout<<endl<<"\t\t\t\t - ["<<i<<"]"<<"["<<j<<"] =";
cin>>A[i][j];
}
}
void mostrar(float A[50][50],int n, int m)
{
cout<<"\n\n\t Matriz = \n";
for(int i=0;i<n;i++)
{
cout<<endl<<"\n\t\t";
for(int j=0;j<m;j++)
{
cout<<" "<<setw(4)<<A[i][j];
}
}
}
void mayor(float A[50][50],int n, int m)
{
float mayor=A[0][0];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(A[i][j]>mayor)
mayor=A[i][j];
}
cout<<"\n\n\n\t\t\tEL MAYOR = "<<mayor;
}
void menor(float A[50][50],int n, int m)
{
float menor=A[0][0];
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
{
if(A[i][j]<menor)
menor=A[i][j];
}
cout<<"\n\n\t\t\tEL MENOR = "<<menor;
}
Menor y Mayor mediante una matriz c/c++
Hoy vamos a hacer un programa en que el elemento A y B se ingresen #n cantidad de elementos y que nos de al final un elemento C de cual es la intersección de los elementos A y B.
Codigo:
#include<iostream>
#include<stdlib.h>
using namespace std;
int contador = 0;
int *Ingresar( int *A , int N)
{
A = new int [100];
for( int i = 0 ; i < N ; i++ )
{
cout<<"\n\t\t\t - ["<<i+1<<"] : ";
cin>>A[i];
}
return A;
}
int *Interseccion( int *A , int *B , int *C , int N ,int M )
{
C = new int [100];
for( int i = 0 ; i < N ; i++ )
for( int j = 0 ; j < M ; j++ )
if ( A[i] == B[j])
{
C[contador++] = A[i];
}
if ( contador == 0)
return 0;
else
return C;
}
void Mostrar( int *A , int N)
{
cout<<" "<<A[0];
for( int i = 1 ; i < N ; i++ )
cout<<" , "<<A[i];
}
int main()
{
int N, M;
int *A = NULL;
int *B = NULL;
int *C = NULL;
cout<<"\n\n\t Primer Conjunto : ";
cin>>N;
A = Ingresar(A , N);
cout<<"\n\n\t\t A = { ";
Mostrar(A,N);
cout<<" } \n\n";
cout<<"\n\n\t Segundo Conjunto : ";
cin>>M;
B = Ingresar(B , M);
cout<<"\n\n\t\t B = { ";
Mostrar(B,M);
cout<<" } \n\n";
C = Interseccion( A , B , C , N , M );
cout<<"\n\n\t\t Interseccion C = { ";
Mostrar(C,contador);
cout<<" } \n\n";
cout<<endl<<endl;
system("pause");
return 0;
}
Interseccion de conjutos c/c++
Esta vez Trabajaremos en Excel ya sea 2007-2010-2013 realizaremos un código de registro en el cual llenaremos las celdas al llenar los campos del registro y nos calculara automáticamente la edad.
1.- llenar los campos de Nombres, Apellidos, Cédula, Fecha de Nacimiento, Edad( La edad sera calculada automáticamente al momento de pasar los datos ingresados al campo de las celdas.
2.- Informar al usuario si desea guardar los datos.
3.- una ves confirmado el guardar informar si el año es bisiesto o no.
Código enVisual Basic (Excel )
Private Sub CommandButton1_Click()
Dim NOMBRE, APELLIDO, CEDULA, FECHA_NACIMIENTO As String
Dim REGISTRO As Double
Dim FECHA As Date, EDAD, I, J As Integer
Dim MES, DIA, ANIO As String
Dim bEscribe1, bEscribir2 As Boolean
'Inicializamos las variables para revisar la fila vacias
I = 1
J = 2
bEscribe1 = False
bEscribe2 = False
'mid substrae una subcadena de una cadena
NOMBRE = TextBox1.Value
APELLIDO = TextBox2.Value
CEDULA = TextBox3.Value
FECHA_NACIMIENTO = TextBox4.Value
MES = Mid(FECHA_NACIMIENTO, 4, 2)
DIA = Mid(FECHA_NACIMIENTO, 1, 2)
ANIO = Mid(FECHA_NACIMIENTO, 7, 4)
'trim buscar espacio en blanco para colocarlos en un orden
Do While bEscribe1 = False
If Trim(Hoja1.Cells(I, 1)) = "" And Trim(Hoja1.Cells(I, 2)) = "" And Trim(Hoja1.Cells(I, 3)) = "" And Trim(Hoja1.Cells(I, 4)) = "" And Trim(Hoja1.Cells(I, 5)) = "" Then
bEscribe1 = True
Else
I = I + 1
End If
Loop
Do While bEscribe2 = False
If Trim(Hoja2.Cells(J, 1)) = "" And Trim(Hoja2.Cells(J, 2)) = "" And Trim(Hoja2.Cells(J, 3)) = "" And Trim(Hoja2.Cells(J, 4)) = "" And Trim(Hoja2.Cells(J, 5)) = "" Then
bEscribe2 = True
Else
J = J + 1
End If
Loop
'len mide una cadena
If Len(FECHA_NACIMIENTO) = 10 Then
If MES >= 1 And MES <= 12 And DIA >= 1 And DIA <= 31 And ANIO >= 1 And ANIO <= Year(Date) Then
FECHA = CDate(TextBox4)
EDAD = CInt((Date - FECHA) / 365)
a = MsgBox("CONFIRMAR GUARDAR DATOS", vbOKCancel, "AVISO")
If a = 1 Then
If MES = 12 Then
Hoja2.Cells(J, 1) = NOMBRE
Hoja2.Cells(J, 2) = APELLIDO
Hoja2.Cells(J, 3) = CEDULA
Hoja2.Cells(J, 4) = FECHA_NACIMIENTO
Hoja2.Cells(J, 5) = EDAD
Else
Hoja1.Cells(I, 1) = NOMBRE
Hoja1.Cells(I, 2) = APELLIDO
Hoja1.Cells(I, 3) = CEDULA
Hoja1.Cells(I, 4) = FECHA_NACIMIENTO
Hoja1.Cells(I, 5) = EDAD
End If
'calculo del año
TextBox4.Text = Year(TextBox4.Text)
año = TextBox4.Text
If año Mod 100 = 0 Then
Bisiesto = (año Mod 400 = 0)
Else
Bisiesto = (año Mod 4 = 0)
End If
If Bisiesto = True Then
MsgBox ("AÑO ES BISIESTO")
Else
MsgBox ("AÑO NO ES BISIESTO")
End If
TextBox1.Text = Empty
TextBox2.Text = Empty
TextBox3.Text = Empty
TextBox4.Text = Empty
TextBox1.SetFocus
Else
MsgBox ("GRACIAS, LA INFORMACION NO SE GUARDO")
End If
Else
MsgBox ("ERROR, EN LA FECHA INGRESADA")
End If
Else
MsgBox ("ERROR EL FORMATO DE LA FECHA DEBE SER DD/MM/AAAA")
End If
End Sub
Private Sub CommandButton2_Click()
a = MsgBox("DESEA SALIR?", vbOKCancel, "AVISO")
If a = 1 Then
End
End If
End Sub
Private Sub CommandButton3_Click()
TextBox1.Text = Empty
TextBox2.Text = Empty
TextBox3.Text = Empty
TextBox4.Text = Empty
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Label5_Click()
End Sub
Simular Registro (Excel 2016) Code VB
En este programa veremos utilizando las clases para crear operadores en que el usuario ingrese dos números cualquiera.
Codigo:
#include <iostream>
#include <stdlib.h>
using namespace std;
class Operaciones{
public:
int a;
int b;
void set_a_b(int n1, int n2);
void suma();
void resta();
void multiplicacion();
void divicion();
};
void Operaciones::set_a_b(int n1, int n2)
{
cout<<"Ingrese valores para LAS OPERACIONES: "<<endl;
cin>>n1; cin>>n2;
cout<<"\n\t\t\t Resultados\n"<<endl;
a=n1;
b=n2;
}
void Operaciones::suma()
{
cout<<"\n\t lA SUMA DE "<<a<<" + "<<b<<" ES: "<<a+b<<"\n";
}
void Operaciones::resta()
{
cout<<"\n\t lA RESTA DE "<<a<<" - "<<b<<" ES: "<<a-b<<"\n";
}
void Operaciones::divicion()
{
cout<<"\n\t lA DIVISION DE "<<a<<" / "<<b<<" ES: "<<a/b<<"\n";
}
void Operaciones::multiplicacion()
{
cout<<"\n\t lA MULTIPLICACION DE "<<a<<" * "<<b<<" ES: "<<a*b<<"\n";
}
int main()
{
system("color f9");
Operaciones op;
op.set_a_b('a','b');
op.suma();
op.resta();
op.multiplicacion();
op.divicion();
return 0;
}
Clases de operadores
Veremos cómo definir una CLASE, funciones miembro crear OBJETOS de la clase, datos privados y públicos.
Código:
#include <stdlib.h>
#include <iostream>
using namespace std;
class Calendario{
private:
int dias;
char meses[15];
int semana;
int anio;
public:
void recibirDia(){
cout<<"\n\t Dia: "; cin>>dias;
}
void recibirMeses(){
cout<<"\t Mes: "; cin>>meses;
}
void recibirSemana(){
cout<<"\t Semana: "; cin>>semana;
}
void recibirAnio(){
cout<<"\t Anio: "; cin>>anio;
}
void dis(){
cout<<"\n\t Dia es "<<dias<<"\n";
}
void mess(){
cout<<"\t Mes es "<<meses<<"\n";
}
void seman(){
cout<<"\t Semana es "<<semana<<"\n";
}
void any(){
cout<<"\t Anio es "<<anio<<"\n";
}
};
int main(){
system("color f3");
cout<<"\n\t\t\t EJERCICIO 16 OBJETO CALENDARIO \n"<<endl;
Calendario calen;
calen.recibirDia();
calen.recibirMeses();
calen.recibirSemana();
calen.recibirAnio();
calen.dis();
calen.mess();
calen.seman();
calen.any();
return 0;
}











