#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
#include "EndOrderedLinkedList.cpp"
void ConvertNumber(int,int, EndOrderedList&);
//converts number to stack of characters in number base
void WriteNumber(ostream&, EndOrderedList&);
//writes the number and empties the list
int main()
{
EndOrderedList mystack;
ifstream dat3d;
ofstream out3d;
int p;
dat3d.open("F:\\dat3d.txt");
if(!dat3d)
{
cout<<"failure to open dat3d.txt"<<endl;
system("PAUSE");
return 1;
}
out3d.open("F:\\out3d.txt");
if(!out3d)
{
cout<<"failure to open out3d.txt"<<endl;
system("PAUSE");
return 1;
}
dat3d>>p;
while (dat3d)
{
ConvertNumber(2, p, mystack);
WriteNumber(out3d, mystack);
out3d<<endl;
ConvertNumber(16, p, mystack);
WriteNumber(out3d, mystack);
out3d<<endl;
ConvertNumber(8, p, mystack);
WriteNumber(out3d, mystack);
out3d<<endl;
system ("PAUSE");
dat3d>>p;
}
dat3d.close(); out3d.close();
system ("PAUSE");
return 0;
}
void ConvertNumber(int base,int n, EndOrderedList& mystack)
{ int i;
char r;
while (n>0)
{
i = n % base;
r = i + '0';
mystack.push(r);
n = n/base;
}
}
void WriteNumber(ostream& out3d, EndOrderedList& mystack)
{
while(mystack.isempty())
{
out3d<<mystack.top();
mystack.pop();
}
}
You're Browsing As A Guest! Register Now... |
||
|
Become a C++ Expert!
Join 416,733 C++ Programmers for FREE! Get instant access to thousands
of C++ experts, tutorials, code snippets, and more! There are 2,924 people online right now.Registration is fast and FREE... Join Now!
|
||
Page 1 of 1
one code to convert decimal to binary, hex, octal i tried the code (r=i+'0') but it doesn't do hexidecimal c
#1
one code to convert decimal to binary, hex, octal
Posted 23 July 2007 - 05:31 PM
#2
Re: one code to convert decimal to binary, hex, octal
Posted 23 July 2007 - 07:38 PM
Can you expand your post with "EndOrderedLinkedList.cpp".
I think it necessary to explain your problem. Because usually at the #include stuff file header (*.h) not other like (*.cpp).
Where you show error in your program ?
I think it necessary to explain your problem. Because usually at the #include stuff file header (*.h) not other like (*.cpp).
#include "EndOrderedLinkedList.cpp" //#include "EndOrderedLinkedList.h"
Where you show error in your program ?
#3
Re: one code to convert decimal to binary, hex, octal
Posted 23 July 2007 - 10:54 PM
imamkomc, on 23 Jul, 2007 - 08:38 PM, said:
Can you expand your post with "EndOrderedLinkedList.cpp".
I think it necessary to explain your problem. Because usually at the #include stuff file header (*.h) not other like (*.cpp).
Where you show error in your program ?
I think it necessary to explain your problem. Because usually at the #include stuff file header (*.h) not other like (*.cpp).
#include "EndOrderedLinkedList.cpp" //#include "EndOrderedLinkedList.h"
Where you show error in your program ?
Sorry there is no error in the program everything is fine. I am just having a problem finding one code for coverting decimal to binary, hex and octal. My program works fine. Can you help with the coverting problem?
[/quote]
Page 1 of 1


Ask A New Question
Reply





MultiQuote






|