Pascal Car Rental System

Asked

Viewed 1,198 times

-5

Want instructions on how to make a car rental company, how should my code work? Can anyone help me?

  • 1

    Andrey, SOPT works much better if you have a concrete question about what you want to do, or an error that is actually happening. Your question currently asks for the solution of many different problems without providing details about exactly where you are having difficulties. Read this post about "too broad" questions and try to rephrase your question. I’m sure you’ll get help. Welcome to SOPT!

1 answer

3

Basically saying you should create a registry vector that will contain the following data: car model, make, daily value, situation (Available or Rented), current customer and daily amount.

Consider that the program has the customer registration with code, name and telephone.

Vehicle registration: To enter the data of a vehicle in one of the available positions, when the program is started, the first position shall be initialized with the name Available and other data with zero. Whenever a new vehicle is registered, the next position shall be initialized with the name Available and other data with zero (unless the vector capacity is exceeded).

Vehicle exit: To register the exit of a vehicle the user must indicate the car model, the name of the customer who is renting the car and the amount of daily requested.

If the car is available, you should change the situation to rent and register the other data. If the car is already rented, the program should display a message stating this and return to the main menu.

Return of vehicle: To register the return of a vehicle the user must search the model of the car. When you find it, you should display on the screen the customer’s name, car model and total rental value. After that, should modify the situation of the car to available.

Take this example:

program locadora_auto;
uses crt;

type cadastro_locadora=record
        modelo_carro:string;
        marca:string;
        valor_diaria:real;
        situacao:char;
        cliente_atual:string;
        quantidade_diaria:integer;
   end;
   {Criação de um tipo registro para o cadastro da locadora}

   vet1=array [1..10]of cadastro_locadora;
   {Criação de um tipo vetor de tamanho 10 do tipo cadastro_locadora,
   para facilitar o desenvolvimento do programa}

var vetor:vet1;                //vetor - Criação de um vetor do tipo vet1 para o armazenamento dos cadastros
    cont,cont2,m,j:integer;    //Cont - Conta o número de posições utilizadas do vetor
                               //Cont2 - Um contador para saber se o registro digitado encontra-se no vetor (nesse caso soma +1), pra fazer a verificação - Se cont2=0 e o vetor se encontrar na última posição, o programa imprimirá um texto alegando que o registro nao se encontra no vetor.
                               //m - Criado para a leitura e verificação dos índices do menu
                               //j - Criado para uso do laço de repetição FOR
    nome_carro:string;         //nome_carro - Criado para receber o nome do carro para verificar se o texto digitado bate com o salvo no vetor

{Inicializa todos os itens do registro conforme pedido}
procedure inicializa(var vet:vet1;i:integer);
begin
   vet[i].modelo_carro:='0';
   vet[i].marca:='0';
   vet[i].valor_diaria:=0;
   vet[i].situacao:='D';
   vet[i].cliente_atual:='0';
   vet[i].quantidade_diaria:=0;
end;

{Faz a atribuição dos nomes e valores a suas devidas variáveis}
procedure cadastro(var vet:vet1;i:integer);
begin
   writeln('Modelo do carro: ');
   readln(vet[i].modelo_carro);
   vet[i].modelo_carro:=upcase(vet[i].modelo_carro);
   writeln('Marca do carro: ');
   readln(vet[i].marca);
   vet[i].marca:=upcase(vet[i].marca);
   write('Valor da diaria: R$');
   read(vet[i].valor_diaria);
   vet[i].situacao:='D';
   vet[i].cliente_atual:='0';
   vet[i].quantidade_diaria:=0;
end;

{Armazena no vetor o nome do cliente e o numero de diarias e muda a situação do veículo para alugado}
procedure saida(var vet:vet1;i:integer);
begin
   vet[i].situacao:='A';
   writeln('Nome do cliente: ');
   readln(vet[i].cliente_atual);
   repeat
   begin
      writeln('Numero de diarias: ');
      readln(vet[i].quantidade_diaria);
   end;
   until (vet[i].quantidade_diaria<30);

end;

{Imprime os dados do cliente, o valor total da locação, e muda a situação do carro para disponível}
procedure devolucao(var vet:vet1;i:integer);
begin
   writeln('Nome do cliente: ', vet[i].cliente_atual);
   writeln('Modelo atual: ', vet[i].modelo_carro);
   writeln('Valor total da locacao: R$', (vet[i].valor_diaria*vet[i].quantidade_diaria):2:2);
   vet[i].situacao:='D';
   vet[i].cliente_atual:='0';
   vet[i].quantidade_diaria:=0;
   readln;
end;

{Apenas exibe o menu na tela}
procedure menu();
begin
   writeln('[1] - Cadastro de veiculo');
   writeln('[2] - Saida de veiculo');
   writeln('[3] - Devolucao de veiculo');
   writeln('[4] - Sair');
end;

begin
   cont:=1;
   repeat
   begin
      clrscr;
      menu();
      readln(m);
      if m=1 then //cadastro de veículo
      begin
         clrscr;
         inicializa(vetor,cont);
         cadastro(vetor,cont);
         cont:=cont+1;
         inicializa(vetor,cont);
         cont2:=0;
      end
      else if m=2 then  //saída de veículo
      begin
         clrscr;
         writeln('Digite o modelo do carro: ');
         readln(nome_carro);
         nome_carro:=upcase(nome_carro);
         for j:=1 to 10 do
         begin
            if vetor[j].modelo_carro=nome_carro then  //se o nome do carro digitado está cadastrado no sistema
            begin
               writeln;
               saida(vetor,j);
               cont2:=cont2+1;
            end;
            if (cont2=0) and (j=10) then  //se tiver na ultima posição do vetor e o contador cont2=0, não existe o carro cadastrado no sistema
            begin
               writeln;
               writeln('Modelo nao cadastrado!');
               readln;
            end;
         end;
      end
      else if m=3 then   //devolução de veículo
      begin
         clrscr;
         writeln('Digite o modelo do carro: ');
         readln(nome_carro);
         nome_carro:=upcase(nome_carro);
         for j:=1 to 10 do
         begin
            if vetor[j].modelo_carro=nome_carro then  //se o nome do carro digitado está cadastrado no sistema
            begin
               writeln;
               devolucao(vetor,j);
               cont2:=cont2+1;
            end;
            if (cont2=0) and (j=10) then  //se tiver na ultima posição do vetor e o contador cont2=0, não existe o carro cadastrado no sistema
            begin
               writeln;
               writeln('Modelo nao cadastrado!');
               readln;
            end;
         end;
      end;
   end;
   until (m=4);
end.

Source

  • There are people who vote negative because the question is bad. This was commented on the goal a few days ago. Patience.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.