(C PROGRAMMING ONLY!) 3. Pet Lover by CodeChum Admin One of the easiest ways to make a pet lover happy is to give them very many pets! My friend, Jhelian is a pet lover and for her 21st birthday, I'm planning to give her very many Dogs. It's very timely because my pet dog just gave birth to a lot of cuties! So I don't really need to buy. All I need is to just give these cute little fur babies to her. Instructions: In the code editor, you are provided with the definition of a struct Dog. This struct needs a character value for its gender, which could either be 'm' for a male Dog or 'f' for a female Dog. Furthermore, an array of Dogs has already been created an each of their genders has been set. Then, on line 16, a call to the function giveDogs() was made where the dogs array was passed. Your task is to implement this giveDogs() function which has the following details: Return type - void Name - giveDogs Parameters a pointer/holder of a Dogs array size of the Dogs array Description - loops through the Dogs array and prints the correct message (refer to the sample output) Output Note that the dog number starts at 1, not 0. Dog #1 (gender = m) Dog #2 (gender = f) Dog #3 (gender = m) Dog #4 (gender = f) Dog #5 (gender = m) Dog #6 (gender = f) Dog #7 (gender = m) Dog #8 (gender = f) Dog #9 (gender = m) Dog #10 (gender = f) Dog #11 (gender = m) Dog #12 (gender = f) Dog #13 (gender = m)
(C PROGRAMMING ONLY!)
3. Pet Lover
by CodeChum Admin
One of the easiest ways to make a pet lover happy is to give them very many pets!
My friend, Jhelian is a pet lover and for her 21st birthday, I'm planning to give her very many Dogs. It's very timely because my pet dog just gave birth to a lot of cuties!
So I don't really need to buy. All I need is to just give these cute little fur babies to her.
Instructions:
In the code editor, you are provided with the definition of a struct Dog. This struct needs a character value for its gender, which could either be 'm' for a male Dog or 'f' for a female Dog.
Furthermore, an array of Dogs has already been created an each of their genders has been set. Then, on line 16, a call to the function giveDogs() was made where the dogs array was passed.
Your task is to implement this giveDogs() function which has the following details:
Return type - void
Name - giveDogs
Parameters
a pointer/holder of a Dogs array
size of the Dogs array
Description - loops through the Dogs array and prints the correct message (refer to the sample output)
Output
Note that the dog number starts at 1, not 0.
Dog #1 (gender = m)
Dog #2 (gender = f)
Dog #3 (gender = m)
Dog #4 (gender = f)
Dog #5 (gender = m)
Dog #6 (gender = f)
Dog #7 (gender = m)
Dog #8 (gender = f)
Dog #9 (gender = m)
Dog #10 (gender = f)
Dog #11 (gender = m)
Dog #12 (gender = f)
Dog #13 (gender = m)
.
.
.
![Dog #3
(gender
Dog #4 (gender =
f)
main.c
く
<>
+ c
Dog #5 (gender
= m)
1 #include<stdio.h>
Dog #6 (gender = f)
2
Dog #7 (gender = m)
3 typedef struct {
char gender;
Dog #8 (gender = f)
4
Dog #9 (gender = m)
5 } Dog;
Dog #10 (gender = f)
7 void giveDogs(Dog*, int);
Dog #11 (gender = m)
8
Dog #12 (gender = f)
9 int main(void) {
Dog dogs[100];
Dog #13 (gender = m)
10
11
for(int i
dogs[i].gender = i % 2 == 0 ? 'm' : 'f';
}
12
= 0; i < 100; i++) {
13
15
giveDogs (dogs, 100);
16
17
O O H N m4](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F71371a8c-30ee-4a4f-b2de-58573b8f2d7c%2F44d4dc32-876d-430f-a4c7-8273731d860c%2Frfagjeb_processed.jpeg&w=3840&q=75)
![main.c
<>
+ c
4
char gender;
5 } Dog;
7 void giveDogs (Dog*, int);
8
9 int main(void) {
Dog dogs[100];
10
11
for(int i = 0; i < 100; i++) {
dogs[i].gender = i % 2
}
12
13
== 0 ? 'm' : 'f';
14
15
giveDogs (dogs, 100);
16
17
18
return 0;
19 }
20
21 void giveDogs(Dog *dogs, int size) {
// TODO: Implement this
22
23 }](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F71371a8c-30ee-4a4f-b2de-58573b8f2d7c%2F44d4dc32-876d-430f-a4c7-8273731d860c%2Fa9blxuj_processed.jpeg&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images









