Saber si hay alguna funcion que devuelva subcadena de un arreglo de caracteres similar a subsrt(); de la clase string, no se si me explique bien , de todas maneras pensaba seguir manejandome con la clase string
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int opcion;
string fecha;
cout << "INGRESE UNA FECHA EN EL FORMATO DDMMAAAA: ";
getline(cin, fecha);
cout << "ELEGIR FORMATO" << endl;
cout << "1. MM/DD/AAAA" << endl;
cout << "2. DD/MM/AAAA" << endl;
cout << "3. AAAA/MM/DD" << endl;
cin >> opcion;
switch(opcion){
case 1: cout << fecha.substr(2,2) <<"/" << fecha.substr(0,2) << "/" << fecha.substr(4,4) << endl ;break;
case 2: cout << fecha.substr(0,2) <<"/" << fecha.substr(2,2) << "/" << fecha.substr(4,4) << endl ;break;
case 3: cout << fecha.substr(4,4) <<"/" << fecha.substr(2,2) << "/" << fecha.substr(0,2) << endl ;break;
default: cout << "OPCION INCORRECTA" << endl;
}
system("pause");
return 0;
}
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
int opcion;
string fecha;
cout << "INGRESE UNA FECHA EN EL FORMATO DDMMAAAA: ";
getline(cin, fecha);
cout << "ELEGIR FORMATO" << endl;
cout << "1. MM/DD/AAAA" << endl;
cout << "2. DD/MM/AAAA" << endl;
cout << "3. AAAA/MM/DD" << endl;
cin >> opcion;
switch(opcion){
case 1: cout << fecha.substr(2,2) <<"/" << fecha.substr(0,2) << "/" << fecha.substr(4,4) << endl ;break;
case 2: cout << fecha.substr(0,2) <<"/" << fecha.substr(2,2) << "/" << fecha.substr(4,4) << endl ;break;
case 3: cout << fecha.substr(4,4) <<"/" << fecha.substr(2,2) << "/" << fecha.substr(0,2) << endl ;break;
default: cout << "OPCION INCORRECTA" << endl;
}
system("pause");
return 0;
}
#include <iostream>
#include <string.h>
using namespace std;
const int MAX=8;
typedef char tcad[MAX];
int main()
{
tcad fecha;
char dia[2], mes[2], año[4];
int opcion;
cout << "Ingrese un afecha en formato DD/MM/AAAA: ";
cin.getline(fecha,9,'\n');
dia[0]=fecha[0];
dia[1]=fecha[1];
mes[0]=fecha[2];
mes[1]=fecha[3];
año[0]=fecha[4];
año[1]=fecha[5];
año[2]=fecha[6];
año[3]=fecha[7];
cout << "Seleccione formato" << endl;
cout << "1. MM/DD/AAAA" << endl;
cout << "2. DD/MM/AAAA" << endl;
cout << "3. AAAA/MM/DD" << endl;
cin >> opcion;
switch(opcion){
case 1: cout << mes << "/" << dia << "/" << año << endl; break;
case 2: cout << dia << "/" << mes << "/" << año << endl; break;
case 3: cout << año << "/" << mes << "/" << dia << endl; break;
default: cout << "Opcion incorrecta" << endl;
}
system("pause");
return 0;
}
Cita de: MAFUS en 4 Julio 2018, 23:27 PM
En lo referente a fflush(stdin): el estándar dice que fflush solo es para flujos de salida así que depende del compilador que funcione o no. Cómo norma general no deberías usarlo.
En cuanto a la recursividad: sí, está bien hecha. Tiene una condición de parada, una llamada que actualiza un estado para que active la condición de parada en el momento oportuno y un trabajo a cumplir.
Lo que hace es escribir en pantalla: Entrando en el sueño del suelo... repitiendo tantas veces del sueño como se hayan indicado en el argumento de llamada.
Por cierto, no destroces el lenguaje con x y e. El español es un de los lenguajes más ricos que existen.
main()
{ int dni;
tcad nombre;
cout << "Ingrese DNI: ";
cin >> dni;
//fflush(stdin); Aca viene el error
cout << "Ingrese nombre: ";
gets(nombre);
void maxmin(matrix m, int &max, int &min)
{
bool band=false;
for(int i=0;i<FILAS;i++){
for(int j=0;j<COLUMNAS;j++){
if(band==false){
max=m[i][j];
min=m[i][j];
band=true;
}
else{
if(m[i][j]>max){
max=m[i][j];
}
if(m[i][j]<min){
min=m[i][j];
}
}
}
}
}
void como_la_realidad(int vida)
{
if(vida<=1)
cout << "Entrando en el sueño";
else
como_la_realidad(vida-1);
cout << " del sueño";
}
int fibonacci(int n)
{
tpila pila;
init_stack(pila);
while(pila.cima<n-1){
push_stack(pila, pila.datos[pila.cima]+pila.datos[pila.cima-1]);
}
return top_stack(pila);
}
int serie(int n)
{
tpila pila;
init_stack(pila);
if(pila.cima>n-1){
while(pila.cima>n-1){
pop_stack(pila);
}
}
else{
while(pila.cima<n-1){
push_stack(pila, pila.datos[pila.cima]+pila.datos[pila.cima-1]+pila.datos[pila.cima-2]);
}
}
return top_stack(pila);
}
#include <iostream>
#include <math.h>
using namespace std;
const int TAMPILA=32;
typedef int contenedor[TAMPILA];
typedef struct{
contenedor datos;
int cima;
}tpila;
void fibonacci(int n);
void init_stack(tpila &pila);
void push_stack(tpila &pila, int nuevo);
bool full_stack(tpila pila);
bool empty_stack(tpila pila);
int pop_stack(tpila &pila);
int top_stack(tpila pila);
void ingreso(int n);
int main()
{
int numero;
cout << "Ingrese un numero: ";
cin >> numero;
fibonacci(numero);
system("pause");
return 0;
}
void fibonacci(int n)
{
tpila pila;
init_stack(pila);
while(n>0){
//Aca pondria mi algoritmo si tuviera uno
}
cout << "\nFibonacci: " << << endl;
}
void init_stack(tpila &pila)
{
pila.cima=-1;
}
void push_stack(tpila &pila, int nuevo)
{
if(full_stack(pila)==true){
cout << "PILA LLENA" << endl;
}
else{
pila.cima++;
pila.datos[pila.cima]=nuevo;
}
}
bool full_stack(tpila pila)
{
return pila.cima==TAMPILA-1;
}
bool empty_stack(tpila pila)
{
return pila.cima==-1;
}
int pop_stack(tpila &pila)
{
int aux;
if(empty_stack(pila)==true){
aux=-1;
}
else{
aux=pila.datos[pila.cima];
pila.cima--;
}
return aux;
}
int top_stack(tpila pila)
{
int aux;
if(empty_stack(pila)==true){
aux=-1;
}
else{
aux=pila.datos[pila.cima];
}
return aux;
}