Question

In: Computer Science

Explain your code with comments. Solve in C++. 1. Write a str2int() function that convers a...

Explain your code with comments. Solve in C++.
1. Write a str2int() function that convers a string to integer. The function will take the number as a string then will return it as integer. E.g. str2int(“123”) will return 123 str2int(“005”) will return 5 str2int(“102”) will return 102

Solutions

Expert Solution

Here is the solution of your question

here is the code

#include <iostream>
using namespace std;
//include string library to use string function
#include<string>
//function defination of str2int
int str2int(string s)
{ //stoi function is used to convert a string into int
return stoi(s);
}
int main()
{ //function calling
cout<<stoi("123")<<"\n";
cout<<stoi("005")<<"\n";
cout<<stoi("102")<<"\n";

return 0;
}


Related Solutions

In python and comments your code : Exercise 1 1.Write a function waiting for two matrices...
In python and comments your code : Exercise 1 1.Write a function waiting for two matrices and returning their addition, −1 if it is not not possible. 2. Write a function associated with a matrix and a scalar and returning the produced matrix. 3. Write a function accompanying an n × m matrix and a vector n and returning the vector produced by each other, −1 if this is not possible. 4. Write a function accompanying two n × m...
Please solve this problem, in c++ (algoritms) write code and explaination how to solve it! 1)...
Please solve this problem, in c++ (algoritms) write code and explaination how to solve it! 1) N numbers are given. The first K of them are sorted in ascending order, the remaining NK are also sorted in ascending order. Sort numbers in ascending order in O (N). Input data format N - number of numbers, K - number of numbers in the first half (sorted). Example input 10 6 1 2 5 6 8 9 3 4 7 12 Sample...
Understand the code and explain the code and answer the questions. Type your answers as comments....
Understand the code and explain the code and answer the questions. Type your answers as comments. #include #include using namespace std; // what is Color_Size and why it is at the end? enum Color {        Red, Yellow, Green, Color_Size }; // what is Node *next and why it is there? struct Node {        Color color;        Node *next; }; // explain the code below void addNode(Node* &first, Node* &last, const Color &c) {        if (first == NULL)...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment,...
Source code with comments explaining your code in C# Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random number between 0 and the...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an...
**Add comments to existing ARM code to explain steps** Question that my code answers: Write an ARM assembly program to calculate the value of the following function: f(y) = 3y^2 – 2y + 10 when y = 3. My Code below, that needs comments added: FunSolve.s LDR R6,=y LDR R1,[R6] MOV R2,#5 MOV R3,#6 MUL R4,R1,R1 MUL R4,R4,R2 MUL R5,R1,R3 SUB R4,R4,R5 ADD R4,R4,#8 st B st y DCD 3
1. Write code in mips that will play battleships. Include comments in code on what each...
1. Write code in mips that will play battleships. Include comments in code on what each part is doing.
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
Write code in C please. #1 Write a function multiples() which will take an integer input...
Write code in C please. #1 Write a function multiples() which will take an integer input and it will print out all the multiples of this number starting from 2 but not including itself. For example, multiples(10) will print 2, 5 and multiples(100) will print 2, 4, 5, 10, 20, 25, 50 #2 Write and test a Fibonacci() function that uses a loop instead of recursion to calculate Fibonacci numbers.
C++ Write the C++ code for a void function that prompts the user to enter a...
C++ Write the C++ code for a void function that prompts the user to enter a name, and then stores the user's response in the string variable whose address is passed to the function. Name the function getName.
*Code in C* Write a function that checks if a number is a perfect cube. Write...
*Code in C* Write a function that checks if a number is a perfect cube. Write another function that calculates the integer cubic root. Under the main program: Prompt the user to input a number Tell the user if the number is a perfect cube or not Print the cubic root if the inputted number is a perfect cube.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT