SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
I/o Streams As An Introduction To Objects And Classes
Exercise:
Programming Projects
Question:14 | ISBN:9780321531346 | Edition: 7

Question

This project is the same as Programming Project 13, except that in this

project your program will use a more sophisticated method for choosing

the answer to a question. When your program reads a question, it counts

the number of characters in the question and stores the number in a variable named count. It then responds with answer number count%ANSWERS.

The first answer in the file is answer number 0, the next is answer number

1, then 2, and so forth. ANSWERS is defined in a constant declaration, as

shown next, so that it is equal to the number of answers in the answer file:

const int ANSWERS = 8;

This way you can change the answer file so that it contains more or fewer

answers and you need change only the constant declaration to make your

program work correctly for a different number of possible answers.

Assume that the answer listed first in the file will always be the following,

even if the answer file is changed:

I'm not sure, but I think you will find the answer in Chapter #N.

That's a good question.

If I were you, I would not worry about such things.

That question has puzzled philosophers for centuries.

I don't know. I'm just a machine.

Think about it and the answer will come to you.

I used to know the answer to that question, but I've forgotten it.

The answer can be found in a secret place in the woods.

I'm not sure, but I think you will find the answer in Chapter #N

When replacing the two characters #N with a number, use the number

(count%NUMBER_OF_ CHAPTERS + 1), where count is the variable discussed

above, and NUMBER_OF_CHAPTERS is a global named constant defined to be

equal to the number of chapters in this book.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.