Pascal/Turbo Pascal - sin grandes avances ..necesito ayuda

 
Vista:
sin imagen de perfil
Val: 6
Ha aumentado su posición en 2 puestos en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

sin grandes avances ..necesito ayuda

Publicado por oscar (64 intervenciones) el 20/11/2012 21:35:13
Me puedes corregir lo que tengo mal por favor?gracias..
ademas en abrir compra de cesta existente tiene q ser : se preguntará al usuario el nombre de la cesta (que será el nombre del fichero que la contiene).
el codigo

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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
program registrocesta;
 
uses crt;
 
const
tammaxcesta = 5;
tamreg = 10;
 
type regcesta = record
nombre : string;
numero : integer;
precio : real;
en_cesta : boolean;
end;
 
producto = array[0..tammaxcesta] of regcesta;
 
var
cesta : array[1..tamreg] of producto;
nn:integer;
n, nu:integer;
cont : integer;
tec : char;
fich : file of producto;
prese : producto;
nombe : string;
 
 
procedure lee_producto(ces, n : integer);
var
r : integer;
rd : char;
begin
repeat
clrscr;
writeln(' Introduzca Entrada Cesta Numero : ',n);
writeln; write(' Introduzca Nombre Producto : ');
readln(cesta[ces][n].nombre);
write(' Introduzca Cantidad : ');
readln(cesta[ces][n].numero);
write(' Introduzca Precio Unidad : ');
readln(cesta[ces][n].precio);
cesta[ces][r].en_cesta := true;
writeln;
writeln(' Desea introducir mas Productos en La Cesta [S/N]');
repeat
rd := upcase(readkey);
until rd in['S','N'];
if rd = 'S' then
n := n + 1;
until (n > tammaxcesta) or (rd = 'N');
if n > tammaxcesta then begin clrscr;
writeln('**** Fin De Entradas Pulse una tecla ****');
end;
end;
 
procedure inicializa_cestas(ces : integer);
var
i : integer;
begin
if ces > tamreg then
begin
writeln(' Excedido Numero de Cestas. Pulsar [Enter]');
readln;
end
else
begin
for i := 0 to tammaxcesta do
begin
cesta[ces][i].en_cesta := false;
cesta[ces][i].nombre := ' ';
end;
clrscr;
writeln('Cesta Inicializada. Pulse una tecla');
readln;
end;
end;
 
procedure mostrar_productos(pro : integer);
var
y:integer;
d : integer;
begin
clrscr;
if cont > 1 then
begin
y := 3;
writeln('Nombre de Producto , Numero de Productos y Precio');
for d := 0 to tammaxcesta do
begin
if cesta[pro][d].nombre = ' ' then
begin
end
else
begin
writeln(cesta[pro][d].nombre);
writeln(cesta[pro][d].numero);
writeln(cesta[pro][d].precio:0:2);
y := y + 1;
end;
end;
end
else
writeln(' La Cesta esta Vacia. Pulsar [Enter] ');
readln;
end;
 
procedure mostrar_cesta(ces : integer);
var
p : integer;
begin
clrscr;
write(' Introduzca Posicion a Visualizar : ');
readln(p);
if (p = 0) or (p > tamreg) then
begin
if cont > 1 then
begin
writeln('Nombre:');
writeln(cesta[ces][p].nombre);
writeln('Numero De Productos:');
writeln(cesta[ces][p].numero);
writeln('Precio');
writeln(cesta[ces][p].precio:0:2);
writeln;
writeln('Pulse [Enter] ');
end
else
writeln('La Cesta Esta Vacia. Pulse una tecla ');
readln;
end;
end;
 
function cuenta_productos(ddd : integer) : integer;
var
b:integer;
c : integer;
begin
c := 0;
for b := 1 to tammaxcesta do
if cesta[ddd][b].en_cesta = true then
c := c + 1;
cuenta_productos := c;
end;
 
function busca_libre(lll : integer) : integer;
var
c:integer;
vv : integer;
begin
c := 0;
for vv := 1 to tammaxcesta do
if cesta[lll][vv].en_cesta = false then
begin
c := vv;
break;
end;
if c > 0 then
begin
busca_libre := c;
end
else
begin
busca_libre := 0;
end;
end;
 
procedure incluir_producto_en_cesta;
var
n, gg : integer;
begin
writeln(' Introduzca Numero Cesta : ');
readln(n);
gg := busca_libre(n);
lee_producto(n,gg);
end;
 
procedure guarda_cesta(nomb : string; ct : producto);
var
gua : integer;
begin
assign(fich,nomb);
{$I-} reset(fich);
{$I+} if ioresult <> 0 then
begin
rewrite(fich);
seek(fich,0);
write(fich, ct);
close(fich);
end
else
begin
seek(fich,filesize(fich));
write(fich, ct);
close(fich);
end;
end;
 
procedure recupera_cesta(nomb : string);
var
nom : string;
i : integer;
bus : longint;
encont : boolean;
begin
assign(fich,nomb);
{$I-} reset(fich);
{$I+} if ioresult <> 0 then
begin
end
else
begin
write(' Introduzca nombre Producto : ');
readln(nom);
bus := 0;
encont := false;
repeat
seek(fich,bus);
read(fich,prese);
for i := 1 to tammaxcesta do
begin
if prese[i].nombre = nom then
begin
encont := true;
end;
end;
if encont = false then bus := bus + 1;
until (bus > filesize(fich) - 1) or (encont = true);
close(fich);
end;
end;
 
function busca_producto(lacesta:producto; nombre:string):integer;
var i:integer;
begin
for i:=1 to TAMMAXCESTA do
begin
if (lacesta[i].nombre = nombre) then
busca_producto:= i
else
busca_producto:= 0;
end;
end;
 
procedure eliminar_producto_de_cesta(var lacesta:producto);
var
aproduct:string;
posaux:integer;
begin
{leemos el nombre del producto}
write('Por favor, indique el nombre del producto a eliminar: ');
readln(aproduct);
{pos := 0; {inicializamos pos (aunque no hace falta aquí)}}
posaux:= busca_producto(lacesta,aproduct); {buscamos el producto}
{pos := 0; {inicializamos pos (aunque no hace falta aquí)}
if posaux = 0 then {si lo encontramos}
writeln ('Producto no encontrado.');{c[pos].en_cesta := false {lo eliminamos}
else
begin
lacesta[posaux].en_cesta:= false;
writeln('Producto numero: ',posaux,'encontrado y eliminado');
end;
end;
 
 
var
lacesta: producto;
opcion: integer;
begin
cont := 1;
repeat
writeln;
{Presentación del menú}
writeln('1. Comenzar cesta de compra nueva.');
writeln('2. Abrir cesta de compra existente.');
writeln('3. Añadir producto a la cesta.');
writeln('4. Eliminar producto de la cesta.');
writeln('5. Guardar cesta.');
writeln('6. Pedir cesta.');
writeln('7. Salir del programa.');
writeln;
write('Por favor, introduzca una opcion: ');
readln(opcion);
writeln;
repeat
tec := readkey;
until
tec in['1','2','3','4','5','6','7'];
case tec of
 
'1' : begin write(' Cesta Numero : ');
readln(nn);
inicializa_cestas(nn);
end;
 
'2': begin lee_producto(cont,1);
cont := cont + 1;
end;
 
 
'4' : begin eliminar_producto (lacesta);
end;
 
'3' : begin incluir_producto_en_cesta;
end;
 
'5' : begin write(' Introduzca Nombre Archivo y Extension : ');
readln(nombe);
write(' Introduzca Num. Posicion : ');
readln(n);
if n > tamreg then n := tamreg;
guarda_cesta(nombe,cesta[n]);
end;
 
'6' : begin write(' Introduzca Nombre Archivo y Extension : ');
readln(nombe);
recupera_cesta(nombe);
end;
end;
until tec = '7';
end.
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

sin grandes avances ..necesito ayuda

Publicado por ramon (2158 intervenciones) el 21/11/2012 22:05:44
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
{Lo tienes funcionando revisa y ajusta lo}
 
program registrocesta;
 
uses crt;
 
const
tammaxcesta = 5;
tamreg = 10;
 
type regcesta = record
nombre : string;
numero : integer;
precio : real;
en_cesta : boolean;
end;
 
producto = array[0..tammaxcesta] of regcesta;
 
var
cesta : array[1..tamreg] of producto;
nn:integer;
n, nu:integer;
cont : integer;
tec : char;
fich : file of producto;
prese : producto;
nombe : string;
 
 
procedure lee_producto(ces, n : integer);
var
r : integer;
rd : char;
begin
repeat
clrscr;
writeln(' Introduzca Entrada Cesta Numero : ',n);
writeln; write(' Introduzca Nombre Producto : ');
readln(cesta[ces][n].nombre);
write(' Introduzca Cantidad : ');
readln(cesta[ces][n].numero);
write(' Introduzca Precio Unidad : ');
readln(cesta[ces][n].precio);
cesta[ces][r].en_cesta := true;
writeln;
writeln(' Desea introducir mas Productos en La Cesta [S/N]');
repeat
rd := upcase(readkey);
until rd in['S','N'];
if rd = 'S' then
n := n + 1;
until (n > tammaxcesta) or (rd = 'N');
if n > tammaxcesta then begin clrscr;
writeln('**** Fin De Entradas Pulse una tecla ****');
end;
end;
 
procedure inicializa_cestas(ces : integer);
var
i : integer;
begin
if ces > tamreg then
begin
writeln(' Excedido Numero de Cestas. Pulsar [Enter]');
readln;
end
else
begin
for i := 0 to tammaxcesta do
begin
cesta[ces][i].en_cesta := false;
cesta[ces][i].nombre := ' ';
end;
clrscr;
writeln('Cesta Inicializada. Pulse una tecla');
readln;
end;
end;
 
procedure mostrar_productos(pro : integer);
var
y:integer;
d : integer;
begin
clrscr;
if cont > 1 then
begin
y := 3;
writeln('Nombre de Producto , Numero de Productos y Precio');
for d := 0 to tammaxcesta do
begin
if cesta[pro][d].nombre = ' ' then
begin
end
else
begin
writeln(cesta[pro][d].nombre);
writeln(cesta[pro][d].numero);
writeln(cesta[pro][d].precio:0:2);
y := y + 1;
end;
end;
end
else
writeln(' La Cesta esta Vacia. Pulsar [Enter] ');
readln;
end;
 
procedure mostrar_cesta(ces : integer);
var
p : integer;
begin
clrscr;
write(' Introduzca Posicion a Visualizar : ');
readln(p);
if (p = 0) or (p > tamreg) then
begin
if cont > 1 then
begin
writeln('Nombre:');
writeln(cesta[ces][p].nombre);
writeln('Numero De Productos:');
writeln(cesta[ces][p].numero);
writeln('Precio');
writeln(cesta[ces][p].precio:0:2);
writeln;
writeln('Pulse [Enter] ');
end
else
writeln('La Cesta Esta Vacia. Pulse una tecla ');
readln;
end;
end;
 
function cuenta_productos(ddd : integer) : integer;
var
b:integer;
c : integer;
begin
c := 0;
for b := 1 to tammaxcesta do
if cesta[ddd][b].en_cesta = true then
c := c + 1;
cuenta_productos := c;
end;
 
function busca_libre(lll : integer) : integer;
var
c:integer;
vv : integer;
begin
c := 0;
for vv := 1 to tammaxcesta do
if cesta[lll][vv].en_cesta = false then
begin
c := vv;
break;
end;
if c > 0 then
begin
busca_libre := c;
end
else
begin
busca_libre := 0;
end;
end;
 
procedure incluir_producto_en_cesta;
var
n, gg : integer;
begin
writeln(' Introduzca Numero Cesta : ');
readln(n);
gg := busca_libre(n);
lee_producto(n,gg);
end;
 
procedure guarda_cesta(nomb : string; ct : producto);
var
gua : integer;
begin
assign(fich,nomb);
{$I-} reset(fich);
{$I+} if ioresult <> 0 then
begin
rewrite(fich);
seek(fich,0);
write(fich, ct);
close(fich);
end
else
begin
seek(fich,filesize(fich));
write(fich, ct);
close(fich);
end;
end;
 
procedure recupera_cesta(nomb : string);
var
nom : string;
i : integer;
bus : longint;
encont : boolean;
begin
assign(fich,nomb);
{$I-} reset(fich);
{$I+} if ioresult <> 0 then
begin
end
else
begin
write(' Introduzca nombre Producto : ');
readln(nom);
bus := 0;
encont := false;
repeat
seek(fich,bus);
read(fich,prese);
for i := 1 to tammaxcesta do
begin
if prese[i].nombre = nom then
begin
encont := true;
end;
end;
if encont = false then bus := bus + 1;
until (bus > filesize(fich) - 1) or (encont = true);
close(fich);
end;
end;
 
function busca_producto(lacesta:producto; nombre:string):integer;
var i:integer;
begin
for i:=1 to TAMMAXCESTA do
begin
if (lacesta[i].nombre = nombre) then
busca_producto:= i
else
busca_producto:= 0;
end;
end;
 
procedure eliminar_producto_de_cesta(var lacesta:producto);
var
aproduct:string;
posaux:integer;
begin
{leemos el nombre del producto}
write('Por favor, indique el nombre del producto a eliminar: ');
readln(aproduct);
{pos := 0; {inicializamos pos (aunque no hace falta aquí)}
posaux:= busca_producto(lacesta,aproduct); {buscamos el producto}
{pos := 0; {inicializamos pos (aunque no hace falta aquí)}
if posaux = 0 then {si lo encontramos}
writeln ('Producto no encontrado.'){c[pos].en_cesta := false {lo eliminamos}
else
begin
lacesta[posaux].en_cesta:= false;
writeln('Producto numero: ',posaux,'encontrado y eliminado');
end;
end;
 
 
var
lacesta: producto;
opcion: integer;
begin
cont := 1;
repeat
clrscr;
writeln('****  Menu General ****');
writeln;
{Presentación del menú}
writeln('1. Comenzar cesta de compra nueva.');
writeln('2. Abrir cesta de compra existente.');
writeln('3. Añadir producto a la cesta.');
writeln('4. Eliminar producto de la cesta.');
writeln('5. Guardar cesta.');
writeln('6. Pedir cesta.');
writeln('7. Salir del programa.');
writeln;
write('Por favor, introduzca una opcion: ');
 
repeat
tec := readkey;
until
tec in['1','2','3','4','5','6','7'];
case tec of
 
'1' : begin write(' Cesta Numero : ');
readln(nn);
inicializa_cestas(nn);
end;
 
'2': begin lee_producto(cont,1);
cont := cont + 1;
end;
 
 
'4' : begin eliminar_producto_de_cesta (lacesta);
end;
 
'3' : begin incluir_producto_en_cesta;
end;
 
'5' : begin write(' Introduzca Nombre Archivo y Extension : ');
readln(nombe);
write(' Introduzca Num. Posicion : ');
readln(n);
if n > tamreg then n := tamreg;
guarda_cesta(nombe,cesta[n]);
end;
 
'6' : begin write(' Introduzca Nombre Archivo y Extension : ');
readln(nombe);
recupera_cesta(nombe);
end;
end;
until tec = '7';
end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar
sin imagen de perfil
Val: 6
Ha aumentado su posición en 2 puestos en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

sin grandes avances ..necesito ayuda

Publicado por oscar (64 intervenciones) el 21/11/2012 22:11:52
ok gracias
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