Jump to content

Duvida- Ficheiros


joaovasco

Recommended Posts

Olá , boa noite a todos.

Fiz este programa de Ficheiros :

Program Loja_musicaFase3 ;

Type

automoveis = record

Tipo:string;

Marca:string;

Modelo:string;

Cor:string;

Ano:integer;

Matricula:string;

end;

stand = file of automoveis;

Var

fich:stand;

reg:automoveis;

resp:char;

Procedure Ler (Var x:automoveis);

begin

writeln('Digite a marca do Automovel');

readln(x.Marca);

writeln('Digite o modelo do Automovel');

readln(x.Modelo);

writeln('Digite a cor do Automovel');

readln(x.Cor);

writeln('Digite o ano do Automovel');

readln(x.Ano);

writeln('Digite a matricula do Automovel');

readln(x.Matricula);

  end;

Procedure escrever(var xx:automoveis);

begin

writeln('A marca do automovel é',xx.Marca);

writeln('O modelo do automovel é',xx.Modelo);

writeln('A cor do automovel é',xx.Cor);

writeln('O ano do automovel é', xx.Ano);

writeln('A matricula do automovel é', xx.Matricula);

end;

  Function ExisteFich( xxx:string):boolean;

  Var

  f:stand;

  Begin

  {$I-}

  assign(fich,'c:\LP\LojaMF2.dat');

  reset(F);

  close (F);

  {$I+}

  If ioresult=0 then existefich:=true else existefich:=false;

  end;

Begin

assign (fich,'c:\LP\lojaM3.dat');

if existefich ('c:\LP\lojaMF2.dat') then

reset(fich) else rewrite(fich);

repeat

seek(fich,filesize(fich));

ler(reg);

write(fich,reg);

writeln('deseja continuar S\N ?');

readln(resp);

until (Resp = 'n') or  (resp = 'N')  ;

close (fich);

reset(fich);

read(fich,reg);

escrever(reg);

readln;

End.

Apareçe um erro na alinea reset(fich) else rewrite(fich); , que dá o seguinte erro: Path not Found.

Alguem sabe como posso resolvelo.

obrigado

😉

Link to comment
Share on other sites

Boa Tarde,

    bom ja não programo em pascal a uns bons aninhos mas julgo que o erro esta neste if ( if existefich ('c:\LP\lojaMF2.dat') then)

a função deve retornar alguma coisa,ou seja deveras por if existefich('c:\LP\lojaMF2.dat') == true then  <condição_caso_seja_verdade> else <condição_caso_seja_falso>

Espero ter ajudado.

(Não sei se o sinal de igual em pascal é aquele.)

Cmpts

Link to comment
Share on other sites

Boa Tarde,

    bom ja não programo em pascal a uns bons aninhos mas julgo que o erro esta neste if ( if existefich ('c:\LP\lojaMF2.dat') then)

a função deve retornar alguma coisa,ou seja deveras por if existefich('c:\LP\lojaMF2.dat') == true then  <condição_caso_seja_verdade> else <condição_caso_seja_falso>

Espero ter ajudado.

(Não sei se o sinal de igual em pascal é aquele.)

Cmpts

???????? Existe alguma linguagem de programação em que o if não responda de acordo com o valor de retorno ser true/false???

funcao(...) <- retorna true

funcao(...) == true <- retorna true

qual é a diferença? :S

Não respondo a dúvidas por mensagem.

Link to comment
Share on other sites

Já agora o pessoal, tou aqui com mais uma duvida neste programa.

Queria acrescenta-lhe um ficheiro de clientes, no sentido de poder cruzar a informação relativa

aos clientes que compraram determinado automovel.

O programa tb devia apresentar listagem de todos os automoveis,pesquisa no ficheiro de automoveis segundo vários critérios;

Deve fazer o mesmo para o ficheiro de clientes, deve ainda permitir o cruzamento de

informação dos dois ficheiros no sentido de poder informar o utilizador acerca do cliente

que comprou determidado automovel ( no caso desse automovel ter sido vendido...)

Até agora isto é o que consegui resolver

Program Loja_musicaFase3 ;

Type

automoveis = record

Tipo:string;

Marca:string;

Modelo:string;

Cor:string;

Ano:integer;

Matricula:string;

end;

stand = file of automoveis;

Var

fich:stand;

reg:automoveis;

resp:char;

Procedure Ler (Var x:automoveis);

begin

writeln('Digite a marca do Automovel');

readln(x.Marca);

writeln('Digite o modelo do Automovel');

readln(x.Modelo);

writeln('Digite a cor do Automovel');

readln(x.Cor);

writeln('Digite o ano do Automovel');

readln(x.Ano);

writeln('Digite a matricula do Automovel');

readln(x.Matricula);

  end;

Procedure escrever(var xx:automoveis);

begin

writeln('A marca do automovel é',xx.Marca);

writeln('O modelo do automovel é',xx.Modelo);

writeln('A cor do automovel é',xx.Cor);

writeln('O ano do automovel é', xx.Ano);

writeln('A matricula do automovel é', xx.Matricula);

end;

  Function ExisteFich( xxx:string):boolean;

  Var

  f:stand;

  Begin

  {$I-}

  assign(fich,'c:\LP\LojaMF2.dat');

  reset(F);

  close (F);

  {$I+}

  If ioresult=0 then existefich:=true else existefich:=false;

  end;

Begin

assign (fich,'c:\LP\lojaM3.dat');

if existefich ('c:\LP\lojaMF2.dat') then

reset(fich) else rewrite(fich);

repeat

seek(fich,filesize(fich));

ler(reg);

write(fich,reg);

writeln('deseja continuar S\N ?');

readln(resp);

until (Resp = 'n') or  (resp = 'N')  ;

close (fich);

reset(fich);

read(fich,reg);

escrever(reg);

readln;

End.

Alguem sabe? :S

Link to comment
Share on other sites

Precisamos de estabelecer uma relação entre o automovel e o cliente (dono)

Para isso usamos uma chave de ligação (codigo de identificação unico)

Temos uma Entidade que é o Cliente e outra que é automóvel

Cliente  1 --> n  Automóvel

1 Cliente pode ter varios automóveis, mas um automovel só pode ser de 1 ou nenhum cliente.

Temos de ter 3 tabelas para esta relação:

1 para os clientes.

1 para os automveis

1 para a relacao

clientes(id, nome, morada, etc)

automovel(id, marca, modelo, etc)

dono(id_cliente, id_automovel)

Espero que isto resolva a tua questão,

agora é só implementar isto em pascal.

Link to comment
Share on other sites

Program stand_automoveis ;

Type

automoveis = record

Tipo:string;

Marca:string;

Modelo:string;

Cor:string;

Ano:integer;

Matricula:string;

end;

Type

clientes = record

n_cliente:integer;

nome:string;

morada:string;

telemovel:integer;

end;

stand = file of automoveis;

compradores =file of clientes;

Var

fich:stand;

reg:automoveis;

resp:char;

fich2:compradores;

reg2:clientes;

i:integer;

op:integer;

x:automoveis;

xx:clientes;

Function ExisteFich( xxx:string):boolean;

  Begin

  {$I-}

  assign(fich,'C:\ficheiros');

  reset(fich);

  close (fich);

  {$I+}

  If ioresult=0 then existefich:=true else existefich:=false;

  end;

Function ExisteFich2( xxx:string):boolean;

  Begin

  {$I-}

  assign(fich2,'C:\ficheiros2');

  reset(fich2);

  close (fich2);

  {$I+}

  If ioresult=0 then existefich2:=true else existefich2:=false;

  end;

Begin

writeln('Digite a marca do Automovel');

readln(x.Marca);

writeln('Digite o modelo do Automovel');

readln(x.Modelo);

writeln('Digite a cor do Automovel');

readln(x.Cor);

writeln('Digite o ano do Automovel');

readln(x.Ano);

writeln('Digite a matricula do Automovel');

readln(x.Matricula);

writeln('Digite o numero do ',i,' cliente');

readln(xx.n_cliente);

writeln('Digite o nome do ',i,' cliente');

readln(xx.nome);

writeln('Digite a morada do ',i,' cliente');

readln(xx.morada);

writeln('Digite o numero de telemovel do ',i,' cliente');

readln(xx.telemovel);

repeat

writeln('Menu');

writeln('1-Exibir automoveis');

writeln('2-Exibir clientes');

writeln('3-Exibir automoveis por marca');

writeln('4-Exibir automoveis por matricula');

writeln('5-Exibir compras dos clientes');

writeln('6-Sair');

readln(op);

if (op<=0) or (op>=7) then

Begin

writeln('opcao errada');

end;

case op of

1:begin

Só consegui fazer isto e o prazo pa entregar tase a acabar 😛

Alguem me pode corrigir e ajudar senão não chego lá

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.