Dev - C++ - Ayuda con el desarrollo de un programa

 
Vista:

Ayuda con el desarrollo de un programa

Publicado por Renzo (2 intervenciones) el 26/01/2014 05:53:34
Buenas Noches amigo. Tengo un problema con el siguiente programa, me solicitan lo siguiente
1.- Con la información para el siguiente archivo:

Nombre del Archivo (S.O): ’Mango.dat’ Nombre del Registro: Zapatería

Nombre del Campo Descripción del Campo Formato o valores posibles
Codzap Código del Zapato ’9999-WZ-9999’
Tipozap Tipo del Zapato 1, 2 , 3
Color Color del Zapato ’Negro’, ’Marrón’ , ’Gris’
Ubicación Ubicación del Zapato ’E99-99’
Precio Precio del Zapato 1e4 , 4e4, 7e4

Se pide:
• Programa Crear
• Programa General Básico
• Función Menú y Búsqueda
• Procedimientos incluir, consultar, modificar y eliminar

Ya lo hice, pero el archivo no se crea, es decir, puedo incluir el registro del zapato y me dice que está completado, pero cuando quiero consultar o modificar me dice que no existe. Me podrían ayudar?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include <stdio.h>
#include <conio.h>
struct{
 char Codzap[12];
 int Tipzap;
 char Color[6];
 char Ubicacion[6];
 long int Precio;
 }Zapateria;
char sel;
char menu();
int BuscarRegistro(int tipobus);
void IncluirRegistro();
void ConsultarRegistro();
void ModificarRegistro();
void EliminarRegistro();
void main()
{
clrscr();
FILE *arch1;
arch1=fopen("Mango.dat","w");
fclose(arch1);
printf("Archivo Creado");
do
 {
 sel= menu();
 switch (sel)
  {
  case '1':{
			  IncluirRegistro();
			  break;
			  }
  case '2':{
			  ConsultarRegistro();
			  break;
			  }
  case '3':{
			  ModificarRegistro();
			  break;
			  }
  case '4':{
			  EliminarRegistro();
			  break;
			  }
  }
 }while (sel != '5');
}
char menu()
{
char y;
clrscr();
gotoxy(30,8);printf("Zapateria MANGO");
gotoxy(20,10);printf("1.-Incluir Registros");
gotoxy(20,12);printf("2.-Consultar Registros");
gotoxy(20,14);printf("3.-Modificar Registros");
gotoxy(20,16);printf("4.-Eliminar Registros");
gotoxy(20,18);printf("5.-Salida");
gotoxy(40,20);printf("Seleccion= ");
y = getchar();
return y;
}
int BuscarRegistro(int tipobus)
{
int z;
int band=0;
FILE *arch1;
arch1=fopen("Mango.dat","r");
while((band==0)&&(fread(&Zapateria,sizeof(Zapateria),1,arch1)==1))
 {
 if(Zapateria.Tipzap==tipobus)
  {
  band=1;
  }
 }
if(band==0)
z=0;
else
z=1;
fclose(arch1);
return(z);
}
void IncluirRegistro()
{
int tipbus;
int m;
clrscr();
printf("Ingrese el tipo de zapato= ");
scanf("%d",&tipbus);
m=BuscarRegistro(tipbus);
if(m==0)
 {
 Zapateria.Tipzap=tipbus;
 printf("Ingrese el codigo del zapato= ");
 scanf("%s",&Zapateria.Codzap);
 printf("Ingrese el color del zapato= ");
 scanf("%s",&Zapateria.Color);
 printf("Ingrese la ubicacion del zapato= ");
 scanf("%s",&Zapateria.Ubicacion);
 printf("Ingrese el precio del zapato= ");
 scanf("%ld",&Zapateria.Precio);
 FILE *arch1;
 arch1=fopen("Mango.dat","at+");
 fwrite(&Zapateria,sizeof(Zapateria),1,arch1);
 fclose(arch1);
 printf("\nRegistro del zapato completado");
 }
 else
 {
 printf("\n Tipo de zapato ya ingresado");
 }
getch();
}
void ConsultarRegistro()
{
int tipbus;
int m;
clrscr();
printf("Ingrese el tipo de zapato a consultar= ");
scanf("%d",&tipbus);
m=BuscarRegistro(tipbus);
if(m==1)
 {
 printf("Codigo del zapato= %s \n",Zapateria.Codzap);
 printf("Color del Zapato= %s \n",Zapateria.Color);
 printf("Ubicacion del Zapato= %s \n",Zapateria.Ubicacion);
 printf("Precio del Zapato= %ld \n",Zapateria.Precio);
 }
 else
 {
 printf("\n Tipo de zapato NO ENCONTRADO");
 }
getch();
}
void ModificarRegistro()
{
int tipbus;
int m;
clrscr();
printf("Ingrese el tipo de zapato= ");
scanf("%d",&tipbus);
m=BuscarRegistro(tipbus);
if(m==1)
 {
 FILE *arch1;
 arch1=fopen("Mango.dat","r");
 FILE *arch2;
 arch2=fopen("Temp.dat","at+");
 while((fread(&Zapateria,sizeof(Zapateria),1,arch1)==1))
  {
  if(Zapateria.Tipzap==tipbus)
	{
	printf("Ingrese el codigo del zapato= ");
	scanf("%s",&Zapateria.Codzap);
	printf("Ingrese el color del zapato= ");
	scanf("%s",&Zapateria.Color);
	printf("Ingrese la ubicacion del zapato= ");
	scanf("%s",&Zapateria.Ubicacion);
	printf("Ingrese el precio del zapato= ");
	scanf("%ld",&Zapateria.Precio);
	}
  fwrite(&Zapateria,sizeof(Zapateria),1,arch2);
  }
 fclose(arch1);
 fclose(arch2);
 remove("Mango.dat");
 rename("Temp.dat","Mango.dat");
 printf("\n Registro actualizado");
 }
 else
 {
 printf("\n Tipo de zapato NO ENCONTRADO");
 }
getch();
}
void EliminarRegistro()
{
int tipbus;
int m;
clrscr();
printf("Ingrese el tipo de zapato= ");
scanf("%d",&tipbus);
m=BuscarRegistro(tipbus);
if(m==1)
 {
 FILE *arch1;
 arch1=fopen("Mango.dat","r");
 FILE *arch2;
 arch2=fopen("Temp.dat","at+");
 while((fread(&Zapateria,sizeof(Zapateria),1,arch1)==1))
  {
  if(Zapateria.Tipzap!=tipbus)
	{
	fwrite(&Zapateria,sizeof(Zapateria),1,arch2);
	}
  }
 fclose(arch1);
 fclose(arch2);
 remove("Mango.dat");
 rename("Temp.dat","Mango.dat");
 printf("\n Registro Eliminado");
 }
 else
 {
 printf("\n Tipo de zapato NO ENCONTRADO");
 }
getch();
}
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