LAB 6.2 Introduction to Pass by Value Retrieve program newproverb.cpp from the Lab 6.1 folder. The code is as follows: // This program will allow the user to input from the keyboard // whether the last word to the following proverb should be party or country: // "Now is the time for all good men to come to the aid of their ___" // Inputting a 1 will use the word party. Any other number will use the word country.   // PLACE YOUR NAME HERE   #include #include using namespace std;   // Fill in the prototype of the function writeProverb.   int main() { int wordCode;   cout << "Given the phrase:" << endl; cout << "Now is the time for all good men to come to the aid of their ___" << endl;   cout << "Input a 1 if you want the sentence to be finished with party" << endl; cout << "Input any other number for the word country" << endl;   cout << "Please input your choice now" << endl; cin >> wordCode;  cout << endl;   writeProverb(wordCode);   return 0; }   // ****************************************************************************** // writeProverb // // task:   This function prints a proverb. The function takes a number //           from the call. If that number is a 1 it prints "Now is the time //           for all good men to come to the aid of their party." //           Otherwise, it prints "Now is the time for all good men //           to come to the aid of their country." // data in:  code for ending word of proverb (integer) // data out: no actual parameter altered // // *****************************************************************************   void writeProverb(int number) { // Fill in the body of the function to accomplish what is described above }   Exercise 1: Some people know this proverb as “Now is the time for all good men to come to the aid of their country” while others heard it as “Now is the time for all good men to come to the aid of their party.” This program will allow the user to choose which way they want it printed. Fill in the blanks of the program to accomplish what is described in the program comments. What happens if you inadvertently enter a float such as -3.97? Exercise 2: Change the program so that an input of 1 from the user will print “party” at the end, a 2 will print “country” and any other number will be invalid so that the user will need to enter a new choice. sample run: Given the phrase: Now is the time for all good men to come to the aid of their___ input a 1 if you want the sentence to be finished with party input a 2 if you want the sentence to be finished with county please input your choice now 4 i'm sorry but that is an incorrect choice; Please input a 1 or 2 2 Now is the time for all good men to come to the aid of their country Exercise 3: Change the previous program so the user may input the word to end the phrase. The string holding the user’s input word will be passed to the proverb function instead of passing a number to it. Notice that this change requires you to change the proverb function heading and the prototype as well as the call to the function. Sample Run: Given the phrase: Now is the time for all good men to come to the aid of their Please input the word you would like to have finish the proverb family Now is the time for all good men to come to the aid of their family

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter3: Input/output
Section: Chapter Questions
Problem 4PE: 4. During each summer, John and Jessica grow vegetables in their backyard and buy seeds and...
icon
Related questions
Question

LAB 6.2 Introduction to Pass by Value

Retrieve program newproverb.cpp from the Lab 6.1 folder. The code is as follows:

// This program will allow the user to input from the keyboard

// whether the last word to the following proverb should be party or country:

// "Now is the time for all good men to come to the aid of their ___"

// Inputting a 1 will use the word party. Any other number will use the word country.

 

// PLACE YOUR NAME HERE

 

#include <iostream>

#include <string>

using namespace std;

 

// Fill in the prototype of the function writeProverb.

 

int main()

{

int wordCode;

 

cout << "Given the phrase:" << endl;

cout << "Now is the time for all good men to come to the aid of their ___"

<< endl;

 

cout << "Input a 1 if you want the sentence to be finished with party"

<< endl;

cout << "Input any other number for the word country" << endl;

 

cout << "Please input your choice now" << endl;

cin >> wordCode; 

cout << endl;

 

writeProverb(wordCode);

 

return 0;

}

 

// ******************************************************************************

// writeProverb

//

// task:   This function prints a proverb. The function takes a number

//           from the call. If that number is a 1 it prints "Now is the time

//           for all good men to come to the aid of their party."

//           Otherwise, it prints "Now is the time for all good men

//           to come to the aid of their country."

// data in:  code for ending word of proverb (integer)

// data out: no actual parameter altered

//

// *****************************************************************************

 

void writeProverb(int number)

{

// Fill in the body of the function to accomplish what is described above

}

 

Exercise 1: Some people know this proverb as “Now is the time for all good
men to come to the aid of their country” while others heard it as “Now is
the time for all good men to come to the aid of their party.” This program
will allow the user to choose which way they want it printed. Fill in the
blanks of the program to accomplish what is described in the program
comments. What happens if you inadvertently enter a float such as -3.97?


Exercise 2: Change the program so that an input of 1 from the user will print
“party” at the end, a 2 will print “country” and any other number will be
invalid so that the user will need to enter a new choice.

sample run:

Given the phrase:

Now is the time for all good men to come to the aid of their___

input a 1 if you want the sentence to be finished with party

input a 2 if you want the sentence to be finished with county

please input your choice now

4

i'm sorry but that is an incorrect choice; Please input a 1 or 2

2

Now is the time for all good men to come to the aid of their country

Exercise 3: Change the previous program so the user may input the word to
end the phrase. The string holding the user’s input word will be passed to the
proverb function instead of passing a number to it. Notice that this change
requires you to change the proverb function heading and the prototype as
well as the call to the function.

Sample Run:
Given the phrase:
Now is the time for all good men to come to the aid of their
Please input the word you would like to have finish the proverb
family
Now is the time for all good men to come to the aid of their family

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Types of Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning