Question

In: Computer Science

Define a struct pet with properties name, age, weight, and type. Use appropriate data types for the different properties.

use C source code to complete the following:

Define a struct pet with properties name, age, weight, and type. Use appropriate data types for the different properties. You may assume that the strings will never be longer than 19 chars. Don’t forget to add an extra char for the NULL character that terminates the strings.

Solutions

Expert Solution

struct pet // structure declaration

{

char name[20];

int age;

float weight;

string type; // Considering type as string assuming that its type of pet

} p1; // creating stucture variable p1.

int main ()

{

struct pet p2; // cerating variable p2 for structure

}

// We can create structure variables as shown in above 2 types ( for p1 and p2)


Related Solutions

Create a User struct that has properties for basic information about a user. At a minimum, it should have properties to represent a user's name, age, height, weight, and activity level.
Create a User struct that has properties for basic information about a user. At a minimum, it should have properties to represent a user's name, age, height, weight, and activity level. You could do this by having name be a String, age be an Int, height and weight be of type Double, and activityLevel be an Int that will represent a scoring 1-10 of how active they are. Implement this now.Create a variable instance of User and call it your...
declare a struct named matrix and typedef the struct to type name Matrix. A mathematical matrix...
declare a struct named matrix and typedef the struct to type name Matrix. A mathematical matrix is a two-dimensional, rectangular data structure. The matrix struct should have three fields (in this order): an unsigned variable named "rows", an unsigned variable named "columns", and a pointer to a pointer to double (i.e. double**) named "data". (Code #including matrix.h should be able to declare Matrix variables.) In matrix.c, implement the create_matrix function. The Matrix should be filled with 0.0 values. data[i] should...
(C++ ONLY) You will define your own data type. It will be a struct called Fraction....
(C++ ONLY) You will define your own data type. It will be a struct called Fraction. The struct will have 2 integer fields: numerator and denominator. You will write a function called reduce that takes a Fraction as a parameter and returns that Fraction in its reduced form. For example, if the fraction 2/4 is passed to the function, the fraction 1/2 will be returned. Consider any fraction with a denominator of 1 to be in reduced form. You will...
Name the different types of research in healthcare and describe the focus of each type and...
Name the different types of research in healthcare and describe the focus of each type and how it advances healthcare in the US.
Please TYPE your answers: (a) Name the types of NONsampling error and define them in a...
Please TYPE your answers: (a) Name the types of NONsampling error and define them in a sentence or two. (b) Name the types of sampling error and define them in a sentence or two.
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...
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...
1. Define a struct for a soccer player that stores their name, jersey number, and total...
1. Define a struct for a soccer player that stores their name, jersey number, and total points scored. 2. Using the struct in #1, write a function that takes an array of soccer players and its size as arguments and returns the average number of points scored by the players. 3. Using the struct in #1, write a function that takes an array of soccer players and its size as arguments and returns the index of the player who scored...
implement the following logic in Python, use appropriate data types. Data types are represented as either...
implement the following logic in Python, use appropriate data types. Data types are represented as either numeric (num) or string. string name string address num item num quantity num price num SIZE = 6 num VALID_ITEM [SIZE] = 106, 108, 307, 405, 457, 688 num VALID_ITEM_PRICE [SIZE] = 0.59, 0.99, 4.50, 15.99, 17.50, 39.00 num sub string foundIt = “N” string MSG_YES = “Item available” string MSG_NO = “Item not found” get name, address, item, quantity sub = 0 while...
name four different types of steels and cite compositional differences, distinctive properties, and typical uses for...
name four different types of steels and cite compositional differences, distinctive properties, and typical uses for each.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT