At Westonci.ca, we make it easy for you to get the answers you need from a community of knowledgeable individuals. Join our platform to connect with experts ready to provide detailed answers to your questions in various areas. Join our platform to connect with experts ready to provide precise answers to your questions in different areas.

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.

We appreciate your visit. Our platform is always here to offer accurate and reliable answers. Return anytime. We appreciate your time. Please come back anytime for the latest information and answers to your questions. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.