# data[].attributes.body
#include <iostream>
using namespace std;

/*
Date: 10/02/2018
Name: Jowoon Kim
Project name: lab3
*/

int main () {

char x;

cout << "Enter a character: ";
cin >> x;

cout << x << "\'s integer equivalent is " << static_cast<int>( x );

return 0;

}

# data[].attributes.body
#include <iostream>
using namespace std;
int main()
{
int usage, rate;
cout << "Enter Your Electrical Usage in Kilowatt Hours: " ;
cin >> usage;
if (usage>1000)
rate = usage * 0.45;
else
rate = usage * 0.6;
cout <<"Total Electric Bill: RM" << rate;
return 0;
}

# data[].attributes.body
#include<iostream>
#include<iomanip>
using namespace std;

int main ()
{
int dec;
cout << "Enter a decimal number: " << endl;
cin >> dec;
cout << "The hexadecimal number is: " << hex << dec;

}

# data[].attributes.body
#include <iostream>
#include <string>
using namespace std;
int main()
{
string mixture;
bool red, green, blue;
string string_bool;
cout << "Include red in mixture? (y/n) \n";
cin >> string_bool;
if (string_bool == "y")
red = true;

cout<<"include green in mixture? (y/n) \n";
cin >> string_bool;
if (string_bool == "y")
green = true;
cout << "Include blue in mixture? (y/n) \n";
cin >> string_bool;
if (string_bool == "y")
blue = true;
if (!blue && !green)
mixture = "RED";
else if (!red && !blue)
mixture = "GREEN";
else if (!red && !green)
mixture = "BLUE";
else if (red)
{
if (green || blue)
{ if (green && blue)
mixture = "BLACK";
else if (green)
mixture = "YELLOW";
else
mixture = "PURPLE";
}
}
else
{
if (blue && green)
mixture = "CYAN";
else
mixture = "WHITE";
}
cout << "Your mixture is " << mixture << "\n";

return 0;
}

# data[].attributes.body
Y N Y = Purple

Y Y N = Yellow

N N N = Red

Y Y N = Yellow

N Y N = Green

Y N N = Red

# data[].attributes.body
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int num;
cout << "Present to you by Harold and Eslam."<< endl;
cout << "___________________________________"<< endl << endl;
cout <<"Enter a number : ";
cin >> num;
cout << endl <<"Hexadecimal of this number is "<< hex << num <<".";
}

# data[].attributes.body
#include <iostream>
using namespace std;
int main ()
{
char x;
char choice;
do{
cout << "Enter the character: ";
cin >> x;
cout << endl << "The integer equivalent of the character is " << static_cast<int>(x) << "." << endl;
cout << endl << "Do you want to continue (Y/N): ";
cin >> choice;
cout << endl;}
while (choice=='Y');
return 0;
}

# data[].attributes.body
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
int num;
cout <<"   Present to you by Harold and Eslam."<< endl;
cout <<"_________________________________________;"<< endl << endl;
cout << "Enter a number : ";
cin >> num;
cout << endl <<"Hexadecimal of this number is "<< hex << num <<".";
}

# data[].attributes.body
#include <iostream>
#include <string>
using namespace std;
int main()
{

int customer_city;
double gal_last;
double discount_rate = 1;
cout << "Customer City (1 for Boston and 2 for Worcester)";
cin>> customer_city;
cout << "Number of gallons of oil used last year: ";
cin >> gal_last;

switch (customer_city)
{
case 1:
switch (gal_last>= 1200)
{
case true:
discount_rate = .9;
break;
case false:
discount_rate = 1;
break;

}
break;
case 2:
switch (gal_last>=1200)
{
case true:
discount_rate = .9;
break;
case false:
discount_rate = 1;
break;
}
break;
default:
switch (gal_last>=1200)
{
case true:
discount_rate = .9;
case false:
discount_rate = 1;
}

}

cout << "Discount rate is: " << discount_rate;
return 0;
}

# data[].attributes.body
// to arrange the order, it is possible to use array
#include<iostream>

using namespace std;

main()
{
int dec,newrt;
cout<<"Enter Decimal Number: "<<endl;
cin>>dec;

while(dec>0)
{
newrt=dec%16;
dec=dec/16;

if(newrt>9)
{
switch(newrt)
{
case 10:cout<<"A";
break;
case 11:cout<<"B";
break;
case 12:cout<<"C";
break;
case 13:cout<<"D";
break;
case 14:cout<<"E";
break;
case 15:cout<<"F";
break;
}
}

else
{
cout<<newrt;
}

}

return 0;
}
+++++++++++++++++++++++++++
This version use array to store the arrangement of hex value.

// C++ program to convert a decimal
// number to hexadecimal number

#include<iostream>
using namespace std;

// function to convert decimal to hexadecimal
void decToHexa(int n)
{
// char array to store hexadecimal number
char hexaDeciNum[100];

// counter for hexadecimal number array
int i = 0;
while(n!=0)
{
// temporary variable to store remainder
int temp  = 0;

// storing remainder in temp variable.
temp = n % 16;

// check if temp < 10
if(temp < 10)
{
hexaDeciNum[i] = temp + 48;
i++;
}
else
{
hexaDeciNum[i] = temp + 55;
i++;
}

n = n/16;
}

// printing hexadecimal number array in reverse order
for(int j=i-1; j>=0; j--)
cout << hexaDeciNum[j];
}

# data[].attributes.body
#include<iostream>
using namespace std;

int main()
{
int customer_city;
char B, W;
double gal_last;
double discount_rate = 1;

cout << "1 = Boston, 2 = Worcester" << endl;
cout << "Customer City(1/2):";
cin >> customer_city;

cout << "Number of gallons of oil used last year:";
cin >> gal_last;

switch (customer_city)
{
case 1 :
switch (gal_last >= 1000)
{
case'true' : discount_rate = 0.9;
break;
case'false' : discount_rate = 1;
break;
default : cout << "Invalid rate";
}
break;
case 2 :
switch(gal_last >= 1200)
{
case'true': discount_rate = 0.91;
break;
case'false': discount_rate = 1;
break;
default : cout << "Invalid rate";
}
default :
switch(gal_last >= 1500)
{
case'true': discount_rate = 0.9;
break;
case'false' : discount_rate = 1;
}
cout << "Discount rate is : " << discount_rate;

return 0;
}
}

# data[].attributes.body
#include <iostream>

using namespace std;

int main()
{

float usage;

float electricBill;

// get input from user as long as the input is invalid (i.e, negative)
do {
cout << "Enter the usage in KWH: " ;
cin >> usage;

if (usage < 0) {
cout << "Usage cannot be negative, please enter again" << endl;
}

} while (usage < 0);

// determining the rate
if (usage >= 2000) {
electricBill = (999 * 0.6) + (500 * 0.45) + (500 * 0.4) + ((usage - 1999) * (0.35));
} else if (usage >= 1500) {
electricBill = (999 * 0.6) + (500 * 0.45) + ((usage - 1499) * (0.4));
} else if (usage >= 1000) {
electricBill = (999 * 0.6) + ((usage - 999) * 0.45);
} else {
electricBill = usage * 0.6;
}

cout << "The electric bill is RM " << electricBill << endl;

return 0;
}

# data[].attributes.body
#include<iostream>
using namespace std;
int main()
{
int secElapsed, hours, minutes, seconds;
const int secPerMin = 60;
const int secPerHour = 60 * secPerMin;
cout<<"Please enter the number of second elapsed:  ";
cin>>secElapsed;

hours = secElapsed / secPerHour;
secElapsed = secElapsed % secPerHour;
minutes = secElapsed / secPerMin;
seconds = secElapsed % secPerMin;
cout<<hours<<":"<<minutes<<":"<<seconds<<endl;
return 0;
}

# data[].attributes.body
#include <iostream>
using namespace std;
int main()
{
int usage,rate;
cout<< "Please enter the Electrical Usage: ";
cin>>usage;
if (usage>1000)
{
rate = usage* 0.45;
}
else rate = usage * 0.6;
cout <<"Total Electric Bill : RM"<< rate;
return 0;
}

# data[].attributes.body
#include<iostream>
#include<iomanip>
using namespace std;

int main ()
{
int dec;
cout << "Enter a decimal number: " << endl;
cin >> dec;
cout << "The hexadecimal number is: " << hex << dec;

}