Dev - C++ - duda en c++

 
Vista:

duda en c++

Publicado por toni (1 intervención) el 01/10/2009 21:17:41
tengo este codigo

char nombre_apellido[50];

cout<<introduce nombre<<endl;
cin >>nombre_apellido;
cout << nombre_apellido;
system("pause")

Introduzco el nombre y el apellido pero solo me muestra el nombre y no se por que cuando hay un espacio en medio la segunda palabra no la muestra. ¿como puedo hacer?.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:duda en c++

Publicado por Javier (4 intervenciones) el 18/10/2009 14:44:36
A ver si esto te sirve:

char nombre[25], apellido[25];

cout<< "introduce nombre y apellido separado por un espacio: ";
cin >> nombre >> apellido;
cout << nombre << " " << apellido;

system("PAUSE");

Saludos ...
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

raid 2 en c++

Publicado por jorge butron (1 intervención) el 19/10/2009 15:32:34
Proyecto Base de Datos
Emulación del nivel RAID2

#include <stdlib.h>
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <string.h>
#include <fstream.h>

using namespace std;

int num_bytes;
int bytes_malos;

int error_disco1;
int error_disco2;
int error_disco3;

void fragmentar(string archorigen, string archdestino1 ,string archdestino2 ,string archdestino3 ,string archdestino4)

{
ifstream origen(archorigen.c_str(), ios::binary);
char linea[1];

if(origen.fail())
cerr << "Error al abrir el archivo "<<archorigen << endl;
else
{
ofstream destino1(archdestino1.c_str(), ios::binary|ios::trunc);
ofstream destino2(archdestino2.c_str(), ios::binary|ios::trunc);
ofstream destino3(archdestino3.c_str(), ios::binary|ios::trunc);
ofstream destino4(archdestino4.c_str(), ios::trunc);

if(destino1.fail())
cerr << "Error al crear el archivo destino1"<< endl;
else
{
while(!origen.eof()&&!origen.fail())
{
//escritura en primer disco
origen.read(linea, sizeof(linea));
if(origen.good())
{

cout<<"-";
destino4.put('-');
num_bytes++;

destino1.write(linea, sizeof(linea));
if(destino1.fail())
{
//cerr << "Error en el archivo destino1"<< endl;
cout<<"X";
destino4.put('x');
bytes_malos++;
error_disco1++;
}
}
else if(!origen.eof())
{
cerr << "Error en el archivo origen"<< endl;
}
//scritura en segundo disco
origen.read(linea, sizeof(linea));

if(origen.good())
{
cout<<"-";
destino4.put('-');
num_bytes++;
destino2.write(linea, sizeof(linea));
if(destino2.fail())
{
//cerr << "Error en el archivo destino1"<< endl;
cout<<"x";
destino4.put('x');
bytes_malos++;
error_disco2++;
}
}
else if(!origen.eof())
{
cerr << "Error en el archivo origen"<< endl;

}
//escritura en tercer disco
origen.read(linea, sizeof(linea));
if(origen.good())
{
cout<<"-";
destino4.put('-');
num_bytes++;
destino3.write(linea, sizeof(linea));
if(destino3.fail())
{
//cerr << "Error en el archivo destino1"<< endl;
cout<<"x";
destino4.put('x');
bytes_malos++;
error_disco3++;
}
}
else if(!origen.eof())
{
cerr << "Error en el archivo origen"
<< endl;
}
}
}
destino1.close();
destino2.close();
destino3.close();
destino4.close();
}
origen.close();

getch();
}

void desfragmentar(string archorigen1, string archorigen2 ,string archorigen3, string archorigen4, string archdestino)
{
ifstream origen1(archorigen1.c_str(), ios::binary);
ifstream origen2(archorigen2.c_str(), ios::binary);
ifstream origen3(archorigen3.c_str(), ios::binary);
ifstream origen4(archorigen4.c_str(), ios::binary);

char linea[1];

if(origen1.fail())
//cerr << "Error al abrir el archivo "<<archorigen1 << endl;
cout<<"X";
else
{
ofstream destino(archdestino.c_str(), ios::binary|ios::trunc);

if(destino.fail())
cerr << "Error al crear el archivo destino1"<< endl;
else
{
while(!origen1.eof()&&!origen2.eof()&&!origen3.eof())
{
//lectura del primer disco
origen1.read(linea, sizeof(linea));
cout<<"-";
if(origen1.good())
{
destino.write(linea, sizeof(linea));
if(destino.fail())
{
//cerr << "Error en el archivo destino1"<< endl;
cout<<"X";
}
}
else if(!origen1.eof())
{
cerr << "Error en el archivo origen"<< endl;
}
//lectura del segundo disco
origen2.read(linea, sizeof(linea));
cout<<"-";
if(origen2.good())
{
destino.write(linea, sizeof(linea));
if(destino.fail())
{
cerr << "Error en el archivo destino"<< endl;
cout<<"X";
}
}
else if(!origen2.eof())
{
cerr << "Error en el archivo origen 2"<< endl;
}
//escritura en tercer disco
origen3.read(linea, sizeof(linea));
cout<<"-";
if(origen3.good())
{
destino.write(linea, sizeof(linea));
if(destino.fail())
{
//cerr << "Error en el archivo destino"<< endl;
cout<<"X";
}
}
else if(!origen3.eof())
{
cerr << "Error en el archivo origen" << endl;
}
}
}
destino.close();
}
origen1.close();
origen2.close();
origen3.close();
origen4.close();

getch();
}

int main()
{
string archivo;
cout<<"introduzca nombre de un archivo con su extension"<<endl;
cin>>archivo;
string disco1="disco1.txt";
string disco2="disco2.txt";
string disco3="disco3.txt";
string disco4="control.txt";

string recuperado="recuperado.txt";

num_bytes=0;
cout<<"presione una tecla para desfragmentar"<<endl;
getch();
fragmentar(archivo,disco1,disco2,disco3,disco4);
cout<<endl<<"Se fragmento el archivo con los siguientes resultados:"<<endl;
cout<<"numero de bytes copiados: "<<num_bytes<<endl;
cout<<"numero de bytes malos: "<<bytes_malos<<endl;
cout<<"numero errores en disco1 : "<<error_disco1<<endl;
cout<<"numero errores en disco2 : "<<error_disco2<<endl;
cout<<"numero errores en disco3 : "<<error_disco3<<endl;
cout<<"se crearon las copias de seguridad"<<endl<<endl;
cout<<"presione una tecla para recuperar la informacion"<<endl;
getch();
cout<<"desfragmentando"<<endl;
desfragmentar(disco1,disco2,disco3,disco4,recuperado);
cout<<endl<<"desfragmentando terminado"<<endl;
getch();
return 0;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:raid 2 en c++

Publicado por lorena cecilia figueroa (1 intervención) el 24/11/2009 22:29:33
hola que taloye neHAY UN GRUPO DE BANDIDOS, EN EL VIEJO OESTE QUE SE ENCUENTRAN EN UN PREDICAMENTO DESESPERADO. EL GRUPO ESTA RODEADO POR LOS ALGUACILES DEL COMISARIO Y NO TIENEN NINGUNA ESPERANZA DE ESCAPAR EN MASA. SOLO LES QUEDA UN CABALLO. PARA SELECCIONAR QUIEN DEBE TOMAR EL CABALLO Y ESCAPAR CON EL BOTIN, ESTOS (EL CIVILIZADO GRUPO DE BANDIDOS) HACEN LO SIGUIENTE,

ESCRIBEN EN TROZOS DE PAPEL EL NUMERO QUE LE CORRESPONDE A CADA UNO Y LOS REVUELVEN EN UN SOMBRERO. LOS BANDIDOS SE PONEN EN CIRCULO. UNO DE ELLOS ES DESIGNADO PARA OCUPAR LA POSOCION INICIAL.

DIGAMOS QUE SE SACA UN NUMERO “ N “ DEL SOMBRERO Y EL CONTEO EMPIEZA ALREDEDOR DEL CIRCULO (EN EL MISMO SENTIDO DE LAS MANECILLAS DEL RELOJ); SE ELIMINA LA N-ESIMA PERSONA. CUANDO SALE DEL CIRCULO, ESTE SE REDUCE. EL CONTEO EMPIEZA DE NUEVO CON EL HOMBRE QUE ESTA A SU IZQUIERDA. LA N-ESIMA PERSONA OTRA VEZ SE ELIMINA. EL PROCESO CONTINUA HASTA QUE SOLO QUEDA UN BANDIDO, EL CUAL COGE EL BOTIN, SALTA AL CABALLO Y SALE A CAMPO TRAVIESA.

SUPONGAMOS QUE EL CIRCULO INICIAL DE BANDIDOS ESTA COMO SE MUESTRA EN LA FIGURA SIGUIENTE:

EL FLACO

SAMUEL JOSE

EL GATO GRAN MO

Y JOSE ES SELECCIONADO COMO NUMERO UNO (POR QUE EL ES EL MAS GRANDE), SE SACA EL NUMERO CUATRO, Y SAMUEL ES EL PRIMER BANDIDO ELIMINADO. EL CONTEO EMPIEZA CON EL FLACO Y EL GATO ABANDONA EL CIRCULO. OTRA VEZ EL CONTEO EMPIEZA EN EL FLACO Y EL NUMERO CUATRO CAE SOBRE EL FLACO, AHORA JOSE ES EL PRIMERO Y EL GRAN MO PIERDE CON EL NUMERO CUATRO, JOSE AGARRA EL CABALLO Y SALE CON EL BOTIN.

DEBE ESCRIBIR UN PROGRAMA QUE SIMULE ESTE PROCEDIMIENTO. LA ENTRADA DEBE SER LA LISTA DE NOMBRES DE LOS BANDIDOS, ORDENADOS DE ACUERDO AL LUGAR QUE OCUPEN EN EL CIRCULO Y EL NUMERO “N”. AL SACAR EL NOMBRE DE LOS BANDIDOS ESTOS SE ELIMINAN, SOLO GANA EL ULTIMO EN QUEDAR EN LA LISTA,

cesito resolver este problema para mañana ojala ayudame
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar