At Westonci.ca, we connect you with experts who provide detailed answers to your most pressing questions. Start exploring now! Get immediate and reliable solutions to your questions from a community of experienced experts on our Q&A platform. Explore comprehensive solutions to your questions from knowledgeable professionals across various fields on our platform.

Can someone help me out I don't understand how to do this problem at all
---------------------------------------------------------------------------------------------------------------------------
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is:

As long as x is greater than 0
Output x % 2 (remainder is either 0 or 1)
x = x / 2

Your program must define and call the following two functions. The IntegerToReverseBinary() function should return a string of 1's and 0's representing the integer in binary (in reverse). The ReverseString() function should return a string representing the input string in reverse.

string IntegerToReverseBinary(int integerValue)
string ReverseString(string userString)
----------------------------------------------------------------------------------------------------------------------------
here is the general format it gave:

#include
using namespace std;

/* Define your functions here */

int main() {
/* Type your code here. Your code must call the functions. */

return 0;
}

Sagot :

tonb

Answer:

#include <bits/stdc++.h>

#include <string>  

using namespace std;

string IntegerToReverseBinary(int integerValue)

{

 string result;

 while(integerValue > 0) {

   result += to_string(integerValue % 2);

   integerValue /= 2;

 }

 return result;

}

string ReverseString(string userString)

{

 reverse(userString.begin(), userString.end());

 return userString;

}

int main() {

 string reverseBinary = IntegerToReverseBinary(123);

 string binary = ReverseString(reverseBinary);

 cout << binary << endl;

 return 0;

}

Explanation:

The string reverser uses a standard STL function. Of course you could always write your own, but typically relying on libraries is safer.

Thank you for visiting. Our goal is to provide the most accurate answers for all your informational needs. Come back soon. Thank you for visiting. Our goal is to provide the most accurate answers for all your informational needs. Come back soon. We're glad you chose Westonci.ca. Revisit us for updated answers from our knowledgeable team.