C++ - Combine code from binary converter (Program1) and string reverser (Program2) into one to print binary in the correct order. Add an additional loop to continue to accept input and display the binary result until a negative number is entered. You may assume that the input will be a series of non-zero integers. Program1 #include using namespace std; int main() { int ger; cin >> ger; while (ger > 0) { cout << ger % 2; ger = ger / 2; } cout << endl; return 0; }   Program2 #include #include using namespace std; int main() { const int MAX_STRINGS = 1000; string inputStrings[MAX_STRINGS]; int count = 0; string line; getline(cin, line); while (!line.compare("Quit") == 0 && !line.compare("quit") == 0 && !line.compare("q") == 0 && count < MAX_STRINGS) { inputStrings[count] = line; count++; getline(cin, line); } for (int i = 0; i < count; i++) { line = inputStrings[i]; for (int j = line.length() - 1; j >= 0; j--) { cout << line[j]; } cout << endl; } return 0; }

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section4.3: Nested If Statements
Problem 7E
icon
Related questions
Question

C++ - Combine code from binary converter (Program1) and string reverser (Program2) into one to print binary in the correct order. Add an additional loop to continue to accept input and display the binary result until a negative number is entered. You may assume that the input will be a series of non-zero integers.

Program1

#include <iostream>
using namespace std;

int main() {

int ger;

cin >> ger;

while (ger > 0) {
cout << ger % 2;
ger = ger / 2;
}

cout << endl;
return 0;
}

 

Program2

#include <iostream>
#include <string>
using namespace std;

int main()
{
const int MAX_STRINGS = 1000;

string inputStrings[MAX_STRINGS];

int count = 0;
string line;

getline(cin, line);

while (!line.compare("Quit") == 0
&& !line.compare("quit") == 0
&& !line.compare("q") == 0
&& count < MAX_STRINGS)
{
inputStrings[count] = line;

count++;

getline(cin, line);
}

for (int i = 0; i < count; i++)
{
line = inputStrings[i];

for (int j = line.length() - 1; j >= 0; j--)
{
cout << line[j];
}
cout << endl;
}

return 0;
}

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning