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...
(Write/read data) Write a Program in BlueJ to create a file name Excersise12_15.txt if it does...
(Write/read data) Write a Program in BlueJ to create a file name Excersise12_15.txt if it does not exist. Write 100 integers created randomly into the file using text I/O. Integers are separated by spaces in the file. Read data back from the file and display the data in increasing order. After writing the file to disk, the input file should be read into an array, sorted using the static Arrays.sort() method from the Java API and then displayed in the...
use python 1. Write a program that a. defines a list of countries that are members...
use python 1. Write a program that a. defines a list of countries that are members of BRICS (Brazil, Russia, India, China, Sri Lanka) b. Check whether a country is a member of BRICS or not Program run Enter the name of country: Pakistan Pakistan is not a member of BRICS Enter the name of country : India India is a member of BRICS 2. Write a program to create a list of numbers in the range of 1 to...
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT