Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
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
Python code
Screenshot and output is must
Chapter 4 Solutions
Absolute C++
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
Class B extends class A. (Class A is the superclass and class B is the subclass.) Describe the order in which t...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
What is the biggest difference between a parameter of a primitive type and a parameter of a class type?
Java: An Introduction to Problem Solving and Programming (8th Edition)
What is a Java applet?
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
When a parameter is changed, does this affect the argument that was passed into the parameter?
Starting Out with Python (3rd Edition)
A(n) ____ method gets a value from a class's field but does not change it. a. retriever b. constructor c. mutat...
Starting Out with Programming Logic and Design (4th Edition)
Write a program to generate personalized junk mail. The program takes input both from an input file and from th...
Problem Solving with C++ (10th 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
- 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…arrow_forward#include #include #include #include using namespace std; // four function declarations int main() { int id nullptr; string* name = nullptr; int* score = nullptr; char filename [20]; cout> filename; int count = readDataFromFile(filename, &id, &name, &score); cout << "count : " << count << endl; printData(id, name, score, count); int max; findMax (score, &max, count); printMaxList (id, name, score, count, max); return 0; Enter filename: student. txt Students List 108927 101981 102888 100738 100892 102893 109189 107182 106627 102930 108992 109281 104244 105566 102871 107889 Alice 80 Paul 92 86 70 Ruth 89 John 91 Tammy 95 Jenny 72 Amy 95 77 71 Cindy Robert Brian Hailey Jake 88 69 95 Sandy Chris Angel 82 Sue 93 *** Max score : 95 Students with max score 109189 95 } 106627 95 // four function definitions (readDataFromFile, printData, findMax, printMaxList) 105566 Chris 95 Tammy Amyarrow_forwardYou 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_forward
- 4. Be able to write a simple user defined function that you can call and use in another program with a simple formula and some plotting. (i.e. like the kinetic energy example or the other example done in class) Write both the program and the function and show that it works.arrow_forwardComplete the process_name() function that takes a single string parameter name. You can assume that the name will always be in the format first name surname with a single space character between the first name and the surname. The function returns a string consisting of the first letter of the first name followed by the first three letters of the surname. All of the characters in the returned string should be in lowercase. Some examples of the function being used are shown below: For example: Test Result print(process_name("Damir Azhar")) dazh print(process_name("Ann Cameron")) acam Answer: (penalty regime: 0 %) Reset answer 1v def process_name (name): 2arrow_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_forwardYou are given a list of tasks to complete, along with their prerequisites. Write a function to determine if it is possible to complete all tasks, and if so, what order they should be completed in.arrow_forward
- Python Programming ONLY. Please use simple code, and avoid using classes. Provide explanation as well. Thank you. Write a program that keeps track of running piggybank deposits. The program should receive input from a user that will enter the amount to deposit into the piggybank. Use a function, add, which takes an argument number from the user input and adds it to a global sum variable. After the 5th deposit, print out the running total thus far.arrow_forwardDon'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_forwardHelp.arrow_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