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
Vector Mechanics For Engineers
Management Information Systems: Managing The Digital Firm (16th Edition)
BASIC BIOMECHANICS
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Electric Circuits. (11th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- USE C++programming languagearrow_forwardTo make a function return more than one result we pass parameters: By value. As int. By void. By reference.arrow_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_forward
- NEED HELP WITH THIS import random print(random.randint(1,6)) #prints a number between 1 and 6. #or: x = random.randint(1,6) print(x) #prints a number between 1 and 6. write a python program that simulates a game with two dice roll based on their sum and value. Your program should: Define a function try_your_luck(dice1, dice2) that takes two arguments i.e., the numbers generated by randint() function (use randint twice). The random numbers should be passed to the function as argument The player wins some money, when: a. Sum of both dice is divisible by three, player wins $5 b. Same number on both die, player wins $10 c. For all other cases, print "try again" Player loses the game, when: a. Sum is greater than 10 and odd b. Sum is 7. Display an appropriate message for each case (player wins or loses).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_forwardMark the following statements as true or false:arrow_forward
- Explain why it's okay for a function to have side effects on sometimes.arrow_forwardConsider the function definition below. Assume x = 5, y = 3 and j = 8 as the function starts. Which variables will change after the function finishes? void findout (int &x, int y, int &j) { for (int i = 1; i 5) { x = 2*x - 3*y; y = 4 + 3 x; } else { Oi y = 2*x - 3; x = 4 + 3% y; } } // end of for loop x and y y All three since the first and last are references. x and jarrow_forwardWrite the functions with the following headers:# Return the reversal of an integer, e.g. reverse(456) returns# 654def reverse(number):# Return true if number is a palindromedef isPalindrome(number): Use the reverse function to implement isPalindrome. A number is a palindrome if its reversal is the same as itself. Write a test program that prompts the user to enter an integer and reports whether the integer is a palindrome.arrow_forward
- Write a function which takes two integer parameters for values to be added together and returns the result by value. The function may not print anything or read anything directly from the user (i.e. no cin/cout in the function). Assume that the values passed to the function will not be negative, but could be 0 or positive, and will both be integers. The function must implement addition recursively, and cannot use the standalone + operator (only ++) or call any other functions.arrow_forwardFind any errors in the following function definition: void fun (int x, int y) int z; return z; } // funarrow_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
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning