SHARE
TWEET

Struct HW

Kocolino Mar 20th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*Animals can be classified into insects, birds, mammals and fishes.
  2. Write a program making the best use of composite variables and
  3. bit fields to manage a database of animal entries. The system must
  4. be able to add, delete, replace and lookup entries into the memory
  5. database. The animal classes are described by:
  6. (a) number of legs and life span for insects
  7. (b) flight speed, wing length and migration habbits for birds
  8. (c) weight, height and food type for mammals
  9. (d) weight, swimming depth and water salt percentage for fishes*/
  10.  
  11. #include <stdio.h>
  12. #include "animals.h"
  13. #include <stdlib.h>
  14.  
  15. int main()
  16. {
  17.     int nr_i,nr_b,nr_m,nr_f,x,a;
  18.     printf("How many insects do you want to enter?\n");
  19.     scanf("%d",&nr_i);
  20.  
  21.     printf("Enter information of insects:\n");
  22.  
  23.     // storing information
  24.     for(x=0; x<nr_i; ++x)
  25.     {
  26.         i[x].nr = x+1;
  27.  
  28.         printf("\nThe insect number %d:\n",i[x].nr);
  29.  
  30.         printf("Enter insect: ");
  31.         scanf("%s",i[x].name);
  32.  
  33.  
  34.         printf("Enter the number of legs: ");
  35.         scanf("%d",&i[x].nr_legs);
  36.  
  37.         printf("Enter the life span in months: ");
  38.         scanf("%d",&i[x].lspan);
  39.  
  40.         printf("\n");
  41.     }
  42.  
  43.     printf("How many birds do you want to enter?\n");
  44.     scanf("%d",&nr_b);
  45.  
  46.     printf("Enter information of birds:\n");
  47.  
  48.     // storing information
  49.     for(x=0; x<nr_b; ++x)
  50.     {
  51.         b[x].nr = x+1;
  52.  
  53.         printf("\nThe bird number %d:\n",b[x].nr);
  54.  
  55.         printf("Enter bird: ");
  56.         scanf("%s",b[x].name);
  57.  
  58.         printf("Enter the flight speed in km/h: ");
  59.         scanf("%d",&b[x].fspeed);
  60.  
  61.         printf("Enter the wing lenght in meters: ");
  62.         scanf("%.1f",&b[x].wlength);
  63.  
  64.         //printf("Enter the migration habbits: ");
  65.         //scanf("%s",b[x].mhabits);
  66.  
  67.  
  68.         printf("\n");
  69.     }
  70.  
  71.  
  72.     printf("How many mammals do you want to enter?\n");
  73.     scanf("%d",&nr_m);
  74.  
  75.      printf("Enter information of mammals:\n");
  76.  
  77.     // storing information
  78.     for(x=0; x<nr_m; ++x)
  79.     {
  80.         m[x].nr = x+1;
  81.  
  82.         printf("\nThe mammal number %d:\n",m[x].nr);
  83.  
  84.         printf("Enter mammal: ");
  85.         scanf("%s",m[x].name);
  86.  
  87.         printf("Enter the weight in kg: ");
  88.         scanf("%.1f",&m[x].weight);
  89.  
  90.         printf("Enter the height in cm: ");
  91.         scanf("%d",&m[x].height);
  92.  
  93.         //printf("Enter the food type: ");
  94.         //scanf("%s",m[x].food);
  95.  
  96.  
  97.         printf("\n");
  98.     }
  99.  
  100.     printf("How many fishes do you want to enter?\n");
  101.     scanf("%d",&nr_f);
  102.  
  103.     printf("Enter information of fishes:\n");
  104.  
  105.     // storing information
  106.     for(x=0; x<nr_f; ++x)
  107.     {
  108.         f[x].nr = x+1;
  109.  
  110.         printf("\nThe fish number %d:\n",f[x].nr);
  111.  
  112.         printf("Enter fish: ");
  113.         scanf("%s",f[x].name);
  114.  
  115.         printf("Enter the weight in kg: ");
  116.         scanf("%.1f",&f[x].weight);
  117.  
  118.         printf("Enter the swimming depths in m: ");
  119.         scanf("%d",&f[x].sdepths);
  120.  
  121.         printf("Enter the water salt percentage: ");
  122.         scanf("%d",&f[x].wsaltper);
  123.  
  124.  
  125.         printf("\n");
  126.     }
  127.  
  128.     printf("Displaying Information:\n\n");
  129.     // displaying information
  130.     for(x=0; x<nr_i; ++x)
  131.     {
  132.         printf("\nInsect number: %d\n",x+1);
  133.         printf("Name: ");
  134.         puts(i[x].name);
  135.         printf("Number of legs: %d\n",i[x].nr_legs);
  136.         printf("Life span: %d months\n",i[x].lspan);
  137.  
  138.         printf("\n");
  139.     }
  140.  
  141.     printf("If you wish to add another student,press 1\n");
  142.  
  143.  
  144.     scanf("%d",&a);
  145.     if(a==1)
  146.         printf("HAI");
  147.     else
  148.         printf("No student,okay boss");
  149.  
  150.  
  151.     return 0;
  152. }
  153.  
  154. struct insects
  155. {
  156.     char name[10];
  157.     int nr;
  158.     int nr_legs;
  159.     int lspan;
  160. }i[10];
  161.  
  162. struct birds
  163. {
  164.     //char mhabits[100];
  165.     char name[10];
  166.     int nr;
  167.     int fspeed;
  168.     float wlength;
  169.  
  170.  
  171. }b[10];
  172.  
  173. struct mammals
  174. {
  175.     char name[30];
  176.     int nr;
  177.     float weight;
  178.     int height;
  179.     //char food[30];
  180. }m[10];
  181.  
  182. struct fishes
  183. {
  184.     char name[20];
  185.     int nr;
  186.     float weight;
  187.     int sdepths;
  188.     int wsaltper;
  189. }f[10];
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top