Concept explainers
Give the function definition for the function with the following function
declaration. Embed your definition in a suitable test
void getDouble(double& inputNumber); //Postcondition: inputNumber is given a value //that the user approves of. |
You can assume that the user types in the input in normal everyday notation, such as 23.789, and does not use e-notation to type in the number. Model your definition after the definition of the function getInt given in Display 8.3 so that your function reads the input as characters, edits the string of characters, and converts the resulting string to a number of type double. You will need to define a function like readAndClean that is more sophisticated than the one in Display 8.2, since it must cope with the decimal point. This is a fairly easy project. For a more difficult project, allow the user to enter the number in either the normal everyday notation, as discussed above, or in e-notation. Your function should decide whether or not the input is in e-notation by reading the input, not by asking the user whether she or he will use e-notation
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Database Concepts (8th Edition)
C How to Program (8th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- Modify the program so that it does the following: Performs a function that gets the area of a rectangle. The function must receive two parameters (decimal numbers) that represent the base and height of the rectangle and must return the calculated value (decimal number). Perform a second function that obtains the total area of a rectangular prism with a rectangular base. The total area of such a prism is equal to the sum of the areas of each of its faces. It uses calls to the previous function for this calculation. Call this last function in the main with user data. Execution example Give me the base: 21.3 Give me the height: 10 Give me the depth: 2.0 The total area of the prism is: 551.2arrow_forwardIn this project, you should design a Date class and use it to create a calendar application that has many features. You are not limited to the features included in these instructions, feel free to add any other components you find useful. Note: A normal year has 365 days. A leap year has 366 days (the extra day is February 29). In this project, you must take this fact into account. The rules that determine leap years are provided later in these instructions. Design the Date class, to be used in your application, containing: A private data member month of type integer that holds the date's month. A private data member day of type integer that holds the date's day. A private data member year of type integer that holds the date’s year. A default constructor that sets the date to January 1, 1753. Accessors for each member variable. Mutators for each member variable. A member function that prints on the screen a date in the form mm / dd / yyyy. A member function that returns the day name of…arrow_forwardWrite the definition of a void function that takes as input two parameters of type int, say sum and testScore the function updates the value of sum by adding the value of testScore. The new value of sum is reflected in the calling environment.arrow_forward
- Fix an error and show it please? And here are the information about the homework and for the error too. def kwargs_to_args_decorator(*args, **kwargs): This question is meant to test your knowledge of creating a decorator that accepts an arbitrary number of positional and keyword arguments, to decorate a function that accepts an arbitrary number of positional and keyword arguments, and alters the arguments before passing them to the decorated function. When the decorated function is invoked, this decorator should modify the arguments the decorated function receives. This decorator should filter out all positional arguments passed to the decorated function, which are found in the positional arguments passed to the decorator when the decorator was initialized. It should also filter out all keyword arguments with keys that are found in the keyword arguments given to the decorator when the decorator was initialized. After performing the modifications to the arguments, the decorator should…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_forwardIn this problem, you will write a solution to the Fizz Buzz problem (description to follow) within the body of the function FizzBuzz. I understand that we haven't discussed functions in detail yet. What you need to know is that our auto-grader will invoke your implementation (the code within the function body) with an integer value to initialize the parameter int n. You will write your definition of Fizz Buzz between the curly braces and with respect to the value stored in the parameter n. Your function will return a string literal based on the value of n: • The string literal Fizz (return "Fizz" ;) if n is divisible by 3 • The string literal Buzz if n is divisible by 5 • The string literal FizzBuzz if n is divisible by 3 and 5 • The n encoded as a string (return std::to_string(n);) if n is not divisible by 3 and/or 5 Hint: the modulus operator will likely prove useful in this problem.arrow_forward
- Consider the function definition: void Demo (int intVal, float& floatVal ) { intVal = intVal * 2; floatVal = float(intVal) + 3.5; } a. Suppose that the caller has variables int myInt and float myFloat whose values are 20 and 4.8, respectively. What are the values of myInt and myFloat after return from the following function call? Demo(myInt, myFloat); myInt: myFloat: b. Also, describe what happens in MEMORY when the Demo function is called. Think about the by reference and by value parameters.arrow_forwardHelp.arrow_forwardWrite a value returning function called HasPair. This function accepts three double parameters and checks whether ANY two of the three parameters are equal. If any two parameters are equal, the function returns true; otherwise the function returns false. 2. Write a valueinteger numberthe number isreturns false.A prime numberany reminder, i.e. divisible by itself and 1 only. returning function called isPrime. This function accepts as parameter and checks whether it is prime or not. If prime the function returns true. Otherwise, function is the number that can be divided by itself and 1 withoutarrow_forward
- 6. Write a void function, called "intDiv", that takes two integers n and m, and returns as reference parameters the factor (how many times m goes to n) and modulus (remainder n%m) without using the C++ operators for division (/) and modulus (8). Γράψτε μια void συνάρτη η, που ονομάζεται "intDiv", που παίρνει δύο ακέραιους αριθμούς η και m , και επιστρέφει ως παραμέτρους αναφοράς τον παράγοντα (πόσες φορές το m πηγαίνει στο n) και το υπόλοιπο (n% m ) χωρίς τη χρήση των τελεστν C++ για διαίρεση ( /) και υπόλοιπο (%). For example, if n = 13 and m= 5, then factor = 2 and modulus = 3. Hint: use repeated additions / subtractions. χρησιμοποιή στε επαναλαμβανό μενες προσθήκες / αφαιρέσεις .arrow_forwardWrite a function named product that takes two int parameters and returns the product of those two integers. Here is an example: int n = product(7, 5); // n is 35 We are providing a test framework that, if you wish, you may use with a compiler to test your function. What you will submit as your answer to this problem is only the product function. Do not submit things like the #include lines or a main routine. If we take the code you write in the space below and insert it into the program, the resulting program must build without compilation errors (mere warnings are allowed). You do not need to write comments in the code; we will not look at any comments. Here is the test framework that you may copy and paste into a C++ source file. For your own testing purposes, you might add additional tests in the main routine, although you won't be turning them in, of course. #include <iostream> #include <cassert> using namespace std; // SUBMIT AS YOUR ANSWER ONLY THE CODE BETWEEN THIS…arrow_forwardJS In this challenge, you must verify the equality of two different values given the parameters a and b. Both the value and type of the parameters need to be equal. The possible types of the given parameters are: What have you learned so far that will permit you to do two different checks (value and type) with a single statement? Implement a function that returns true if the parameters are equal, and false if they are not. Examples checkEquality(1, true) → false // A number and a boolean: the value and type are different. checkEquality(0, "0") → false // A number and a string: the type is different.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning