Eish guys am honesly don't know where to start, please help!
I have write the following set of c++ functions
fromBinaryToDecimal: The function must accept a pointer to a one-dimensional, dynamically allocated, Boolean array together with an integer representing its length as parameters. You may assume that the array represents a positive value. The function’s return value is an unsigned integer.
fromDecimalToBinary: The function receives an unsigned integer as a parameter and returns a string.
fromHexToBinary: The function receives a string as a parameter and returns a string. Your function must check to make sure that the incoming string represents a valid hexadecimal value.
fromBinaryToHex: The function must accept a pointer to a one-dimensional, dynamically allocated, Boolean array together with an integer representing its length as parameters. You may assume that the array represents a positive value. The function’s return value is a string.
Overloaded versions of the fromBinary* functions which accept a string parameter.
A main function in a separate cpp file which demonstrates the use of your functions via a menu system.
Instructions followed but i dont see anything happening as yet and i'd appreciate very much if i can get sum explanations there and there. Can we proceed to the next step please..
Please Galik i know i may sound stupid but please i nid ur help...i have 2mit this deadline please, it wil tac me tym to learn c++..this is a whole new world for me..please be wit me..thank u
There is nothing stupid about not knowing how to program in C++. But why should someone do your work for you because you haven't done it?
You need to try to answer those questions by yourself based on what you have already been taught. Then post your code here and we can help you where you make mistakes. No one here wants to just do your work for you so that you don't learn anything for yourself. You need to be studying C++ along side the questions you ask here. People are going to need to see some evidence of that.
fromBinaryToDecimal: The function must accept a pointer to a one-dimensional, dynamically allocated, Boolean array together with an integer representing its length as parameters. You may assume that the array represents a positive value. The function’s return value is an unsigned integer.
fromDecimalToBinary: The function receives an unsigned integer as a parameter and returns a string.
fromHexToBinary: The function receives a string as a parameter and returns a string. Your function must check to make sure that the incoming string represents a valid hexadecimal value.
fromBinaryToHex: The function must accept a pointer to a one-dimensional, dynamically allocated, Boolean array together with an integer representing its length as parameters. You may assume that the array represents a positive value. The function’s return value is a string.
Overloaded versions of the fromBinary* functions which accept a string parameter.
A main function in a separate cpp file which demonstrates the use of your functions via a menu system
here is my code so far:
#include <iostream>
using namespace std;
int BinaryToDecimal(char *bin)
{
int b, k, m, n;
int len, sum = 0;
len = strlen(bin) - 1;
for(k = 0; k <= len; k++)
{
n = (bin[k] - '0'); // char to numeric value
if ((n > 1) || (n < 0))
{
puts("\n\n ERROR! BINARY has only 1 and 0!\n");
return (0);
}
for(b = 1, m = len; m > k; m--)
{
// 1 2 4 8 16 32 64 ... place-values, reversed here
b *= 2;
}
// sum it up
sum = sum + n * b;
printf("%d*%d + ",n,b); // uncomment to show the way this works
}
return(sum);
}
/*int DecimalToBinary(char *dec)
{
int b, k, m, n;
int len, sum = 0;
len = strlen(dec) + 1;
for(k = 0; k >= len; k++)
{
n = (dec[k] + '0');
if((n < 1) || (n > 0))
{
puts("\n\n ERROR!");
return (0);
}
for(b = 1, m = len; m > k; m--)
{
b *= 2;
}
sum = sum - n / b;
printf("%d*%d + " , n , b);
}
return (sum);
}*/
int main()
{
char *Num;
int name;
cout << "Enter the binary number " << endl;
cin >> Num;
name = BinaryToDecimal(Num);
cout << endl;
Ok thanks and how can you correct me on this function?
int DecimalToBinary(char *dec)
{
int b, k, m, n;
int len, sum = 0;
len = strlen(dec) + 1;
for(k = 0; k >= len; k++)
{
n = (dec[k] + '0');
if((n < 1) || (n > 0))
{
puts("\n\n ERROR!");
return (0);
}
for(b = 1, m = len; m > k; m--)
{
b *= 2;
}
sum = sum - n / b;
printf("%d*%d + " , n , b);
}
return (sum);
}
Eish i'm not really sure on how to reverse it(fromDecimalToBinary)