0% found this document useful (0 votes)
46 views14 pages

Program For Octal and Hexadecimal Equivalent Numbers

The document contains 5 code snippets that demonstrate C++ programs for: 1) Calculating the octal and hexadecimal equivalents of a decimal number. 2) Calculating the binary equivalent of a decimal number using numeric limits. 3) Calculating the lowest common multiple (LCM) of two numbers. 4) Converting a string from lowercase to uppercase. 5) Simulating dice rolls through random number generation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views14 pages

Program For Octal and Hexadecimal Equivalent Numbers

The document contains 5 code snippets that demonstrate C++ programs for: 1) Calculating the octal and hexadecimal equivalents of a decimal number. 2) Calculating the binary equivalent of a decimal number using numeric limits. 3) Calculating the lowest common multiple (LCM) of two numbers. 4) Converting a string from lowercase to uppercase. 5) Simulating dice rolls through random number generation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Q.

1:PROGRAM FOR OCTAL AND HEXADECIMAL EQUIVALENT NUMBERS:#include <iostream>


using namespace std;
#define limit 20

// Declaring the size of arrays

int main()
{
int count1 = 0, count2 = 0, num1, num2, call_hexadecimal,
call_octal, mod_remainder1[limit], remainder[limit],
mod_remainder2[limit]; // Declaring the variables
cout << "Enter a number: ";
cin >> num1;
num2 = num1;
cout << endl << endl;
cout << "Octal Equivalent: ";

// Octal Equivalent Number

while (num1 >= 8)


{
mod_remainder1[count1] = num1 % 8;
num1 /= 8 ;
count1++;
}
cout << num1;
call_octal = count1-1;
while (call_octal >= 0)

// Printing Octal Equivalent Number

{
cout << mod_remainder1[call_octal];

call_octal--;
}

cout << endl << endl;


cout << "Hexadecimal Equivalent: ";// Hexadecimal equivalent
while (num2 >= 16)
{
remainder[count2] = num2 % 16;
mod_remainder2[count2] = remainder[count2];
num2 /= 16;
count2++;
}
cout << num2;
call_hexadecimal = count2 - 1;
while (call_hexadecimal >= 0)

// Printing Hexadecimal

{
if (mod_remainder2[call_hexadecimal] == 10)
{
cout << "A";
}
else if (mod_remainder2[call_hexadecimal] == 11)
{
cout << "B";
}
else if (mod_remainder2[call_hexadecimal] == 12)

{
cout << "C";
}
else if (mod_remainder2[call_hexadecimal] == 13)
{
cout << "D";
}
else if (mod_remainder2[call_hexadecimal] == 14)
{
cout << "E";
}
else if (mod_remainder2[call_hexadecimal] == 15)
{
cout << "F";
}
else
{
cout << mod_remainder2[call_hexadecimal];
}
call_hexadecimal--;
}
return 0;
}

Q.2:* http://www.cplusplus.com/reference/limits/numeric_limits/
Numeric limits type:It provides details about the properties of arithmetic
types integer and floating point both for which the library
compiles.
This class template is specialized for every arithmetic type,
with its members describing the properties. This template shall
not be specialized for any other type.
PROGRAM FOR BINARY EQUIVALENT NUMBERS:#include <iostream>
#include <limits>

//Limiting the value of the variables

using namespace std;


#define limit 20
int main ()
{
int terminator = numeric_limits<int>::max();
//Declaring the variables
int count = 0, num, call_remainder;
bool mod_remainder[limit];
//Declaring the variable as bool type
cout << "Enter a number: ";

//Input from the user

cin >> num;


if (num >= terminator)
{
cout << "The program will not work " << endl;
return 0;
}

cout << endl;


cout << "Binary Equivalent: ";
while (num >= 2)

//Finding the Binary Equivalent

{
mod_remainder[count] = num % 2;
num /= 2;
count++;
}
cout << num;
call_remainder = count - 1;
while (call_remainder >= 0)

//Printing the binary Equivalent

{
cout << mod_remainder[call_remainder];
call_remainder--;
}
return 0;
}

http://www.cplusplus.com/reference/limits/numeric_limits/

Q.3:-

PROGRAM FOR THE LCM OF TWO NUMBERS:#include <iostream>


using namespace std;
int main()
{
int a,b,result_a,result_b;

//Declaring two variables

cout << "Enter one number: ";


cin >> a;

//Taking input from the user

cout << "Enter another number: ";


cin >> b;
result_a = a;
result_b = b;
while (result_a!=result_b)

//Calculating the LCM

if (result_a < result_b)


{
result_a += a;
}
else
{
result_b += b;
}
cout << "LCM of the given numbers: " << result_a << endl;
//Displaying the LCM
return 0;
}

Q.4:PROGRAM FOR THE FUNCTION TO CONVERT AN INPUT STRING FROM LOWER


CASE TO UPPER:* http://www.ytpak.com/watch?v=XUmZcK44lsc
#include<iostream>
using namespace std;
string tocapital(string x)
{
int stringlength;
stringlength=x.length(); //Length() tells the length of string
char word[stringlength];
x.copy(word,stringlength);
for(int count=0; count<stringlength; count++)
{
if ((word[count]>=97) && (word[count]<=122))
{
if (word[count]==32)
{
word[count]=word[count];
}
else
{
word[count]=word[count]-32;
}

}
string result(word);//String variable(variable) converts array
return result;
}
int main()
{
string sentence,print;
cout<<"Enter the sentence: ";
getline(cin,sentence);
print=tocapital(sentence);
cout << endl << endl;
cout<<print;
return 0;
}

* http://www.ytpak.com/watch?v=XUmZcK44lsc

Q.5:PROGRAM FOR THE GENERATION OF THE SIMULATION OF DICE:*http://www.ytpak.com/watch?v=naXUIEAIt4U


#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
#define limit 6
main()

//Declaring limits

int

int num2,num1;

//Declaring variables

int occur[limit]={0,0,0,0,0,0};
srand(time(NULL));
cout<<"Enter the no of times you want to throw the dice: ";
cin>>num2;
for(int count=1; count<=num2; ++count)//Generating random nos.
{
num1 = (rand()%6)+1;
if(num1 == limit)
{
occur[0] = occur[0]+1;
}
if(num1 == limit-1)
{
occur[1] = occur[1]+1;
}

if(num1 == limit-2){
occur[2]=occur[2]+1;
}
if(num1 == limit-3){
occur[3]=occur[3]+1;
}
if(num1 == limit-4){
occur[4]=occur[4]+1;
}
if(num1 == limit-5)
{
occur[5]=occur[5]+1;
}
}
cout << "Result:" << endl;

//Printing the output

cout << "1 appeared: " << occur[5] << "times" << endl;
cout << "2 appeared: " << occur[4] << "times" << endl;
cout << "3 appeared: " << occur[3] << "times" << endl;
cout << "4 appeared: " << occur[2] << "times" << endl;
cout << "5 appeared: " << occur[1] << "times" << endl;
cout << "6 appeared: " << occur[0] << "times" << endl;
return 0;
}

*http://www.ytpak.com/watch?v=naXUIEAIt4U

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy