Sunday, December 16, 2012

How to convert psi to bar, pascal, kilopascal, atmosphere, torr, inch mercury, inch water


This article will show how to convert from one unit of pressure to another. Common units of pressure are psi (pound per square inch), bar, pascal, kilopascal, atmosphere, torr (mm Mercury), and inch water (in H2O). Although there are many units of pressure, there are standard units of pressure according to a system of units. In the SI system, the unit for pressure is the pascal (Pa), which is equal to one newton per square meter (N/m2). In the English system, units of pressure are commonly psi, bar, and inch mercury.

Atmospheric Pressure


Atmospheric pressure or Barometric pressure is the force exerted by the weight of air on a surface of the Earth. Atmospheric pressure decreases with elevation. The atmospheric air pressure is lesser on top of a mountain than on sea level. For every 1,000 feet (305 meters) you ascend, the atmospheric pressure decreases by about 4%. The boiling point of water on sea level is 100 degrees Celsius or 212 degrees Fahrenheit. At higher altitudes, the boiling point of water will be lower than 100 C (212 F) because the air density is lesser (the air is thinner) and the atmospheric air pressure is lesser (lesser pressure acting on the water surface). This means that lesser energy is required to overcome the forces keeping the water in its liquid form. In other words, at the top of a mountain (higher elevation), it is easier and faster to boil water than it is at sea level (lower altitude).

Absolute Pressure


Absolute pressure (P abs) is equal to atmospheric pressure (P atm) plus gauge pressure (P gage).
P abs = P atm + P gage

Absolute pressure (P abs) is equal to atmospheric pressure (P atm) minus vacuum pressure (P vac).
P abs = P atm - P vac

Gauge pressure (P gage) is equal to absolute pressure (P abs) minus atmospheric pressure (P atm).
P gage = P abs - P atm

Vacuum Pressure (P vac) is equal to atmospheric pressure (P atm) minus absolute pressure (P abs). Vacuum pressure is air pressure below atmospheric pressure. This is a negative pressure reading on the pressure gauge (instrument).
P vac = P atm - P abs


How to calculate Absolute Pressure:

  
Example:
Calculate the absolute pressure (psia) in a system with a gauge pressure reading of 10 psi. When the system experiences a vacuum pressure of 2 psi, calculate the resulting absolute pressure in this conditon.

Given:
P gage = 10 psi
P vac = 2 psi

Required:
P abs (absolute pressure in psia)

Solution:
a.)
P abs = P atm + P gage
P abs = 14.7 + 10
P abs = 24.7 psia

b.)
P abs = P atm - P vac
P abs = 14.7 - 2
P abs = 12.7 psia


Standard units of Atmospheric Pressure


The reference unit of atmospheric pressure is One Standard Atmosphere (1 atm). This is measured according to the following conditions:
1. Altitude = sea level
2. Temperature = 20 °C (68 °F)
3. Air density = 1.225 kg/m3
4. Relative humidity = 20%

Under the given conditions above, One Standard Atmosphere (1 atm) is equal to:
1 atm = 14.7 psi
1 atm = 1.01325 bar
1 atm = 101, 325 Pa
1 atm = 101.325 KPa
1 atm = 760 mmHg (torr)
1 atm = 76 cm mercury
1 atm = 29.92 inHg
1 atm = 407.2 inch water 

Conversion from one unit of pressure to another 
  
Converting from one unit of pressure to another is easy. All you have to do is to use the equivalent of 1 atm (listed above) in your calculation to the desired unit of pressure. I will show an example of converting psi to other units of pressure. The procedure is similar when converting from one unit of pressure to another.

Conversion of psi to other units of pressure
  
Example:
The recommended tire pressure for a typical car is 32 psi minimum to 35 psi maximum. I will use this example maximum car tire pressure of 35 psi to covert to other units of pressure. 

1. How to convert psi to atm:
To convert psi to atm, divide the given pressure in psi by 14.7
35 psi x 1 atm/14.7 psi
35/14.7
= 2.38 atm

2. How to convert psi to bar:
To convert psi to bar, multiply the given pressure by 1.01325 and divide by 14.7
35 psi x 1.01325 bar/14.7 psi
35 x 1.01325/14.7
= 2.41 bar

3. How to convert psi to pascals:
To convert psi to pascals, multiply the given pressure by 101,325 and divide by 14.7
35 psi x 101,325 Pa/14.7 psi
35 x 101,325/14.7
= 241,250 Pa

4. How to convert psi to Kilo Pascals:
To convert psi to KPa, multiply the given pressure by 101.325 and divide by 14.7
35 x 101.325 KPa/14.7 psi
35 x 101.325/14.7
= 241.25 KPa

5. How to convert psi to mm Hg (millimeters of mercury or torr):
To convert psi to mmHg, multiply the given pressure by 760 and divide by 14.7
35 psi x 760 mmHg/14.7 psi
35 x 760/14.7
= 1809.52 mmHg

6. How to convert psi to cm Hg (centimeters Mercury):
To convert psi to cmHg, multiply the given pressure by 76 and divide by 14.7
35 psi x 76 cmHg/14.7 psi
35 x 76/14.7
= 180.95 cmHg

7. How to convert psi to in Hg (inches of Mercury):
To convert psi to inHg, multiply the given pressure by 29.92 and divide by 14.7
35 psi x 29.92 inHg/14.7 psi
35 x 29.92/14.7
= 71.24 inHg

8. How to convert psi to in H2O (inch of water):
To convert psi to inH2O, multiply the given pressure by 407.2 and divide by 14.7
35 psi x 407.2 inH2O/14.7 psi
35 x 407.2/14.7
= 969.52 inH2O

Saturday, December 15, 2012

C++ TUTORIAL FOR BEGINNERS: Program to compute for Total Monthly Income (Revenue), Expenses, and Net Income (Profit)


This C++ program is a simple basic addition and subtraction operation involving a typical household monthly salary, revenue, monthly bills and expenses and the total net profit. The user is required to enter the amounts and other information. If a field which requires a data to input does not apply to a given user, 0 (zero) should be entered. An output file called "income.txt" is generated by the program to reflect the values keyed in.

Sample data input:

income.txt file:

Source code:

/*
PROGRAM 6: Monthly Net Income
AUTHOR: eternaltreasures
DATE: 2010 September 18
*/


#include <iostream>
#include <fstream>
using namespace std;

#define newline '\n'

int main ()
{

int year;
char month[10];

float Wages_Salary,
      Spouse_Child_support,
      Other_income;

float Food_Grocery,
      Mortgage_Rent,
      Transportation,
      Retirement,
      Insurance,
      Education,
      Children,
      Cable_Internet,
      Home_Cell_phone,
      Loans_Credit_cards,
      Laundry,
      Electricity,
      Gas_Heating,
      Water_bills,
      Personal,
      Clothing,
      Medical,
      Recreation,
      Donations_Gifts,
      Other_expenses;
     
float INCOME, 
      EXPENSES,
      NET_INCOME;
     
//Open the output file     
ofstream fout;    
fout.open ("income.txt");

//Welcome and instructions
cout << "Welcome to the Monthly Net Income report program!";
cout << newline;
cout << newline;
cout << "Pls. fill up all the data.";
cout << newline;
cout << "Enter 0 if not applicable.";
cout << newline;
cout << newline;

//Year and Month  
cout << "Year: "; cin >> year;
cout << "Month: "; cin >> month;
cout << newline;

//INCOME sources
cout << "MONTHLY INCOME:";
cout << newline;
cout << "Wages/Salary: "; cin >> Wages_Salary;  
cout << "Spouse/Child support: "; cin >> Spouse_Child_support;
cout << "Other income: "; cin >> Other_income;
cout << newline;

//ALL EXPENSES
cout << "MONTHLY EXPENSES:";
cout << newline;
cout << "Food/Grocery: "; cin >> Food_Grocery;
cout << "Mortgage/Rent: "; cin >> Mortgage_Rent;
cout << "Transportation: "; cin >> Transportation;
cout << "Retirement: "; cin >> Retirement;
cout << "Insurance: "; cin >> Insurance;
cout << "Education: "; cin >> Education;
cout << "Children: "; cin >> Children;
cout << "Cable/Internet: "; cin >> Cable_Internet;
cout << "Home/Cell phone: "; cin >> Home_Cell_phone;
cout << "Loans/Credit cards: "; cin >> Loans_Credit_cards;
cout << "Laundry: "; cin >> Laundry;
cout << "Electricity: "; cin >> Electricity;
cout << "Gas/Heating: "; cin >> Gas_Heating;
cout << "Water bills: "; cin >> Water_bills;
cout << "Personal: "; cin >> Personal;
cout << "Clothing: "; cin >> Clothing;
cout << "Medical: "; cin >> Medical;
cout << "Recreation: "; cin >> Recreation;
cout << "Donations/Gifts: "; cin >> Donations_Gifts;
cout << "Other expenses: ";  cin >> Other_expenses;

//Compute Total Income
INCOME = Wages_Salary
       + Spouse_Child_support
       + Other_income;

cout << newline;
cout << "TOTAL MONTHLY INCOME: " << INCOME;

//Compute Total Expenses
EXPENSES = Food_Grocery
         + Mortgage_Rent
         + Transportation
         + Retirement
         + Insurance
         + Education
         + Children
         + Cable_Internet
         + Home_Cell_phone
         + Loans_Credit_cards
         + Laundry
         + Electricity
         + Gas_Heating
         + Water_bills
         + Personal
         + Clothing
         + Medical
         + Recreation
         + Donations_Gifts
         + Other_expenses;

cout << newline;
cout << newline;
cout << "TOTAL MONTHLY EXPENSES: " << EXPENSES;

//Compute Net Income
NET_INCOME = INCOME - EXPENSES;

cout << newline;
cout << newline;
cout << "MONTHLY NET INCOME: " << NET_INCOME;
cout << newline;
cout << newline;

//Write to output file (income.txt)
fout << "Year: " << year;
fout << newline;
fout << "Month: " << month;
fout << newline;
fout << newline;

fout << "MONTHLY INCOME:";
fout << newline;
fout << "Wages/Salary: " << Wages_Salary;  
fout << newline;
fout << "Spouse/Child support: " << Spouse_Child_support;
fout << newline;
fout << "Other income: " << Other_income;
fout << newline;
fout << newline;

fout << "MONTHLY EXPENSES:";
fout << newline;
fout << "Food/Grocery: "  << Food_Grocery;
fout << newline;
fout << "Mortgage/Rent: " << Mortgage_Rent;
fout << newline;
fout << "Transportation: " << Transportation;
fout << newline;
fout << "Retirement: " << Retirement;
fout << newline;
fout << "Insurance: " << Insurance;
fout << newline;
fout << "Education: " << Education;
fout << newline;
fout << "Children: " << Children;
fout << newline;
fout << "Cable/Internet: " << Cable_Internet;
fout << newline;
fout << "Home/Cell phone: " << Home_Cell_phone;
fout << newline;
fout << "Loans/Credit cards: " << Loans_Credit_cards;
fout << newline;
fout << "Laundry: " << Laundry;
fout << newline;
fout << "Electricity: " << Electricity;
fout << newline;
fout << "Gas/Heating: " << Gas_Heating;
fout << newline;
fout << "Water bills: " << Water_bills;
fout << newline;
fout << "Personal: " << Personal;
fout << newline;
fout << "Clothing: " << Clothing;
fout << newline;
fout << "Medical: " << Medical;
fout << newline;
fout << "Recreation: " << Recreation;
fout << newline;
fout << "Donations/Gifts: " << Donations_Gifts;
fout << newline;
fout << "Other expenses: " << Other_expenses;
fout << newline;

fout << newline;
fout << "TOTAL MONTHLY INCOME: " << INCOME;

fout << newline;
fout << newline;
fout << "TOTAL MONTHLY EXPENSES: " << EXPENSES;

fout << newline;
fout << newline;
fout << "MONTHLY NET INCOME: " << NET_INCOME;
fout << newline;
fout << newline;

fout.close();

return 0;
}

Thursday, December 13, 2012

C++ TUTORIAL FOR BEGINNERS: How to read a file and store the records in a string


The program works as follows:

- openbook.txt must have records to read input from
- the program opens the input file for reading
- while condition is used to keep on reading while it's not yet end of the file
- if a record is read, the getline command is used to store in string record
- cout command is used to display on the screen the record read

Source code:

#include<iostream>
#include <string>
#include<fstream>
using namespace std;

int main()
{
string record;
ifstream inputfile;

inputfile.open("openbook.txt");

if (inputfile.is_open())
{
 while (!inputfile.eof())
  {
   getline(inputfile, record);
   cout << record << endl;
  }
}
inputfile.close();
return 0;
}

C++ TUTORIAL FOR BEGINNERS: How to read a file and store the records in a character array


The program works as follows:

- database.txt must have records to read input from
- the main () function calls the function read_database_file
- the program opens the "database.txt" input file for reading
- while condition is used to keep on reading while it's not yet end of the file
- if a record is read, the >> operator is used to store the record in a character array (declared as char database_record [256];)
- cout command is used to display on the screen the contents of the character array ( char database_record [256] )

Source code:

#include<iostream>
#include <string>
#include<fstream>
using namespace std;

#define newline '\n'

char database_record [256];

void read_database_file ()
{
ifstream database_file;

database_file.open ("database.txt");

if (database_file.is_open())
{
 while (!database_file.eof())
  {
   database_file >> database_record;
   cout << database_record << endl;
  }
}
else
{ cout << "Input file not successfully opened.";

database_file.close();
}
}

int main()
{
read_database_file ();
return 0;
}

C++ TUTORIAL FOR BEGINNERS: How to capture the system date and time and display them in useful common format


Source code:

/*
PROGRAM: Capturing the System date and time in business & military format using C++ language
AUTHOR: eternaltreasures
DATE: 2010 September 26
*/

#include <iostream>
#include <time.h>
using namespace std;

int main()
{

/*
Option 1: Capturing the system date using the time () function
ctime format is DayOfTheWeek Month Day Hour:Minute:Seconds Year
*/

time_t systemtime;
time(&systemtime); 

cout << endl;
cout << "System date and time is: " << ctime(&systemtime);
cout << endl;   
   
/*
Option 2: Capturing the system date and time using strdate, strtime
System date format mm/dd/yy (month/day/year)
System time format hh/mm/ss (hour:minute:seconds)
*/

char sysdate[9];
char systime[9];

_strdate(sysdate);
_strtime(systime);

cout << "System time: " << systime << endl;
cout << "System date: " << sysdate << endl;

return 0;
}

C++ Word finder and Word counter: List the words in a sentence and count the total number of words found


/*
PROGRAM: Word finder and Word counter
PURPOSE: List the words in a sentence and count the total number of words found
LANGUAGE: C++
AUTHOR: eternaltreasures
DATE: 2010 October 2
*/

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

#define newline '\n'

char sentence [124];

int i;
int character_x;
int first_write_character = 0;
int wordcounter = 0;

void extractwords ()
{
 //Start testing the sentence from the first character until the null character \0
 for (i=0; sentence[i] != '\0'; i++)
 {
 //if a space is encountered, then write the words
  if (sentence[i] == ' ')
   {   
    wordcounter = wordcounter + 1;    
    for (character_x = first_write_character; character_x < i; character_x ++)
     {
      cout << sentence[character_x];
     }
       cout << newline;
    first_write_character = i + 1;
    }
  }
}

//once the program detects the null character or empty string \0
//then this is the last word in the sentence input from the user
void extractlastword ()
{
 wordcounter = wordcounter + 1;
 for (character_x = first_write_character; character_x < i; character_x ++)
 {
  cout << sentence[character_x];
 
 }
}

//this function displays the total word count in the given sentence
void countwords ()
{
 cout << newline;
 cout << newline;
 cout << "Total words found: " << wordcounter;
}

//this is the main function of execution in the program
int main ()
{
cout << newline;

cout << "Please enter a sentence: ";
cout << newline;
gets (sentence);

cout << newline;
cout << "List of words found:";
cout << newline;
   
extractwords ();

extractlastword ();

countwords ();

return 0;
}

C++ TUTORIAL FOR BEGINNERS: Variables and their practical applications in calculations


What are C++ variables?

Variables are simply values that change as opposed to constants which do not change.

To illustrate the usefulness of variables, let us use them in an example to calculate the net profit of a video game store.

Given:
On a certain week, a video game store has a total sales of $9000 and total expenses of $6000. On the following week, total sales rose to $9500 while the total expenses increased to $6500. Calculate the net profit of the video game store on those two weeks.  

Objective: How to calculate the net profit of a given video game store
Directive: #include <iostream>
Namespace: std
Function: main
Variables: sales, expenses, profit
Data types of variables: int (integer)
Statements: cout, return
Output:
Net profit = 6000

C++ source code:

/*
PROGRAM 2: Calculation of net profit of a video game store
AUTHOR: eternaltreasures
DATE: 2010 August 26
*/

#include <iostream>
using namespace std;
int main ()
{

int sales, expenses, profit;

//First week:
sales = 9000;
expenses = 6000;

//Second week:
sales = sales + 9500;
expenses = expenses + 6500;

//Net profit of the video game store:
profit = sales - expenses;
cout << "Net profit = ";
cout << profit;

return 0;
}


Notes:
* During the first week, initial value of the variable sales is 9000 and the variable expenses is 6000.
* On the second week, the value of the variable sales is 9000 + 9500 = 18500.
* Also on the second week, the value of the variable expenses is 6000 + 6500 = 12500.
* Variables change values depending on the operations done to them on the program.

C++ String Manipulation functions: Card Verification System - Examples of String append & Substring, Reading database file


/*
PROGRAM: String Manipulation functions - Examples of String append and Substring
PURPOSE: The user is prompted to input a card number with 16 digits (four numbers
         at a time, starting from digits one to four), then the program uses the
         string append function to connect these series of four numbers to make
         up a string of 16 numbers. This card number is then matched against a
         card database file using the substring function to extract the first 16
         characters within the record then compared to the user input. If a match
         is found, the program returns a message "Card verification successful!",
         otherwise, it will display a "Card not found on database" message on the
         screen.
LANGUAGE: C++
AUTHOR: eternaltreasures
DATE: 2010 October 3
*/


#include<iostream>
#include <string>
#include<fstream>
using namespace std;

#define newline '\n'

string card_database_record;

string card_database_record_substring;

string string4; 
string card_input_record;

bool cardfound = false;

int database_record_index = 0;

void input_card_number ()
{
 cout << newline;
 cout << "Welcome to the Secure Card Verification System!";
 cout << newline;
 cout << newline;
 cout << "Enter your 16-digit card number:";
 cout << newline;
 cout << newline;

 cout << "1st to 4th digit: "; cin >> string4;
 card_input_record.append (string4);
 database_record_index = database_record_index + 4;

 cout << "5th to 8th digit: "; cin >> string4;
 card_input_record.append (string4);
 database_record_index = database_record_index + 4;

 cout << "9th to 12th digit: "; cin >> string4;
 card_input_record.append (string4);
 database_record_index = database_record_index + 4;

 cout << "13th to 16th digit: "; cin >> string4;
 card_input_record.append (string4);
 database_record_index = database_record_index + 4;

}

void compare_match_input ()
{
  
     card_database_record_substring = card_database_record.substr (0, database_record_index);
     
    
     if (card_input_record == card_database_record_substring)
     {
      cout << "Card "  << card_input_record << ": Card verification successful!";
     cardfound = true;}
    



void read_database_file ()
{
ifstream card_database_file;

card_database_file.open ("database.txt");

if (card_database_file.is_open())
{
 while (!card_database_file.eof())
  {
   card_database_file >> card_database_record;
 cout << endl;
   compare_match_input ();
  
   if (cardfound = false)
  
     cout << "End of file: Card not found on database.";
  }
}
else
{ cout << "Input file not successfully opened.";
card_database_file.close();
}
}


int main()
{
input_card_number ();
read_database_file ();

return 0;
}

C++ TUTORIAL FOR BEGINNERS: How to generate a random number, maximum random number & random numbers within a given range


/*
PROGRAM: How to generate a random number, maximum random number and random numbers within a given range

PURPOSE:
         The user is prompted to press any key to begin generating a random number. The program
         then returns to display a random number then the Maximum random number is displayed.
         The second part of the program is to let the user put a higher limit for the random
         numbers and a lower limit to generate random numbers within the required range of values.
         The program shows the values of those random numbers in the specified given range of limits.

LANGUAGE: C++
AUTHOR: eternaltreasures
DATE: 2010 October 6
*/

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int random_number;
char random_number_obtain;

      
int random_number_generator ()
{  

/* srand (time(0)) initializes the random number generator. Each time you run the program, time(0) will
capture the integer value of the Seconds from the system clock and will be used by the random number
generator as a starting value number called the SEED.

RAND_MAX returns the value of the maximum random number that could be generated and is compiler
dependent but it usually equal to 32767.
*/
srand(time(0));
int maximum_random_number;

cout << endl;
cout << "Random Number Generator" << endl << endl;
cout << "Press Any key to generate a random number."; cin >> random_number_obtain;

random_number = rand ();
maximum_random_number = RAND_MAX;

cout << endl;
cout << "Random number generated is: " << random_number << endl << endl;
cout << "MAXIMUM RANDOM NUMBER: " << maximum_random_number << endl << endl;
}

int random_number_generator_within_range ()
{
int random_counter;
int random_number_high;
int random_number_low;
int random_number_range;
   
cout << endl;
cout << "Random Number Generator within a given Range" << endl << endl;
cout << "Enter the random number higher limit: "; cin >> random_number_high;
cout << "Enter the random number lower limit: "; cin >> random_number_low;

random_number_range = (random_number_high - random_number_low) + 1;

for (random_counter = 0; random_counter < random_number_high; random_counter ++)
 {
     random_number = random_number_low + int(random_number_range * rand()/(RAND_MAX + 1));
     cout << random_number << endl;
 }
}

int main ()
{
bool random_number_generate = true;
   
 random_number_generator ();
 random_number_generator_within_range ();
 random_number_generator ();
}

C++ TUTORIAL FOR BEGINNERS: How to determine a given number if it is Odd or Even number


/*
PROGRAM: How to determine a given number if it is Odd or Even number

PURPOSE:
         In order to know whether a number is even or odd, we must use the concept
of the Modulo Operation (mod). The modulo operation will compute the Remainder of
dividing a given number by another number. For example, if we divide 10 by 2, the
quotient or result is 5 and the remainder is 0. Therefore 10 mod 2 is 0.
         On the other hand, if we divide 11 by 2, the quotient or result is 5
Remainder 1. In this case 11 mod 2 is 1.
         In our C++ program, we will use the Integer modulo operator % to determine
if a number input by a user is an odd or even number.

LANGUAGE: C++
AUTHOR: eternaltreasures
DATE: 2010 October 6
*/

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
      
void modulo_odd_even ()
{
int input_number;

cout << endl;
cout << "Determination of Odd or Even Numbers" << endl << endl;
cout << "Please enter any number: "; cin >> input_number;

//input_nmuber % 2 will find the remainder of input_number divided by 2.
//If the remainder is 0, then the number is even, otherwise it is odd.

    if (input_number % 2 == 0)
        cout << input_number << " is an Even Number" << endl << endl;
    else
        cout << input_number << " is an Odd Number" << endl << endl;   
   
}
      
      
int main()
{

bool endless_loop = true;

//for loop code leading to an ENDLESS LOOP (online mode)
//for loop without increment

for (endless_loop; (endless_loop != false);)
    modulo_odd_even ();
}

C++ Database Name Search Program: User inputs last, first name, search from a name file, match using string function


/*
PROGRAM: Database Name Search
PURPOSE: Last name and first name input are compared to the records on a namefile.
         If a match is found, then display "Record found at database".
         NOTE: string.find is used here (which is not the best method) just to show
         an example of its use. I know that experienced C++ database programmers have
         their best and most recommended ways for a name search program, you are
         welcome to comment and to share your code (thanks in advance).
LANGUAGE: C++
AUTHOR: eternaltreasures
DATE: 2010 October 2
*/

// reading a text file
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

#define newline '\n'

string recordline;
string last_name_input;
string first_name_input;

int recordnumber = 0;
bool namefound = false;

ifstream recordfile ("namefile.txt");

//Welcome introduction
void welcome_introduction ()
{
cout << newline;
cout << "Welcome to the Records Database Facility!";
cout << newline;
cout << newline;
cout << "Enter name to search: ";
cout << newline;
cout << newline;
cout << "Last name: "; cin >> last_name_input;
cout << "First name: "; cin >> first_name_input;
cout << newline;
}

//Compare the user input last name and first name against the database record file
void stringmatch ()
{
 //location1 and location2 are variables to receive the user's last name and first name
 string::size_type location1 = recordline.find(last_name_input, 0);
 string::size_type location2 = recordline.find(first_name_input, 0);

 if (location1 != string::npos)
    {
     if (location2 != string::npos)
      {
      cout << "Name found at database: ";
      cout << "Record " << recordnumber << " " << recordline;
      namefound = true;
      cout << newline;
      }
     } 
}

//Read the Name Database file
//Check the last name and first name inputs if found on the file (database)
void read_record_file ()
{
 if (recordfile.is_open())
   {
    while (!recordfile.eof() )
     {
      getline (recordfile, recordline);
      recordnumber = recordnumber + 1;
      stringmatch ();
     }
    if (recordfile.eof())
     {
      if (namefound == false)
       cout << "eof: Record not found on database.";
     }
    }   
 else
  {
   cout << "Error opening the file";
   recordfile.close();
  }


int main ()
{
welcome_introduction ();   
read_record_file ();

return 0;
}

C++ TUTORIAL FOR BEGINNERS: How to display characters on the screen


Objective: Displaying characters on the screen
Directive: #include <iostream>
Namespace: std
Function: main
Statements: cout, return
Output:
This is a simple C++ program.
It will display these characters on the screen.

C++ source code:

/*
PROGRAM 1: Displaying characters on the screen
AUTHOR: eternaltreasures
DATE: 2010 August 25
*/

#include <iostream>
using namespace std;
int main ()
{
cout << "This is a simple C++ program.\n";
cout << "It will display these characters on the screen.";
return 0;
}

// End of the program.


Explanations:

/*
Block of comments about the program, author, date...
*/

#include <iostream>
Preprocessor command to include the iostream file to be used for input-output operations.

using namespace std;
The contents of the namespace called std would be used. A namespace is a "container" for elements of standard C++ library.

semicolon ;
A semicolon separates statements.

int main ()
This is where the program begins to execute.

braces { }
The main function executes anything that is enclosed within these braces.

cout << "This is a simple C++ program.\n";
The cout is a statement for displaying on the screen the characters within the quotes "".
\n is for starting a new line.

return 0;
The return statement ends the execution of the main function.
0 return code means the execution is OK.

// End of the program.
A single line of comment uses two forward slashes.

Sunday, December 9, 2012

Useful US Equivalent Measurement Units, Approximates, Estimates, and Rough Conversions


These commonly used USA units of measure and their equivalents, rough estimates, and approximate values are useful in a variety of day to day applications including but not limited to:

HOME:
- cooking in the kitchen
- medicine cabinet in the bathroom
- medications and prescription drugs
- food and drink measurements
- home hobbies
- home work and assignments
- and more...

SCHOOL:
- school projects
- physics subject
- chemistry subject
- mathematics subject
- practical arts and trades subjects
- and more...

BUSINESS/COMMERCIAL:
- drugstores and pharmacies
- canteen, cafeteria, coffee shops, restaurants
- groceries and supermarkets
- shopping centres
- home hardware stores
- factories and warehouses
- manufacturing plants
- and more...

---------------------------------------------------

Note:
The symbol ~ has been used here to mean approximate.

ONE CENTIMETER (cm):
1 cm ~ 0.4 inch
1 cm ~ 2/5 inch

ONE INCH:
1 inch ~ 2 1/2 centimeters
1 inch ~ 2.5 centimetres

ADULT HUMAN BODY PARTS MEASUREMENT APPROXIMATIONS:
nail width of little finger ~ 1 centimeter
1 thumb width ~ 1 inch
1 little finger length ~ 2 inches
1 index finger length ~ 3 inches
1 palm width ~ 4 inches
from index finger to front edge of thumb ~ 5 inches
from index finger to back edge of thumb ~ 6 inches
from middle finger to back edge of thumb ~ 7 inches
from middle finger to the wrist joint ~ 8 inches
1 human foot ~ 12 inches
1 cubit (middle finger to elbow) ~ 1 1/2 foot 
1 cubit (middle finger to elbow) ~ 18 inches
1 step at normal walking pace ~ 2 feet
1 step at normal walking pace ~ 24 inches
1 arm length ~ 2 1/2 feet
1 arm length ~ 30 inches

ONE GRAM:
1 gram of water = 1 cubic centimeter (cc) of water
1 gram of water = 1 ml of water

ONE MILLILITER (ml or mL):
1 ml = 1 cc (cubic centimeter)
1 ml = 16 drops

ONE TEASPOON:
1 teaspoon ˜ 5 mL

ONE TABLESPOON:
1 tablespoon ~ 3 teaspoons
1 tablespoon ˜ 15 mL

ONE FLUID OUNCE:
1 US fluid ounce = 2 tablespoons
1 US fluid ounce = 6 teaspoons
1 US fluid ounce ~ 30 ml

ONE GILL:
1 US gill = 1/2 cup
1 US gill = 4 US fluid ounces
1 US gill = 8 tablespoons

ONE CUP:
1 cup = 16 tablespoons
1 cup ˜ 250 mL

CAN OF SODA, COLA, POP, SOFTDRINK:
1 can of soda pop softdrink ~ 1 1/2 cups
1 can of soda pop softdrink = 355 ml

ONE PINT:
1 pint = 2 cups

BOTTLED WATER:
1 bottled water 500 ml = 1/2 liter
1 bottled water 500 ml ~ 2 cups

GLASS OF WATER:
1 small glass of water ~ 1 pint
1 small glass of water ~ 2 cups
1 big glass of water ~ 2 1/2 cups

ONE QUART:
1 quart ~ 1 liter
1 quart = 2 pints
1 quart = 4 cups

ONE LITER:
1 liter ~ 1 quart
1 liter ~ 2 pints
1 liter ~ 4 cups
1 liter of water = 1 kilogram (kg.)
1 liter of water ~ 2 pounds (lbs.)

ONE GALLON:
1 gallon ~ 4 liter
1 gallon = 4 quarts
1 gallon = 8 pints
1 gallon = 16 cups
1 gallon = 32 gills

ONE PECK:
1 peck ~ 2.3 gallons liquid measure
1 peck = 2 gallons dry measure

ONE DRINKING WATER DISPENSER BOTTLE:
1 commercial drinking water dispenser bottle = 5 gallons
1 commercial drinking water dispenser bottle ~ 19 liters

ONE BUCKET:
1 bucket = 5 gallons liquid measure
1 bucket ~ 4 gallons dry measure

ONE BUSHEL:
1 bushel ~ 9 gallons liquid measure   
1 bushel = 8 gallons dry measure

ONE KEG:
1 keg (beer) = 1/2 beer barrel
1 keg (beer) = 15.5 U.S. gallon 

ONE BARREL:
1 barrel = 31.5 gallons (liquid measure)
1 barrel = 27 gallons (dry measure)
1 U.S. beer barrel = 31 U.S. gallons
1 oil barrel = 42 US gallons
1 barrel (wine) = 38 gallons (liquid measure)
1 barrel (wine) = 32.5 gallons (dry measure)

ONE DRUM (petroleum):
1 drum = 55 gallons liquid measure
1 drum = 47 gallons dry measure

ONE PIPE:
1 pipe ~ 2 drums (petroleum)
1 pipe = 3 barrels (petroleum)
1 pipe = 126 gallons (liquid measure)
 
 PICTURES:
A 5 gallon water dispenser bottle.

A 355 ml canned softdrink approximately 1 and half cup.
A 500 ml bottled water is about 2 cups.
A 710 ml pop softdrink or carbonated beverage.
A big glass is about 2 and half cups.
A cup is 250 ml approximately.
A gallon is equal to 4 quarts (approximately 4 liters).
A pint of ice cream is equal to 2 cups.
A quart of ice cream is equal to 2 pints or 4 cups.
A small glass is about 2 cups.
One cup is equal to 16 tablespoons.
One liter of vinegar is equal to 4 cups (estimate).
One tablespoon is roughly equal to 15 mL.
One teaspoon is roughly equal to 5 mL.
One US fluid ounce is equal to 2 tablespoons and approximately  30 ml.
The cubit or length from the middle finger to the elbow is close to 18 inches.
The distance from the tip of the index finger to the front edge of the thumb is 5 inches approx.
The distance from the tip of the middle finger to the wrist joint is 8 inches approximately.
The human foot is approximately 12 inches.
The index finger is about 3 inches long.
The little finger has a length of about 2.5 inches.
The nail width of the little finger is 1 cm approx.
The palm width is about 4 inches wide.
The width of the thumb is about 1 inch wide.

Saturday, November 17, 2012

SCIENCE: Energy conversion from hydroelectric power plant to the house

simple energy conversion from hydroelectric power plant to the house

Water-->Turbine-->Generator-->Transformer-->House Circuit Breaker--->House Power line-->Motor-->Electric Fan


Water

Hydropower, hydraulic power or water power is power that is derived from the force or energy of moving water


Turbine

A turbine is a kind of engine that extracts energy from a fluid and used to turn generators

From Latin turbo + binis (whirling object)


Generator

A generator converts mechanical energy into electrical energy


Transformer

An electrical device for changing the voltage of an alternating current


Circuit breaker

A circuit breaker is an automatically-operated electrical switch designed to protect an electrical circuit from damage caused by overload or short circuit


Power line

Power is transmitted through power lines then to wall sockets


Motor

A motor is a device for converting electrical energy into mechanical energy

From Latin motor = mover, "movere" = move


Electric Fan

A fan run by an electric motor used for cooling

SCIENCE: Physics - Charles' law, Gay-Lussac's law, gas law


Charles' law

Also known as the law of volumes, Gay-Lussac's law

V T curve is a straight line

At constant pressure, the volume of a fixed mass of gas varies directly with the absolute temperature

At constant volume, the gas pressure varies directly with the absolute temperature



V1/T1 = V2/T2  ---> if p = constant


p1/T1 = p2/T2  ---> if v = constant


where:

p1 = absolute pressure at point1

p2 = absolute pressure at point2

V1 = gas volume at point1

V2 = gas volume at point2

T1 = absolute temperature at point1

T2 = absolute temperature at point2



1. Problem:

Air occupies a volume of 70 L at 300 K. If the pressure remains constant, find the temperature of the air when the volume increased to 140 L.



find:

T2 = temperature of the air at V2 = 140 L


given:

p = c

V1 = 70 L

T1 = 300 K

V2 = 140 L


solution:

V1/T1 = V2/T2

70/300 = 140/T2

T2 = 300 * 140/70

T2 = 600 K

thus, direct proportion between volume and absolute temperature. The initial volume of 70 L was doubled to 140 L and therefore 300 K is also doubled giving 600 K.




2. Problem:

In a constant volume process, oxygen has a temperature of 80 C under a pressure of 4 atm. If the pressure is halved, calculate the final temperature.



find:

T2 = final temperature


given:

v = c

T1 = 80 + 273

T1 = 353 K

p1 = 4 atm

p2 = 2 atm


solution:

p1/T1 = p2/T2

4/353 = 2/T2

T2 = 353 * 2/4

T2 = 176.5 K ---> T2 also halved when p2 is halved

Thursday, November 15, 2012

SCIENCE: Physics - Mechanical work (variable force)


Work

- amount of energy transferred by a force acting through a distance

- Work can be zero even when there is a force


W = S(a b) F * dx


where:

W = mechanical work done

F = variable force applied

dx = differential distance (delta x, change in x)

S(a b) = integral from a to b

a = lower limit, initial point

b = upper limit, final point



1. Springs - as springs get stretched, the harder it is to pull


The car suspension system steel spring has a spring constant of 12 lb/in. Find the work needed to stretch from an initial amount of 2 in to a final amount of stretch of 4 in.


find:

W = work done by stretching the spring 2 in to 4 in amount of stretch


given:

k = 12 lb/in

a = 2 in

b = 4 in


solution:

The force needed to stretch the spring increases as the spring gets extended

F = kx ---> equation1


W = S(a b) F * dx


substituting,

W = S(a b) kx * dx

W = k * S(a b) x * dx

W = 12 * S(a b) x dx

W = 12/2 [x^2, (2 4)]

W = 6 * (4^2 - 2^2)

W = 6 * (16 - 4)

W = 6 * 12

W = 72 in.lb


thus,

W = 1/2 k (b^2 - a^2)  ---> for springs

SCIENCE: Physics - Mechanical work (constant force)


Work

- amount of energy transferred by a force acting through a distance

- Work can be zero even when there is a force


W = (F cos A) * d


where:

W = mechanical work done

F = constant force applied

A = angle between F and d

d = distance travelled as a result of the application of force



1. Force and distance on the same line


A toy cart is placed in a rail that is flat on a table. A pulling force of 10 N is applied resulting in a distance of 2 m travelled by the toy cart. Calculate the work done.


find:

W = work done


given:

F = 10 N

A = 0 degrees

d = 2 m


solution:

W = (F cos A) * d

W = (10 * cos 0) * 2

W = (10 * 1) * 2

W = 20 N m



2. Force is at an angle with the direction of motion


If the force is applied with an angle of 30 degrees, calculate the work done.


find:

W = work done


given:

F = 10 N

A = 30 degrees

d = 2 m


solution:

W = (F cos A) * d

W = (10 * cos 30) * 2

W = 17.3 N m



3. The rail is at an angle of 15 degreees with the table



If (in problem #2) the toy cart is moved down, calculate the work done.


find:

Wd = work done if the toy cart is moved down


given:

F = 10 N

a1 = 30 degrees, angle of the force

a2 = 15 degrees, angle of the rail

d = 2 m


solution:

reference is the rail --> direction of the displacement


A = a1 + a2

A = 30 + 15

A = 45 degrees


Wd = (F cos A) * d

Wd = (10 * cos 45) * 2

Wd = 14.1 N m



If (in problem #2) the toy cart is moved up, calculate the work done.


find:

Wu = work done if the toy cart is moved up


given:

F = 10 N

a1 = 30 degrees, angle of the force

a2 = 15 degrees, angle of the rail

d = 2 m


solution:

reference is the rail --> direction of the displacement


A = a1 - a2

A = 30 - 15

A = 15 degrees


Wu = (F cos A) * d

Wu = (10 * cos 15) * 2

Wu = 19.3 N m

Monday, November 5, 2012

C++ TUTORIAL FOR BEGINNERS: Program to calculate Circumference, Area of a Circle, and the Volume of a Sphere

The Basketball ball of the NBA has a standard dimension of 4.7 inch in radius, 9.4 inch in diameter, 29.5 inches in circumference,  22 ounces (size 7) in weight, and 7.5 - 8.5 pounds per square inch of air pressure.

Objective: Calculation of the Circumference, Area of a Circle and the Volume of a Sphere
Directive: #include <iostream>, #include <cmath>
Namespace: std
Function: main
Variables:
CircleRadius
double CircleCircumference
double CircleArea
double SphereVolume
Data types of variables: double
Statements: cout, cin, return
Input: Radius of the circle
Output:
Circumference of the Circle
Area of the Circle
Volume of the Sphere

C++ source code:

/*
PROGRAM : Circumference, Area of a Circle; Volume of a Sphere
AUTHOR: eternaltreasures
DATE: 2010 September 1
*/

#include <iostream>
#include <cmath>
using namespace std;

#define PI 3.14159
#define NEWLINE '\n'     

int main ()
{

double CircleRadius;
double CircleCircumference;
double CircleArea;
double SphereVolume;


cout << "Enter the Radius of the Circle = ";
cin >> CircleRadius;

// Circumference of a Circle
CircleCircumference = 2 * PI * CircleRadius;
cout << "Circumference of the Circle = " << CircleCircumference;
cout << NEWLINE;

// Area of a Circle
CircleArea = PI * pow(CircleRadius, 2);
cout << "Area of the Circle = " << CircleArea;
cout << NEWLINE;

// Volume of a Sphere
SphereVolume = 4 * PI/3 * pow(CircleRadius, 3);
cout << "Volume of the Sphere = " << SphereVolume;
cout << NEWLINE;

return 0;
}