Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your job is now to copy countDucks.cpp to a file myProg02.cpp and make some changes First, let's stipulate that you may assume that everything in

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Your job is now to copy countDucks.cpp to a file myProg02.cpp and make some changes First, let's stipulate that you may assume that everything in the input file is an animal, one per line-if someone adds "potato" or "bicycle" to the file, you can just assume that potato and bicycle are now to be considered types of animals 1. Add a variable that will count ALL animals in the file. Give it an appropriate name and initialize it to zero 2. Add a variable that will count ALL animals in the file that are NOT ducks. Give it an appropriate name and initialize it to zero 3. Add code that will increment those counts when appropriate. It may help to know that C++ has an else clause for an if that looks like this: if (condition) // lines of code here are // executed when condition is true else // lines of code here are // executed when condition is false Note that it is NOT required for every if to have an else clause Also note that the braces are OPTIONAL when there is a SINGLE statement inside a particular if or else block (still recommended though!) . REQUIRED when there is more than one statement inside a particular if or else block After making these changes, one more thing: change the lines that give the output so they look like the ones shown below Report for animals01.txt: Animal count: 3 Duck count: Non duck count: 1 Report for animals02.txt: Animal count:9 Duck count: Non duck count: 3 It is IMPORTANT to be EXACT since the autograder system will compare your output with the expected output character-by-character. The spacing MATTERS! You can add extra spaces at the beginning and end of the string literals for " Animal count: "and" Duck count: "so that the spacing comes out right and matches the expected output. I'm not going to tell you how many; you'll have to figure that out. Note that we will also test your program on other input files, so you should too. Use the cp command to copy animals02.txt to animals03.txt and add some ducks and some other animals (note that you can use Vim's yy and p or P commands to copy/yank and paste lines). Count by hand, and make sure that the count when you run your program matches what is expected. When you are satisfied that the count is correct and that format of the output is precise, you are ready to submit your code for grading. duck 2 duck 3 goose 1 "animals01.txt" 3L, 16C 1 duck 2 duck 3 goose 4 duck 5 duck 6 COW 7 duck 8 duck 9 dog "animals02.txt" 9L, 44C

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

Step: 3

blur-text-image

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

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

Students also viewed these Databases questions

Question

4. How does social marketing differ from commercial marketing?

Answered: 1 week ago

Question

6. Explain the power of labels.

Answered: 1 week ago

Question

5. Give examples of variations in contextual rules.

Answered: 1 week ago

Question

f. What stereotypes were reinforced in the commercials?

Answered: 1 week ago