*** I need help identifying my incoming parameters, outgoing parameters, and return values in the C++ code below. There are 4 functions in the code below and the 3 fields for each function are bolded. Should one of the items not exist, put N/A. ****
#include
#include
using namespace std;
int input(long long); // function to Input of Base 2 value to
enforce the entry of only 1's and 0's
int input2(double);
int Base10toBase2(long long); // Base 10 to Base 2
int Base2toBase10(long long); //Base 2 to Base 10
int main()
{
long long n, o;
while (1)
{
cout << "Enter a positive integer in Base 10: ";
double x;
cin >> x;
if (input2(x))
{
n=x;
break;
}
else
{
cout << "Entered number is not a positive integer. Please try
again." << endl;
}
}
while (1)
{
cout << "Enter a binary number: ";
cin >> o;
if (input(o))
{
break;
}
else
{
cout << "Entered number is not a binary number. Please try
again." << endl;
}
}
cout << endl;
cout << n << " in decimal = " << Base10toBase2(n)
<< " in binary" << endl;
cout << o << " in binary = " << Base2toBase10(o)
<< " in decimal";
return 0;
}
//***********************************************
// Function Name: Base10toBase2
// Incoming Parameters:
// Outgoing Parameters:
// Return Value:
//***********************************************
int Base10toBase2(long long n)
{
long long BinaryNo = 0;
int remainder, i = 1;
while (n != 0)
{
remainder = n % 2;
n /= 2;
BinaryNo += remainder * i;
i *= 10;
}
return BinaryNo;
}
//***********************************************
// Function Name: Base2toBase10
// Incoming Parameters:
// Outgoing Parameters:
// Return Value:
//***********************************************
int Base2toBase10(long long o)
{
int DecimalNo = 0, i = 0, remainder;
while (o != 0)
{
remainder = o % 10;
o /= 10;
DecimalNo += remainder * pow(2, i);
++i;
}
return DecimalNo;
}
//***********************************************
// Function Name: input - input of Base 2 value to enforce the
entry of only 1’s and 0’s
// Incoming Parameters:
// Outgoing Parameters:
// Return Value:
//***********************************************
int input(long long num)
{
long long x;
while (num)
{
x = num % 10;
if ((x == 0) || (x == 1))
{
num = num / 10;
}
else
{
return 0;
}
}
return 1;
}
//***********************************************
// Function name: input2 - ensures the Base 10 number entered by
the user is a positive integer
// Incoming Parameters:
// Outgoing Parameters:
// Return Value:
//***********************************************
int input2(double x){
if(x<0)
return 0;
if(1000*x!=(1000*int(x)))
return 0;
return 1;
}
Answer:
Code:



Output:aw
Raw Code:
#include <iostream>
#include <math.h>
using namespace std;
int input(long long); // function to Input of Base 2 value to
enforce the entry of only 1's and 0's
int input2(double);
int Base10toBase2(long long); // Base 10 to Base 2
int Base2toBase10(long long); //Base 2 to Base 10
int main()
{
long long n, o;
while (1)
{
cout << "Enter a positive
integer in Base 10: "; // Taking input from user
double x;
cin >> x;
if (input2(x)) // Calling input2()
function with 'x' as parameter.
{
n=x;
break;
}
else
{
cout <<
"Entered number is not a positive integer. Please try again."
<< endl; // If the entered number is not a positive
number.
}
}
while (1)
{
cout << "Enter a binary
number: "; // Taking binary number from user
cin >> o;
if (input(o)) // Calling input()
function with 'o' as parameter.
{
break;
}
else
{
cout <<
"Entered number is not a binary number. Please try again." <<
endl; // if the entered number is not a binary number.
}
}
// Printing statements.
cout << endl;
cout << n << " in decimal = " <<
Base10toBase2(n) << " in binary" << endl;
cout << o << " in binary = " <<
Base2toBase10(o) << " in decimal";
return 0;
}
/*
Base10toBase2
Incoming Parameters: 'n' , long type number (nothing but taking
Decimal number)
Outgoing Parameters: N/A
Return Value: BinaryNo
*/
// This function takes the Decimal number as parameter and convert
that number to binary number.
int Base10toBase2(long long n)
{
long long BinaryNo = 0;
int remainder, i = 1;
while (n != 0)
{
remainder = n % 2;
n /= 2;
BinaryNo += remainder * i;
i *= 10;
}
return BinaryNo; // Returning binary number
}
/*
Base2toBase10
Incoming Parameters: 'o' , long type number (nothing but taking
Binary number)
Outgoing Parameters: N/A
Return Value: DecimalNo
*/
// This function takes the binary number as parameter and convert
that number to Decimal number.
int Base2toBase10(long long o)
{
int DecimalNo = 0, i = 0, remainder;
while (o != 0)
{
remainder = o % 10;
o /= 10;
DecimalNo += remainder * pow(2,
i);
++i;
}
return DecimalNo; // Returning decimal number
}
/*
input
Incoming Parameters: 'o' , long type number (nothing but taking
Binary number)
Outgoing Parameters: N/A
Return Value: 0 or 1
*/
// This function takes the long type number as a parameter and
checks the digits in that number.
// if the all digits in that number is '0' or '1' then it will
return '1' otherwise it will return '0'.
int input(long long num)
{
long long x;
while (num){
x = num % 10;
if ((x == 0) || (x == 1))
{
num = num /
10;
}
else
{
return 0;
}
}
return 1;
}
/* input2
Incoming Parameters: 'x' ,double type number (nothing but taking
Decimal number)
Outgoing Parameters: N/A
Return Value: 0 or 1 */
// This function takes the double type number as parameter and
check if the given number is positive or not.If it is negative then
it will return 0.
// Otherwise it will return 1.
int input2(double x){
if(x<0)
return 0;
if(1000*x!=(1000*int(x)))
return 0;
return 1;
}
If you have any doubts ask in comment section.
*** I need help identifying my incoming parameters, outgoing parameters, and return values in the C++...
C++ problem where should I do overflow part? in this code do not write a new code for me please /////////////////// // this program read two number from the user // and display the sum of the number #include <iostream> #include <string> using namespace std; const int MAX_DIGITS = 10; //10 digits void input_number(char num[MAX_DIGITS]); void output_number(char num[MAX_DIGITS]); void add(char num1[MAX_DIGITS], char num2[MAX_DIGITS], char result[MAX_DIGITS], int &base); int main() { // declare the array = {'0'} char num1[MAX_DIGITS] ={'0'}; char...
Help with C++ reverse program with leading zeros. I need to put the line from the function that display the zeros in main not in the function. So how can I move the display with leading zeros in main. Thanks. Here is my code. #include <iostream> #include <cstdlib> #include <iostream> using std::cout; using std::cin; using std::endl; //function templates int reverseNum(int); int main() { //variables char buf[100]; int num; while (true) { //prompt user for input cout << "Enter the number...
C++ Object Oriented assignment Can you please check the program written below if it has appropriately fulfilled the instructions provided below. Please do the necessary change that this program may need. I am expecting to get a full credit for this assignment so put your effort to correct and help the program have the most efficient algorithm within the scope of the instruction given. INSTRUCTIONS Create a fraction class and add your Name to the name fraction and use this...
When I input 210 or 110 or 340 it always returns 0 instead of 3 or 2 or 7. Why isn't it adding the sum of all the numbers? #include <iostream> using namespace std; int main() { long num; cout << "Input a number: "; cin >> num; int n = 0; while (num != 0) { n += num % 10; num = num / 10; } if (num...
Hello everyone! I am working on my assignment for C++ and I'm having a bit of trouble on the value producing functions, I am creating a program wherein I have to input a value and I need to create a function called square value where in it will square the value I have input. I cannot seem to figure out this part. Here is the code that I have so far, and thank you for any help. I greatly appreciate...
Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) { // average function , declaring variable int i; char str[40]; float avg = 0; // iterating in...
i need help determining the output for these problems For ( int count = 1; count < 30; count+=9) Cout << (3 + count) << “ “ ; ________________ int I = 1; While ( I <= 10) { If ( I > 5 && i ! = 9) Cout << ‘x’ ; I++; } ____________________ double a [3] = {1.1, 2.2, 3.3}; cout << a [0] << “ “ << a...
Can you fix this program and run an output for me. I'm using C++ #include using namespace std; //function to calculate number of unique digit in a number and retun it int countUniqueDigit(int input) { int uniqueDigitCount = 0; int storeDigit = 0; int digit = 0; while (input > 0) { digit = 1 << (input % 10); if (!(storeDigit & digit)) { storeDigit |= digit; ...
The following is a sample inventory in C++, i want to ask the user to input a item number for removing from inventory. //CPP #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> #define MAX 1000 using namespace std; //Function to Add a new inventory item to the data into the array in memory void addItem(string desc[],string idNum[], float prices[], int qty[],int &num) { cout<<"Enter the names:"; cin>>desc[num]; cout<<"Enter the item number:"; cin>>idNum[num]; cout<<"Enter the price of item:"; cin>>prices[num]; cout<<"Enter the...
I need this done in C++ Can someone help me get my code from crashing. The code compiles but it can be easily crashed with user input. The rubric and code below Instructions: Write a program that scores the following data about a soccer player in a structure: Player’s Name Player’s Number Points Scored by Player The program should keep an array of 12 of these structures. Each element is for a different player on a...