Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Animals can be classified into insects, birds, mammals and fishes.
- Write a program making the best use of composite variables and
- bit fields to manage a database of animal entries. The system must
- be able to add, delete, replace and lookup entries into the memory
- database. The animal classes are described by:
- (a) number of legs and life span for insects
- (b) flight speed, wing length and migration habbits for birds
- (c) weight, height and food type for mammals
- (d) weight, swimming depth and water salt percentage for fishes*/
- #include <stdio.h>
- #include "animals.h"
- #include <stdlib.h>
- int main()
- {
- int nr_i,nr_b,nr_m,nr_f,x,a;
- printf("How many insects do you want to enter?\n");
- scanf("%d",&nr_i);
- printf("Enter information of insects:\n");
- // storing information
- for(x=0; x<nr_i; ++x)
- {
- i[x].nr = x+1;
- printf("\nThe insect number %d:\n",i[x].nr);
- printf("Enter insect: ");
- scanf("%s",i[x].name);
- printf("Enter the number of legs: ");
- scanf("%d",&i[x].nr_legs);
- printf("Enter the life span in months: ");
- scanf("%d",&i[x].lspan);
- printf("\n");
- }
- printf("How many birds do you want to enter?\n");
- scanf("%d",&nr_b);
- printf("Enter information of birds:\n");
- // storing information
- for(x=0; x<nr_b; ++x)
- {
- b[x].nr = x+1;
- printf("\nThe bird number %d:\n",b[x].nr);
- printf("Enter bird: ");
- scanf("%s",b[x].name);
- printf("Enter the flight speed in km/h: ");
- scanf("%d",&b[x].fspeed);
- printf("Enter the wing lenght in meters: ");
- scanf("%.1f",&b[x].wlength);
- //printf("Enter the migration habbits: ");
- //scanf("%s",b[x].mhabits);
- printf("\n");
- }
- printf("How many mammals do you want to enter?\n");
- scanf("%d",&nr_m);
- printf("Enter information of mammals:\n");
- // storing information
- for(x=0; x<nr_m; ++x)
- {
- m[x].nr = x+1;
- printf("\nThe mammal number %d:\n",m[x].nr);
- printf("Enter mammal: ");
- scanf("%s",m[x].name);
- printf("Enter the weight in kg: ");
- scanf("%.1f",&m[x].weight);
- printf("Enter the height in cm: ");
- scanf("%d",&m[x].height);
- //printf("Enter the food type: ");
- //scanf("%s",m[x].food);
- printf("\n");
- }
- printf("How many fishes do you want to enter?\n");
- scanf("%d",&nr_f);
- printf("Enter information of fishes:\n");
- // storing information
- for(x=0; x<nr_f; ++x)
- {
- f[x].nr = x+1;
- printf("\nThe fish number %d:\n",f[x].nr);
- printf("Enter fish: ");
- scanf("%s",f[x].name);
- printf("Enter the weight in kg: ");
- scanf("%.1f",&f[x].weight);
- printf("Enter the swimming depths in m: ");
- scanf("%d",&f[x].sdepths);
- printf("Enter the water salt percentage: ");
- scanf("%d",&f[x].wsaltper);
- printf("\n");
- }
- printf("Displaying Information:\n\n");
- // displaying information
- for(x=0; x<nr_i; ++x)
- {
- printf("\nInsect number: %d\n",x+1);
- printf("Name: ");
- puts(i[x].name);
- printf("Number of legs: %d\n",i[x].nr_legs);
- printf("Life span: %d months\n",i[x].lspan);
- printf("\n");
- }
- printf("If you wish to add another student,press 1\n");
- scanf("%d",&a);
- if(a==1)
- printf("HAI");
- else
- printf("No student,okay boss");
- return 0;
- }
- struct insects
- {
- char name[10];
- int nr;
- int nr_legs;
- int lspan;
- }i[10];
- struct birds
- {
- //char mhabits[100];
- char name[10];
- int nr;
- int fspeed;
- float wlength;
- }b[10];
- struct mammals
- {
- char name[30];
- int nr;
- float weight;
- int height;
- //char food[30];
- }m[10];
- struct fishes
- {
- char name[20];
- int nr;
- float weight;
- int sdepths;
- int wsaltper;
- }f[10];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement