answersLogoWhite

0


Best Answer

#include <iostream>

#include <string>

using namespace std;

class Decimal

{

public:

Decimal():m_dec(0){}

Decimal(int i):m_dec(i){}

Decimal & operator=(const int i){m_dec=i;return(*this);}

string conv(int base) const;

private:

int m_dec;

};

string Decimal::conv(int base) const

{

if(m_dec==0)

return("0");

int decimal=m_dec;

char NUMS[]="0123456789ABCDEF";

string result="";

do{

result.push_back(NUMS[decimal%base]);

decimal/=base;

}while(decimal!=0);

return(string(result.rbegin(),result.rend()));

}

int main(void)

{

int i=0;

Decimal dec=0;

do{

cout<<"Enter a decimal number (0 to quit): ";

cin>>i;

if(i)

{

dec=i;

cout<<"Base 2: "<<dec.conv(2)<<endl;

cout<<"Base 8: "<<dec.conv(8)<<endl;

cout<<"Base 10: "<<dec.conv(10)<<endl;

cout<<"Base 16: "<<dec.conv(16)<<endl;

}

}while(i);

return(0);

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How to write a class called decimalHexOctalBinary that has four properties mainly decimalUnsignedInt base 10 hexadecimalUnsignedInt base 16 octal UnsignedInt base 8 and and binaryUnsigned Intbase 8?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is difference between unsignedint and signedint in c language?

Unsigned int does not have a sign, meaning that it can be zero or a positive number in the range of data type (int). Signed data has a sign and can be positive, zero or negative.


Write a program in c to lock a folder?

#include&lt;iostream&gt;#include&lt;fstream&gt;#include&lt;windows.h&gt;usingnamespace std;void lockfolder();void unlockfolder();void setcolour(unsignedint colour);int main(){unsignedint choice=0;SetConsoleTitle("Folder Lock"); system("CLS"); setcolour(14); cout &lt;&lt;"\t\t\t\t"&lt;&lt;"- Evil Genious\n"; cout &lt;&lt;"\t\t\t\t"&lt;&lt;"-----------------\n"; setcolour(15); setcolour(30); cout &lt;&lt;"\n\n"&lt;&lt;"Options:\t\t\t\n"; cout &lt;&lt;"\t======================\n"; cout &lt;&lt;"\t1. - Lock Folder.\n"; cout &lt;&lt;"\t2. - Unlock Folder.\n"; cout &lt;&lt;"\t3. - Exit.\n"; cout &lt;&lt;"\t====================== \n"; setcolour(128); cout &lt;&lt;"\nEnter your choice: "; cin &gt;&gt; choice;switch(choice){case1: lockfolder();break;case2: unlockfolder();break;case3:exit(0);break;default: cout &lt;&lt;"\nError. Unknown Option Entered. Quitting ....\n";break;}return0;}void setcolour(unsignedint colour){ HANDLE handle =GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleTextAttribute(handle, colour);}void lockfolder(){charpass[15]=""; ofstream lfolder;char folder[200]={0};char tempfolder[200]={'0'};char attributes[50]={'0'}; setcolour(13); cout &lt;&lt;"\nEnter the complete path to the Folder: "; cin &gt;&gt; folder; strcpy(tempfolder, folder); strcat(folder,"\\Desktop.ini"); lfolder.open(folder, ios::out); lfolder &lt;&lt;"[.shellClassInfo]"&lt;&lt; endl; lfolder &lt;&lt;"CLSID = {63E23168-BFF7-4E87-A246-EF024425E4EC}"&lt;&lt; endl; lfolder.close(); strcpy(attributes,"attrib +h +s "); strcat(attributes, tempfolder);WinExec(attributes, NULL); lfolder.open("C:\\windows\\db.dat", ios::app); lfolder &lt;&lt;"Folder Locked: "&lt;&lt; tempfolder &lt;&lt; endl; lfolder.close(); cout &lt;&lt;"\n\n"&lt;&lt; tempfolder &lt;&lt;" has been locked successfully!\n";}void unlockfolder(){char folder[255];char tempfolder[255];char attributes[50];chardel[50]; ofstream lfolder; setcolour(14); cout &lt;&lt;"\nEnter the complete path to the Folder: "; cin &gt;&gt; folder; strcpy(tempfolder, folder); strcat(folder,"\\Desktop.ini"); strcpy(del,"del "); strcat(del, folder); system(del); strcpy(attributes,"attrib -h -s "); strcat(attributes, tempfolder);WinExec(attributes, NULL); lfolder.open("C:\\windows\\db.dat", ios::app); lfolder &lt;&lt;"! Folder Unlocked: "&lt;&lt; tempfolder &lt;&lt; endl; lfolder.close(); cout &lt;&lt;"\n\n"&lt;&lt; tempfolder &lt;&lt;" has been unlocked successfully!\n";}