Sei sulla pagina 1di 20

COMPUTER SCIENCE

C++ PROJECT
ON
Number system conversion

PROJECT PREPARED BY:


AWHAN KUMAR NAYAK
BOARD ROLL NO:
CLASS: XII SCIENCE
Session: 2014-15

UNDER THE GUIDANCE OF

MANASH RANJAN SAHOO


PGT(COMPUTER SCIENCE)

KENDRIYA VIDYALAYA NO-4


NEELADRI VIHAR
Bhubaneswar-751021

TABLE OF CONTENTS
Certificate
Acknowledgement
Header files and their purpose
Coding
Output
Requirements
Conclusion
Bibliography

Acknowledgement

We thank our Computer Science teacher Manash Ranjan


Sahoo for guidance and support. I also thank our Principal Mrs S
Shadangi. I would like to thank all of our friends and teachers for
encouraging us during the course of this project. Finally I would
like to thank CBSE for giving us this opportunity to undertake
this project.
Name:AWHAN KU. NAYAK
Board Roll.
Class: XII Science
Session: 2014-15

Certificate
This is certify that AWHAN KU. NAYAK of class XII Science,
has successfully completed their project on computer practical for
the AISSCE (All India Senior School Certificate Examination) as
prescribed by CBSE in the year 2014-15.

Date :
Signature of Subject
Teacher

Signature of Principal

____________________

_____________________

Requirements
HARDWARE REQUIRED
Printer, to print the required documents of the project
Compact Drive
Processor : Intel i3 Processor
Ram : 2 GB
Hard disk : 500 Gb.

SOFTWARE REQUIRED
Operating system : Windows XP/7/8
Turbo C++, for execution of program and
Ms word, for presentation of output.

HEADER FILES USED AND


THEIR PURPOSE
1. IOSTREAM.H- for Input/Output Operations
2. FSTREAM.H for file handling
3. PROCESS.H for exit() function
4. CONIO.H for clrscr() and getch() functions
5. STDIO.H for standard I/O operations
6. STRING.H for string handling
7. IOMANIP.H- for I/O manipulation

CODING
#include <iostream>
#include <cmath>
#include <string.h>
#include <fstream>
using namespace std;
//Function to convert Decimal to Binary
int start = 0;
void DTOB()
{
long dec,rem,i=1,sum=0,temp;
cout << "Enter the decimal number [0-9] to be converted: ";
cin >> dec;
temp = dec;
do
{
rem=dec%2;
sum=sum + (i*rem);
dec=dec/2;
i=i*10;
}while(dec>0);
cout << "The binary of the given number is:" << sum << endl;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Decimal to Binary\n";
fileout<<"Input : "<<temp<<" Output : "<<sum<<"\n";
fileout.close();
}
//End of Function
//Function to convert decimal to hexadecimal
void DTOH()
{
int input ;
cout << "Enter the decimal number [0-9] to be converted: " ;
cin >> input ;

cout << "The hexadecimal of the given number is: " << std::hex <<
input << endl ;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Decimal to Hexadecimal\n";
fileout<<"Input : "<<input<<" Output : "<<std::hex <<
input<<"\n";
fileout.close();
}
//End of Function
//Function to convert decimal to octal
void DTOO()
{
int input ;
cout << "Enter the decimal number [0-9] to be converted: " ;
cin >> input ;
cout << "The octal of the given number is: " << std::oct << input
<< endl;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Decimal to Octal\n";
fileout<<"Input : "<<input<<" Output : "<<std::oct <<
input<<"\n";
fileout.close();
}
//End of Function
//Function to convert Binary to Decimal
void BTOD()
{

int a[10],i,no,sum=0,j,k=0,temp;
cout << "Enter the binary number [0-1] to be converted: ";
cin >> no;
temp = no;
i=0;
while(no>0)
{
a[i]=no%10;
no=no/10;
i++;
}
for(j=0;j<i;j++)
{
sum=sum+a[j]*pow(2,k);
k++;
}
cout << "The decimal of the given number is: " << sum << endl;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Binary to Decimal\n";
fileout<<"Input : "<<temp<<" Output : "<<sum<<"\n";
fileout.close();
}
//End of Function
//Function to convert binary to hexadecimal
void BTOH()
{
int a[10],i,no,sum=0,j,k=0,temp;
cout << "Enter the binary number [0-1] to be converted: ";
cin >> no;
temp = no;
i=0;
while(no>0)
{
a[i]=no%10;
no=no/10;
i++;
}

for(j=0;j<i;j++)
{
sum=sum+a[j]*pow(2,k);
k++;
}
cout << "The hexadecimal of the given number is: " << std::hex <<
sum << endl;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Binary to Hexadecimal\n";
fileout<<"Input : "<<temp<<" Output : "<<std::hex << sum<<"\n";
fileout.close();
}
//End of Function
//Function to convert binary to octal
void BTOO()
{
int decimal=0, i=0, n,temp;
cout << "Enter the binary number [0-1] to be converted: ";
cin >> n;
temp = n;
while(n!=0)
{
decimal+=(n%10)*pow(2,i);
++i;
n/=10;
}
cout << "The octal of the given number is:" << std::oct <<
decimal << endl;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else

{
fileout.open("Output.txt",ios::app);
}
fileout<<"Binary to Octal\n";
fileout<<"Input : "<<temp<<" Output : "<<std::oct <<
decimal<<"\n";
fileout.close();
}
//End of Function
//Function to convert hexadecimal to decimal
void HTOD()
{
int x,temp,y;
cout<<"Enter the hexadecimal number [0-9][a-f] to be converted:
"<<endl;
cin >>std::hex >> x;
cout << "The decimal number of the given number : "<< x << endl;
//cout<<"value of temp:"<<temp;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Hexadeimal to Decimal\n";
fileout<<"Output : "<<x<<" Input : "<< std::hex << x << "\n";
fileout.close();
}
//End of Function
//Function to convert hexadecimal to binary
void HTOB()
{
int rem, i=1, dec, sum=0,temp;
cout << "Enter the hexadecimal number [0-9][a-f] to be converted:
" <<endl;
cin >> std::hex >> dec;
temp=dec;
do
{

rem=dec%2;
sum=sum + (i*rem);
dec=dec/2;
i=i*10;
}while(dec>0);
cout << "The binary number of the given number :" << sum<< endl;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Hexadeimal to Binary\n";
fileout<<"Output : "<<sum<<" Input : "<< std::hex << temp <<
"\n";
fileout.close();
}
//End of Function
//Function to convert hexadecimal to octal
void HTOO()
{
int dec,t1;
cout << "Enter the hexadecimal number [0-7][a-f] to be converted:
" <<endl;
cin >> std::hex >> dec;
t1=dec;
cout << "The octal number of the given number :" << std::oct <<
dec << endl;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Hexadeimal to Octal\n";

fileout<<"Input : "<< std::hex << t1 <<" Output : "<<std::oct <<


dec << "\n";
fileout.close();
}
//End of Function
//Function to convert octal to decimal
void OTOD()
{
int dec,t1;
cout << "Enter the octal number [0-7] to be converted: " <<endl;
cin >> std::oct >> dec;
cout << "The octal number of the given number :" << dec << endl;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Octal to Decimal\n";
fileout<<"Output : "<< dec <<" Input : "<< std::oct << dec <<
"\n";
fileout.close();
}
//End of Function
//Function to convert octal to binary
void OTOB()
{
int dec, rem, i=1, sum=0, temp;
cout << "Enter the octal number [0-7] to be converted: " << endl;
cin >> std::oct >> dec;
temp = dec;
do
{
rem=dec%2;
sum=sum + (i*rem);
dec=dec/2;
i=i*10;
}while(dec>0);

cout << "The binary of the given number is: " << sum << endl;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Octal to Binary\n";
fileout<<"Output : "<<sum<<" Input : "<< std::oct << temp <<
"\n";
fileout.close();
}
//End of Function
//Function to convert octal to hexadecimal
void OTOH()
{
int dec,t1;
cout << "Enter the octal number [0-7] to be converted: " << endl;
cin >> std::oct >> dec;
t1=dec;
cout << "The hexadecimal number of the given number : " <<
std::hex << dec <<endl;
//inserting the output to the file.
ofstream fileout;
if(start==0)
{
fileout.open("Output.txt",ios::out);
start = 1;
}
else
{
fileout.open("Output.txt",ios::app);
}
fileout<<"Hexadeimal to Octal\n";
fileout<<"Input : "<< std::oct << t1 <<" Output : "<<std::hex <<
dec << "\n";
fileout.close();
}
//End of Function
//Start of Main function

int main()
{
char again = 'y';
int choice;
cout << " Welcome to the Converter" << endl <<
"*******************************************" << endl << endl;
while ( again == 'y' )
{
cout << "*******************************************" << endl;
cout << "| Decimal to Binary : Press 1 |" << endl;
cout << "| Decimal to Hexadecimal : Press 2 |" << endl;
cout << "| Decimal to Octal : Press 3 |" << endl;
cout << "| Binary to Decimal : Press 4 |" << endl;
cout << "| Binary to Hexadecimal : Press 5 |" << endl;
cout << "| Binary to Octal : Press 6 |" << endl;
cout << "| Hexadecimal to Decimal : Press 7 |" << endl;
cout << "| Hexadecimal to Binary : Press 8 |" << endl;
cout << "| Hexadecimal to Octal : Press 9 |" << endl;
cout << "| Octal to Decimal : Press 10 |" << endl;
cout << "| Octal to Binary : Press 11 |" << endl;
cout << "| Octal to Hexadecimal : Press 12 |" << endl;
cout << "*******************************************" << endl;
cin >> choice;
switch(choice)
{
case 1 : DTOB();break;
case 2 : DTOH();break;
case 3 : DTOO();break;
case 4 : BTOD();break;
case 5 : BTOH();break;
case 6 : BTOO();break;

case 7 : HTOD();break;
case 8 : HTOB();break;
case 9 : HTOO();break;
case 10 : OTOD();break;
case 11 : OTOB();break;
case 12 : OTOH();break;
default : cout << "you have pressed wrong choice" << endl;
}
choice = 0 ;
cout << "Want to do again : Press y or n" << endl;
cin >> again;
}

Output
(Screen Shots)

Conclusion
This project number system converter is made for scientific
purpose where we can convert a data from one base type to
other base type,we have also implemented the data file handling
to store the converted values this project ultimately helps those
who are going to convert various data on different base.

FUTURE SCOPE AND


ENHANCEMENT
One s complement,two s complement arithmetical operations can be
done through this software.

Biblography:
1. Computer Science with C++ by Sumita Arora

Potrebbero piacerti anche