(C PROGRAMMING ONLY) 5. Making a Kid From Two Persons by CodeChum Admin `The population is slowly decreasing! It's now time to enable these Persons to create their own. But we need to be careful. The overall gender distribution of the Persons should always be maintained (i.e. the Male should be nearly equal as the female) so that gender equality can be easier to maintain. Here is the guide in determining the gender of the newly created Person: If the father is older than the mother, then the child is Male If the mother is older than the father, then the child is Female If the father's age is equal to the mother's age and the age is even, then the child is Male If the father's age is equal to the mother's age and the age is odd, then the child is Female What are you waiting for, let's settle this problem once and for all! Instructions: In the code editor, you are provided with the definition of a struct Person. This struct needs an integer value for its age and a character value for its gender. Furthermore, you are provided with a displayPerson() function which accepts a struct Person as its parameter. In the main(), there are two Persons already created: one Male Person and one Female Person. Your task is to first ask the user for the age of the Male Person and the age of the Female Person. Then, define and declare a function called createKidPerson() which has the following definition: Return type - Person Name - createKidPerson Parameters Person father - the father of the kid to be created Person mother - the mother of the kid to be created Description - creates a new Person and returns this. The age of this Person will be set to 1 while its gender will be set based on the rules mentioned above. Finally, create a new Person and call this createKidPerson() in the main and then pass this newly created Person in the displayPerson() function. Input 1. The age of the Male Person 2. The age of the Female Person Output Enter the Male Person's age: 24 Enter the Female Person's age: 21 PERSON DETAILS: Age: 1 Gender: Male
(C PROGRAMMING ONLY)
5. Making a Kid From Two Persons
by CodeChum Admin
`The population is slowly decreasing!
It's now time to enable these Persons to create their own. But we need to be careful. The overall gender distribution of the Persons should always be maintained (i.e. the Male should be nearly equal as the female) so that gender equality can be easier to maintain.
Here is the guide in determining the gender of the newly created Person:
If the father is older than the mother, then the child is Male
If the mother is older than the father, then the child is Female
If the father's age is equal to the mother's age and the age is even, then the child is Male
If the father's age is equal to the mother's age and the age is odd, then the child is Female
What are you waiting for, let's settle this problem once and for all!
Instructions:
In the code editor, you are provided with the definition of a struct Person. This struct needs an integer value for its age and a character value for its gender. Furthermore, you are provided with a displayPerson() function which accepts a struct Person as its parameter. In the main(), there are two Persons already created: one Male Person and one Female Person.
Your task is to first ask the user for the age of the Male Person and the age of the Female Person.
Then, define and declare a function called createKidPerson() which has the following definition:
Return type - Person
Name - createKidPerson
Parameters
Person father - the father of the kid to be created
Person mother - the mother of the kid to be created
Description - creates a new Person and returns this. The age of this Person will be set to 1 while its gender will be set based on the rules mentioned above.
Finally, create a new Person and call this createKidPerson() in the main and then pass this newly created Person in the displayPerson() function.
Input
1. The age of the Male Person
2. The age of the Female Person
Output
Enter the Male Person's age: 24
Enter the Female Person's age: 21
PERSON DETAILS:
Age: 1
Gender: Male
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images