Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1 (10 points): Handling input to functions In this exercise, your will write a function called greedPerson that takes in as input 2 arguments:

Exercise 1 (10 points): Handling input to functions In this exercise, your will write a function called greedPerson that takes in as input 2 arguments: 1. A persons first name as a string 2. Their age as an integer Implement the code for this function such that it will print out the following given then provided input arguments: Hi personName you are looking like a very adult age year old For reference, in python, this code would look something like the following: def greetPerson(firstName, age): print("Hi", firstName, "you are looking like a very adult", age, "year old!") greetPerson("Lily", 7) greetPerson("Brutus", 58) You are, of course, to do this in C++. Define your function above the main function and then call it at least twice from within the main function. Compile and run your program to ensure that it works.

Exercise 2 (10 points): Handling input to functions (plus, plus!) In this exercise, your will write a program in C++ that prints the lyrics of the classic song Old Mac Donald Had a Farm to the screen. For those that havent had the pleasure of hearing/singing this song before, the lyrics are as follows: Old MacDonald had a farm, E-I-E-I-O And on that farm he had a [animal name], E-I-E-I-O With a [animal noise], [animal noise] here and a [animal noise], [animal noise] there Here a [animal noise], there a [animal noise], everywhere a [animal noise], [animal noise] Old MacDonald had a farm, E-I-E-I-O For example, when singing about a cow, the lyrics could be the following: Old MacDonald had a farm, E-I-E-I-O And on that farm he had a cow, E-I-E-I-O With a moo, moo here and a moo, moo there Here a moo, there a moo, everywhere a moo, moo Old MacDonald had a farm, E-I-E-I-O For this exercise, you will write a function called singVerse that takes as input two strings (first animalName and second animalNoise) that it will use to automatically fill in the blanks for the song and print the resulting verse to the screen. Once you have written the singVerse function, call it three separate times from within your main function by passing in different animal names and noises of your choosing. Compile and run your program to ensure that it works

Exercise 3 (10 points): Conditional Statements Lets suppose that youve got some noisy neighbors and you need to write a program that helps you determine if theyre being too loud too late. Create a function called checkNoisePollution that takes in two input variables. The first will be an integer (int loudness) that represents how loud the neighbors are (on a scale of 0 to 100). The second input variable will be an integer (int hour) that denotes the current time on a 24-hour clock (we will just keep track of the hour and not the minutes). If the values inform you that the neighbors are being too loud too late at night, your function should return the string Quiet down or Ill call the cops!. Otherwise your function should return the string Oh, theyre just kids being kids. If its currently the daytime (from 8am up to but not including 8pm that is, from 8 and up to but not including 20 on a 24-hour clock) then youll know that the neighbors are being too loud if their loudness is represented as a value that is greater than 90. If its night-time (from 8pm up to but not including 8am that is, 20 and up to but not including 8 on a 24-hour clock) then the neighbors will only be too loud if their loudness is represented as a value that is greater than 65. As an example, calling the function with the following input parameters: cout << checkNoisePollution(50, 18) << endl; cout << checkNoisePollution(20, 3) << endl; cout << checkNoisePollution(95, 14) << endl; cout << checkNoisePollution(80, 10) << endl; cout << checkNoisePollution(80, 20) << endl; should result in the following being printed to the screen: Oh, theyre just kids being kids. Oh, theyre just kids being kids. Quiet down or Ill call the cops! Oh, theyre just kids being kids. Quiet down or Ill call the cops!

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions