Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone please make me a program that exactly follows the following instructions? Problem 2: Code You are observing penguins and their moods at the

Can someone please make me a program that exactly follows the following instructions?

Problem 2: Code

You are observing penguins and their moods at the local zoo. You keep track of the moods and the number of penguins with that mood in a file calledpenguins.txtand want to create a report like the output file given below (with the first line containing the total number of penguins and the moods on the next line).

Define the functions given below to match the sample run (they should work with the given main below).

Make sure not to hardcode the file information in the code the code should work with any input file, not just the one example I am giving.

Penguins.txt (input file)

Happy

3

Silly

4

Angry

5

Structure of the input file:

Mood

# of penguins with that mood

Mood

# of penguins with that mood

Mood

# of penguins with that mood

Output file:

***12 Penguins!***

-Moods: Happy, Silly and Angry!

Given Codes

#include

#include

#include

/*This function takes an input filename, a 2D array to hold penguin moods, and a 1D array

to hold the number of penguins that have that mood (see input file to see the different moods and the number that have that mood.)

The function should return 0 if the file doesnt open and 1 if it does open and file contents are successfully read in to arrays*/

int read_file(char filename[][, char all_penguins_mood[][20], int penguin_count[]]

/*This function takes an output filename, a 2D array that is holding penguin moods from the input file,

and a total number of penguins counted. It should output a file like the output file shown above

(the total count of penguins in the header followed by a list of all the moods.*/

void penguin_report(char filename[], char all_penguins_mood[][20], int penguin_count)

int main (int argc, char **argv)

{

int i, total_penguins=0;

char moods[3][20];

int counts[3];

int file=read_file(argv[1], moods, counts);

if(file)

{

for(i=0;i

{

total_penguins += counts[i] // note that this could also be written as: total_penguins=total_penguins+counts[i];

}

penguin_report(argv[2], moods, total_penguins);

}

else

{

printf(\"File didn't open...exiting \")

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Android 4 Application Development

Authors: Reto Meier

3rd Edition

1118223853, 9781118223857

More Books

Students also viewed these Programming questions

Question

What kind of lookup did you perform in the preceding problem?

Answered: 1 week ago