Advertisement
Guest User

Untitled

a guest
Sep 28th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.38 KB | None | 0 0
  1. import std.stdio;
  2. import std.string;
  3.  
  4. struct Human
  5. {
  6.  string name;
  7.  float peso;
  8.  ushort age;
  9. };
  10.  
  11. void print_list(Human[] human_list)
  12. {
  13.  foreach(human; human_list)
  14.    {
  15.     writefln("\nNome: %s",human.name);
  16.     writefln("Peso: %0.2f",human.peso);
  17.     writefln("Idade: %d\n",human.age);
  18.    }
  19. }
  20.  
  21. void add_human(Human[] human_list)
  22. {
  23.   ushort age;
  24.   float peso;
  25.   string name;
  26.  
  27.   write("\nName: ");                          
  28.   readf(" %s\n", &name);                        
  29.   writeln();
  30.   write("Peso: ");                          
  31.   readf(" %f\n", &peso);
  32.   writeln();
  33.   write("Age: ");                            
  34.   readf(" %u\n", &age);                      
  35.  
  36.   Human tmp_human = {name, peso, age};
  37.   human_list ~= tmp_human;
  38. }
  39.  
  40. void main()
  41. {
  42.   Human[] human_list;
  43.   char choice;
  44.  
  45.   do{
  46.       writeln("A)dd New Human.");
  47.       writeln("P)rint Human List.");
  48.       writeln("Q)uit.");
  49.  
  50.       write("Input: ");
  51.       readf(" %c", &choice);
  52.        
  53.       switch(choice)
  54.        {
  55.          case('A'):
  56.          case('a'): add_human(human_list);
  57.          break;
  58.          
  59.          case('P'):
  60.          case('p'): print_list(human_list);
  61.          break;
  62.          
  63.          case('Q'):
  64.          case('q'):
  65.          break;
  66.          
  67.          default: writeln("Opção Invalida ..!!!\n");
  68.       }
  69.     }while(choice != 'q' || choice != 'Q');
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement