Question

In: Computer Science

Write a program that defines an animal data type, with an animal name, age, and category...

Write a program that defines an animal data type, with an animal name, age, and category (cat, dog, etc.), as well as an animal array type that stores an array of animal pointers. Your program will prompt the user to enter the data for as many animals as they wish. It will initialize a dynamically allocated animal structure for each animal, and it will store each animal in an instance of the animal array structure. Your program will then print all the animal information to the screen. You will upload your C program as one file.

Solutions

Expert Solution

C program to collect animal details

Steps:

  • Ask user the number of animal details wishes to enter
  • Collect the animal details
  • Display the collected animal details

Source code:

#include <stdio.h>
struct student {
    char firstName[50];
    int num;

    int age;
} s[10];

int main() {
    int i,x;
    //int x;
    printf("Enter the number of animal details you wish to collect :");
    scanf("%d",&x);

    // storing information
    for (i = 0; i < x; ++i) {
        s[i].num = i + 1;
        printf("\n Number : %d,\n", s[i].num);
        printf("Enter animal name: ");
        scanf("%s", s[i].firstName);
        printf("Enter the age : ");
        scanf("%d", &s[i].age);
    }
    printf("Displaying Information:\n\n");

    // displaying information
    for (i = 0; i < x; ++i) {
        printf("\nNumber : %d\n", i + 1);
        printf("Animal  name: ");
        puts(s[i].firstName);
        printf("Age : %d", s[i].age);
        printf("\n");
    }
    return 0;
}

The output


Related Solutions

Write a program that defines an animal data type, with an animal name, age, and category...
Write a program that defines an animal data type, with an animal name, age, and category (cat, dog, etc.), as well as an animal array type that stores an array of animal pointers. (ex. structType *arr[size];) Your program will prompt the user to enter the data for as many animals as they wish. It will initialize a dynamically allocated animal structure for each animal, and it will store each animal in an instance of the animal array structure. Your program...
Part A In PyCharm, write a program that prompts the user for their name and age....
Part A In PyCharm, write a program that prompts the user for their name and age. Your program should then tell the user the year they were born. Here is a sample execution of the program with the user input in bold: What is your name? Amanda How old are you? 15 Hello Amanda! You were born in 2005. Write the program. Format your code using best practices. Refer to the zyBooks style guide, if needed, to use proper naming...
(JAVA) Create a program that prompts the user for an age input. The program defines the...
(JAVA) Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program. Age Age Group 0 Baby 1-3 Toddler 4-11 Child 12-17 Teenager 18-21 Young Adult 22-64 Adult 65+ Senior Negative Number Invalid Input Sample Input Enter an age: 18 Sample Output: You are a young adult. Sample Input Enter an age: 29 Sample Output: You are an adult. Sample...
Write a program that: (a) Reads name and age of 10 different persons (b) Stores this...
Write a program that: (a) Reads name and age of 10 different persons (b) Stores this information in a dictionary (remember, dictionary contains keys and values) (c) Sorts your dictionary based on keys (d) Sorts your dictionary based on values (e) Displays the original and both sorted dictionaries (step c and d) (f) You search for a specific person and the program displays their name and age on the screen. If the person’s information is not in the dictionary, the...
DO THIS IN C#. Design and implement a program (name it MinMaxAvg) that defines three methods...
DO THIS IN C#. Design and implement a program (name it MinMaxAvg) that defines three methods as follows: Method max (int x, int y, int z) returns the maximum value of three integer values. Method min (int X, int y, int z) returns the minimum value of three integer values. Method average (int x, int y, int z) returns the average of three integer values. In the main method, test all three methods with different input value read from the...
Search for Methylprednisolone information: Generic Name, Brand Name, Type of drug, Pregnancy Category, Therapeutic action, ....
Search for Methylprednisolone information: Generic Name, Brand Name, Type of drug, Pregnancy Category, Therapeutic action, . Indications, Contraindications,. Dose / Adult and Pediatric, Adverse effects, Interactions, Nursing considerations in implementation and Patient Education
Search for Dobutamine information: Generic Name, Brand Name, Type of drug, Pregnancy Category, Therapeutic action, ....
Search for Dobutamine information: Generic Name, Brand Name, Type of drug, Pregnancy Category, Therapeutic action, . Indications, Contraindications,. Dose / Adult and Pediatric, Adverse effects, Interactions, Nursing considerations in implementation and Patient Education
Search for Glucagon information: Generic Name, Brand Name, Type of drug, Pregnancy Category, Therapeutic action, ....
Search for Glucagon information: Generic Name, Brand Name, Type of drug, Pregnancy Category, Therapeutic action, . Indications, Contraindications,. Dose / Adult and Pediatric, Adverse effects, Interactions, Nursing considerations in implementation and Patient Education
Search for Labetalol information: Generic Name, Brand Name, Type of drug, Pregnancy Category, Therapeutic action, ....
Search for Labetalol information: Generic Name, Brand Name, Type of drug, Pregnancy Category, Therapeutic action, . Indications, Contraindications,. Dose / Adult and Pediatric, Adverse effects, Interactions, Nursing considerations in implementation and Patient Education
Search for Metoprolol information: Generic Name, Brand Name, Type of drug, Pregnancy Category, Therapeutic action, ....
Search for Metoprolol information: Generic Name, Brand Name, Type of drug, Pregnancy Category, Therapeutic action, . Indications, Contraindications,. Dose / Adult and Pediatric, Adverse effects, Interactions, Nursing considerations in implementation and Patient Education
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT