ABSOLUTE C++ -TEXT
6th Edition
ISBN: 2810017515514
Author: SAVITCH
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 4, Problem 5PP
Write a
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
create a file in c++.
In this lab, you will replace the existing functions with more flexible ones, and you will add additional functions to perform modular tasks.
The "old" functions for displaying "hello", "goodbye", "invalid selection" and "invalid input" all do basically the same thing. They simply display a message to the user. Replace the old functions with a new function called displayMessage. The function should take a string argument, and display it.
void displayMessage(string); //prototype
The old function for displaying the menu would be more useful if it also returned the menu selection. Replace the old function with a new one called getMenuSelection that will return the menu selection as a char variable. Make sure to use the function result when you call it (assignment, display, use in expression, another function call, etc.).
char getMenuSelection(); //prototype
Wouldn't it be nice to check the menu selection for an invalid input? How about checking to see if the exit…
Change each one of these questions to now work using a function.  decide what the name of the function of each should be, how many parameters are required and what value needs to be returned. You’re no longer required to solve the problem - try to re-manage your code to be a function.
Write a program that uses input to prompt a user for their name and then welcomes
them.
Enter your name: Chuck
Hello Chuck
Some of the earliest computer games developed were Interactive Fiction games, in which the user’s environment is described in text, and the user makes choices using text commands. In this problem and the next one, we’ll be developing a very simple text-based adventure game. Every choice in this game will have exactly three options, so we can write a function that works for any of them.
Write a function selection(text, optionA, optionB, optionC), that takes in four string values. text is a string representing a prompt in a text adventure game, and optionA, optionB, and optionC are strings representing the three possible options.
The function should print out the text, and then print out the options (label them with A., B., and C.). Next, the input() function should be used to prompt the user to choose A, B, or C. Then the function should return (not print) the one character string that represents the user’s choice: 'A', 'B', or 'C'. If the user does not choose one of those…
Chapter 4 Solutions
ABSOLUTE C++ -TEXT
Ch. 4 - Write a program that converts from 24-hour...Ch. 4 - The area of an arbitrary triangle can be using the...Ch. 4 - Write a program that tells what coins to give out...Ch. 4 - Write a program that will read in a length in feet...Ch. 4 - Write a program like that of the previous exercise...Ch. 4 - (You should do the previous two programming...Ch. 4 - Write a program that will read a weight in pounds...Ch. 4 - Write a program like that of the previous exercise...Ch. 4 - (You should do the previous two programming...Ch. 4 - (You should do Programming Projects 4.6 and 4.9...
Ch. 4 - You are a contestant on a game show and have won a...Ch. 4 - In the land of Puzzlevania, Aaron, Bob, and...Ch. 4 - You would like to know how fast you can run in...Ch. 4 - Your time machine is capable of going forward in...Ch. 4 - Write a function named convertToLowestTerms that...Ch. 4 - Consider a text file named scores. txt that...Ch. 4 - Given the scores . txt file described in...Ch. 4 - Write a function named sort that takes three...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
True or False: An object of a superclass can access members declared in a subclass.
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Write a program to read in three nonnegative integers from the keyboard. Display the integers in increasing ord...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Which of the following activities require real-time processing? a. Printing mailing labels b. Playing a compute...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Determine the resultant internal normal force, shear force, and bending moment at point C in the beam.
Mechanics of Materials (10th Edition)
Assume a telephone signal travels through a cable at two-thirds the speed of light. How long does it take the s...
Electric Circuits. (11th Edition)
Use the following tables for your answers to questions 3.7 through 3.51 : PET_OWNER (OwnerID, OwnerLasst Name, ...
Database Concepts (8th Edition)
Knowledge Booster
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
- You are tasked with writing a small part of a museum's ticketing system. The museum calculates ticket prices using the following rules: $20.00 per admission. Children under 15 get a 50% discount. Seniors (60 years and older) get a 25% discount. Write a Python function that takes a list of customers' ages and returns the total cost for the group. Your function must match the docstring below. You do not need to include the docstring in your solution. '''Function -- get_ticket_costCalculates the cost of museum admission for a group.Parameter:group_ages -- A list of integers representing customer ages.Returns:The total cost for the group, a float. The return value is not rounded.''' Example get_ticket_cost([10, 39, 40]) returns 50.0arrow_forwardMust show it in Python: Please show step by step with comments. Please show it in simplest form. Input and Output must match with the Question Please go through the Question very carefully.arrow_forwardLook carefully at the code for your functions read_age and read_siblings. Can you see a pattern? Each of these functions prompts the user until they supply a valid integer, which is then returned. In fact, the only differences between the two functions are the prompt string for the user and a few variable names. When we find very similar blocks of code like this in a program, we should look for a single function that can do both tasks. So ... how can we generalise these functions into a single function that can be used (in two separate calls) to read both the age and the number of siblings while still printing a suitab prompt? Add a new function to your program called read_int(prompt) that takes a prompt string as input. It should use that string to prompt the user for a valid integer and then return it. Once you have done this, delete the functions read_age and read_siblings from your program and replace all calls to them with appropriate calls to you new read_int(prompt) function so…arrow_forward
- Over the years, people have created a few nicknames for me. One that sticks without me telling me to call me that name is "Denck." It works great with anyone whose name ends with an "er". We are going to create a function called "nickName" which takes in one parameter. This parameter stores the name you want to create the nickname for. If the name ends with an er, return the name with the er removed. If the name does not have an er then return the full name back to the program.arrow_forwardWrite a GO program that uses a struct that holds employee, hoursWorked, and payPerHour. Create two variables of type struct (2 employees) and write a function that calculates the two employees paychecks. You may hardcode values if you are using the web compiler. (Hardcode the values!)arrow_forward*DONOT USE CHATGPT, please put comments so i can understand. It’s a C language program with algorithm.arrow_forward
- Don't send me AI response and I don't need plagiarised answer. If I see plagiarism then I'll give you multiple times downvotes for sure.arrow_forwardChange this question to work using a function. decide what the name of the function of each should be, how many parameters are required and what value needs to be returned. You're no longer required to solve the problem - try to re-manage your code to be a function. Write a program that uses input to prompt a user for their name and then welcomes them. Enter your name: Chuck Hello Chuckarrow_forwardTask 2: The formula for the area, A, of a triangle with sides of length a, b, and c is V[s(s – a)(s – b)(s – c)] A = Where (a + b + c) s = Write, test, and execute a function that accepts the values of a, b, and c as parameters from a calling function, and then calculates the values of s and [s(s - a)(s - b)(s - c)]. If this quantity is positive, the function calculates A. If the quantity is negative, a, b, and c do not form a triangle, and the function should set A = -1. The value of A should be returned by the function. Test the function by passing various data to it and verifying the returned value.arrow_forward
- Write a C++ program to carry out the operations of a simple calculator that accepts whole numbers and decimals. • Your user must be able to use the calculator without having to restart cach time. • Also, include functions to: add, subtract, and convert vectors from complex form to polar form and vice versa. Include a function that displays a menu of options. All mathematical operators are to be included.arrow_forwardIN C Programming Language...THANKS The phone numbers of the companies are stored in the phones.txt. The area codes are missing in some of the phone numbers. (A phone number including area code is 10 characters). You will write a program to format phone numbers and add area code if necessary. At the end all the phone numbers will look like the following; (312) 4250204. Write the following functions; readFromFile that reads all the phone numbers from the file phones.txt into a string array. The function should return the number of phones. updateDirectory that takes the string array which keeps the phone numbers and the number of phones in the array as parameters, and updates the phone numbers adding the parentesis and area code (312) where necessary (i.e (312) 4250204). printDirectory that takes the string array which keeps the phone numbers and the number of phones in the array as parameters, and displays the number of phones and the phone list on the screen.arrow_forwardPython questionarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
What Are Data Types?; Author: Jabrils;https://www.youtube.com/watch?v=A37-3lflh8I;License: Standard YouTube License, CC-BY
Data Types; Author: CS50;https://www.youtube.com/watch?v=Fc9htmvVZ9U;License: Standard Youtube License