Concept explainers
“atof” function:
In C++, the predefined function “atof” is used to convert a string value into a double-precision floating point value; it passes a string literal or character array as an argument and it converts the received value into a double type value; it takes only one parameter as an argument.
- If the argument value contains nonconvertible contents combined with the integer value then the values will be ignored while converting.
- In same way, the function will return “0” when the values can’t be able to convert into double data type.
Syntax:
Syntax for the “atof” function is as follows:
double atof (const char* n);
In the above statement,
- “double” represents the return type of the function.
- “atof” represents the name of the function.
- “const char*” represents the data type of the passing argument.
- “n” is a string variable which is required to be converted.
Example:
The example for the “atof” function is as follows:
//change the string literal to a double value.
double n = atof ("1258.11E-14 ");
In the above line, the string literal “1258.11E-14” is passed as an argument to “atof” and it returns the converted value that is “1.25811e-11”.
Trending nowThis is a popular solution!
Chapter 10 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
- Option #1: String Values in Reverse Order Assignment Instructions Write a Python function that will accept as input three string values from a user. The method will return to the user a concatenation of the string values in reverse order. The function is to be called from the main method. In the main method, prompt the user for the three strings.arrow_forward99.arrow_forwardWrite the countVowels function which counts the number of vowels using the string class as follows: int countVowels(const string& s) Write a test program that prompts the user to enter a string, invokes the countVowels function and displays the total number of vowels in the string.arrow_forward
- When I try another flight number besides the first one it returns invalid and why arent my set(1) spacing out correctly #include #include #include #include #include #include using namespace std; int main(){ string usern; //Declare string Usern string passwrd; //Declare string passwrd string _usern; //Declare string Usern string _passwrd; //Declare string passwrd string _fname; string _lname; string _time; string _destination; int ffn; //Declare ffn integer int seats; int flightno; //Declare flightno integer int _ffn; int _flightno; //Declare flightno integer int _total_seats; int _seats_available; double _price; double total; //Declare total variable int attemptCount = 0; string line = " "; bool match_found = 0 ; //variable which hold 1 if match found ifstream readFile1("accounts.dat"); ifstream readFile2("flights.dat"); bool match_found2 = 0; while(getline(readFile2,line)) { //read file line by line till end of file stringstream iss(line); iss >> _flightno >>…arrow_forwardCreate aC++ function named countWords that counts the number of words in the current string and displays a message stating how many words are in the string Examples: The string 2015 has zero words The string "Hello World" has two words The string " I am Woman " has 3 wordsarrow_forward#include #include #include #include using namespace std; int main (){ const double PI = 3.14159265359; return 0; }arrow_forward
- Problem: Feed Nibble Monster Till Full Write a program that generates a number in [0, 500] at the beginning -- this corresponds to how hungry the monster is -- and keeps asking the user to feed the monster until that number falls to zero. Each time the user feeds the monster a nibble, hunger decreases by the decimal value of the character (i.e. if the user feeds 'A' hunger decreases by 65). But when the user feeds the monster some character that isn't a nibble, the hunger increases by the decimal value of the character (since puking depletes energy). Use while loop. Sample runs: Notice the loop exits after one iteration, because hunger was very low and one nibble made the monster full: Notice hunger increasing after non-nibble (pink highlight): Notice that the program just keeps going when the user feeds the monster only non-nibbles. Do you think the program will keep running forever if the user never gives the monster nibbles?arrow_forward. COMPLETE THE CODES.arrow_forward1. This program reads one number, as a string, and assign it to String getData Increment and display getData as integer and double Only strings are to be read 2. This program reads strings only Read ten digits, such as 2345678923 store them in getData, which is a string Display each value and it position in the stringarrow_forward
- Given the following code: long int data = {5, 7, 9, 1}; long int* ptr = nullptr; Write a statement that sets ptr to point to the number 9.arrow_forwardAllowed libraries:arrow_forwardWhat is the difference between these two statements? void showValues(int num)void showValues(int nums[], int size).arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education