Sunday, July 17, 2016

Odd and Even Number Checker in Rust

Hello friends in this article I would like to share with you how to write a program to check if the given number by the user is odd or even number  using Rust Programming language. Yesterday I am attending a lecture in Mozilla Philippines office here in Makati City, Philippines. The talk is given by Sir Bob Reyes a Mozilla representative here in the Philippines he is discussing the Rust programming language I found his lecture interesting because Rust is designed for systems programming and best of all it is open source.

Rust is a programming language that is developed by Mozilla foundation the creator of Mozilla Firefox web browser one of the most popular and secure web browser in the world. I hope you will give a try to learn Rust.

In this program it will ask the user to give a number and then our program will determine whether the given number is odd and even.


Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

odd_even.rs

// Odd and Even Number Checker in Rust Programming language.
// Written By: Mr. Jake R. Pomperada, MAED-IT
// July 17, 2016

use std::io::{self, Write};
use std::fmt::Display;
use std::process;

fn main() {
       println!("\n");
       println!("\tOdd and Even Number Checker in Rust");
       println!("\n");

    let value: i32 = grab_input("Enter a Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));

   if value % 2 == 0 {
    println!("\n"); 
    println!("The number {} is an EVEN number.",value);
} else {
    println!("\n");
    println!("The number {} is an ODD number.",value);
   }

    println!("\n"); 
    println!("End of Program");
}

fn grab_input(msg: &str) -> io::Result<String> {
    let mut buf = String::new();
    print!("{}: ", msg);
    try!(io::stdout().flush());

    try!(io::stdin().read_line(&mut buf));
    Ok(buf)
}

fn exit_err<T: Display>(msg: T, code: i32) -> ! {
    let _ = writeln!(&mut io::stderr(), "Error: {}", msg);
    process::exit(code)
}





Addition of Two Numbers in Rust

Hello friends in this article I would like to share with you how to write a program to find the sum of two numbers  using Rust Programming language. Yesterday I am attending a lecture in Mozilla Philippines office here in Makati City, Philippines. The talk is given by Sir Bob Reyes a Mozilla representative here in the Philippines he is discussing the Rust programming language I found his lecture interesting because Rust is designed for systems programming and best of all it is open source.

Rust is a programming language that is developed by Mozilla foundation the creator of Mozilla Firefox web browser one of the most popular and secure web browser in the world. I hope you will give a try to learn Rust.

In this program it will ask the user to give to two numbers and then our program will find the sum of the two numbers provided by the user.

Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.


My mobile number here in the Philippines is 09173084360.



Sample Program Output



Program Listing

add.rs

// Addition of Two Numbers in Rust Programming language.
// Written By: Mr. Jake R. Pomperada, MAED-IT
// July 17, 2016

use std::io::{self, Write};
use std::fmt::Display;
use std::process;

fn main() {
       println!("\n");
       println!("\tAddition of Two Numbers in Rust");
       println!("\n");

    let value1: i32 = grab_input("Enter First Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));

    let value2: i32 = grab_input("Enter Second Number ")
        .unwrap_or_else(|e| exit_err(&e, e.raw_os_error().unwrap_or(-1)))
        .trim()
        .parse()
        .unwrap_or_else(|e| exit_err(&e, 2));


    let sum = value1 + value2;
     
    println!("\n"); 
    println!("The sum of {} and {} is {}. ",value1,value2,sum);
    println!("\n"); 
    println!("End of Program");
}

fn grab_input(msg: &str) -> io::Result<String> {
    let mut buf = String::new();
    print!("{}: ", msg);
    try!(io::stdout().flush());

    try!(io::stdin().read_line(&mut buf));
    Ok(buf)
}

fn exit_err<T: Display>(msg: T, code: i32) -> ! {
    let _ = writeln!(&mut io::stderr(), "Error: {}", msg);
    process::exit(code)
}




Friday, July 15, 2016

Addition of Five Numbers in AngularJS

In this article I would like to share with you a sample program that I wrote using AngularJS one of the most popular javascript framework today. What does the program will do is to ask the user to give five numbers and then it will find the sum of the five numbers that is being provided by the user. What is good about this program is that it uses buttons to add the sum of numbers and clear button to clear the content of the text box. I hope you will find my work useful.

Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

<html>
<head> 
<title> Avergage of Five Numbers in AngularJS </title>
</head>
<style>
p,h3 {
   color:blue;
     display: inline-block;
    float: left;
    clear: left;
    width: 380px;
    text-align: left;
   font-family: "arial";
   font-style: bold;
   size: 16;
  };
  
  
 </style>
<script type="text/javascript" src="angular.js"></script>
<body bgcolor="lightgreen">
<script>
var app = angular.module('myApp', []);

app.controller('MainCtrl', function($scope) {
$scope.add=function(a,b,c,d,e)
{
  $scope.result=parseInt(a)+parseInt(b)+parseInt(c)+parseInt(d)+parseInt(e);
}

$scope.clear_all=function()
{
  $scope.a = null;
   $scope.b = null;
   $scope.c = null;
   $scope.d = null;
   $scope.e = null;
    
}


});

</script>
<br><br>
<h3>Addition of Five Numbers in AngularJS</h3>
<div ng-app="myApp">
<div ng-controller="MainCtrl">
    <p>Enter a Value in Item No. 1 :
        <input type="text" ng-model="a" placeholder="enter a number" autofocus size="15"/>
    </p><br>
    
   <p>Enter a Value in Item No. 2 :
        <input type="text" ng-model="b" placeholder="enter a number" size="15"/>
    </p><br>
<p>Enter a Value in Item No. 3 :
        <input type="text" ng-model="c" placeholder="enter a number" size="15"/>
    </p><br>
    
    <p>Enter a Value in Item No. 4 :
        <input type="text" ng-model="d" placeholder="enter a number" size="15"/>
    </p><br>
<p>Enter a Value in Item No. 5 :
        <input type="text" ng-model="e" placeholder="enter a number" size="15"/>
    </p><br> 
      <br>
<br><br>
<br><br>
     <p><input type="button" ng-click="add(a,b,c,d,e)" value="ADD">
&nbsp;
 <input type="button" ng-click="clear_all(this)" value="CLEAR"></p>
<br><br>
<p> Total Sum is  {{result}}. </p>
<div>
</div>
</html>




Sunday, July 10, 2016

Sum of Three Numbers in Java

A simple program that I wrote in Java that will ask the user to give three integer numbers and then our program will find the total sum of three numbers based of the given values by our user. 

Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing


sum_three.java


package hello;


import java.util.Scanner;
public class sum_three {
 public static void main(String args[]){
 
 Scanner input = new Scanner(System.in);
    
       int sum=0;
       int a=0,b=0,c=0;
    
       System.out.println("Sum of Three Numbers in Java");
       System.out.println();
       System.out.print("Enter First Number : ");
       a = input.nextInt();
       System.out.print("Enter Second Number : ");
       b = input.nextInt(); 
       System.out.print("Enter Third Number : ");
       c = input.nextInt(); 
     
       sum = (a+b+c);
       
       System.out.println();
       System.out.println("The sum of " +a + "," + b + " and " + 
           c + " is " + sum + ".");
       System.out.println();
       System.out.println("\t End of Program");
 
 }
 
}



Sum of Three Numbers Using C++

A simple program that I wrote using C++ as my programming language that will compute the sum of three numbers using functions and structure. The code is very simple and easy to understand.

Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing

#include <iostream>

using namespace std;

struct num {
     int value[3];
 };


int addition(num a)
 {
     return(a.value[0] +
            a.value[1] +
            a.value[2]);
 }



 main() {
        num b;
        cout << "\t Sum of Three Numbers ";
        cout << "\n\n";
        cout << "Enter three numbers : ";
        cin >> b.value[0] >> b.value[1] >> b.value[2];
        cout << "\n\n";
        cout << "The sum is "  <<addition(b);
        cout << "\n\n";
        system("pause");
 }

Product Total Cost in C++

A simple program that I wrote in C++ that will compute the product total cost. I used this program as an example in my programming class in college before I work in the industry as software engineer. I hope you will find my work useful.


Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Program Listing

#include <iostream>
#include <iomanip>


using namespace std;


struct item {

    string name,type;
    int quantity;
    float price;
};

main() {
     item product;
     float solve=0.00;
     cout << "\n\tProduct Total Cost 1.0";
     cout << "\n\n";
     cout << "Enter Product Name         : ";
     getline(cin,product.name);
     cout << "Enter Product Description  : ";
     getline(cin,product.type);
     cout << "Enter Product Quantity     : ";
     cin >> product.quantity;
     cout << "Enter Product Price/Pcs    : ";
     cin >> product.price;

     solve = (product.quantity * product.price);

     cout << fixed << setprecision(2);

     cout << "\n  === Report ===";
     cout << "\n\n";
     cout << "\nProduct Name   : " << product.name;
     cout << "\nProduct Type   : " << product.type;
     cout << "\nQuantity       : " << product.quantity;
     cout << "\nPrice          : " << product.price;
     cout << "\n\n Total Cost  : $ " << solve;
     cout << "\n\n";
     system("pause");
}


Currency Converter in C++

In this article I would like to share with you a sample program that I wrote 6 years ago in my class in C++ programming I called this program currency converter in C++. I will ask the user amount of money in US dollars and then it will convert into Philippine Peso equivalent using structure as my data structure in C++. I hope you will find my work useful in learning C++ programming.

Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

#include <iostream>
#include <iomanip>

using namespace std;

const

int us_to_pesos = 43;

 struct emp {
    string name,position;
    char gender;
    float salary;
};

main() {

    emp person;

    float solve=0.00;

    cout << "\t US Dollar To Philippine Peso Conversion ";
    cout << "\n\n";
    cout << " Employee's Name   :  ";
    getline(cin,person.name);
    cout << " Job Description   :  ";
    getline(cin,person.position);
    cout << " Employee's Gender :  ";
    cin >> person.gender;
    cout << " Employee's Salary : $ ";
    cin >> person.salary;

      solve = (person.salary * us_to_pesos);

    cout << "\n\n";
    cout << "\n ====== Salary Report =====";
    cout <<"\n\n";
    cout << "\n Name    : " << person.name;
    cout << "\n Job     : " << person.position;
    cout << "\n Gender  : " << person.gender;
    cout << "\n\n";
    cout << fixed << setprecision(2);
    cout << "\n Salary in $ US Dollar     : $   " << person.salary;
    cout << "\n Salary in Philippine Peso : Php " << solve;
    cout << "\n\n";
    cout << "\t End of Program";
    cout << "\n\n";
    system("pause");
}


Compare Two Strings in Java

In this article I would like to share with you a sample program that I wrote in Java to compare the two string if they are the same or the first string is greater than the second string or vice versa. One of the things that I love in Java is that there are many built in functions that makes programming much easier compared to other programming language. I hope you will find my work useful.

Add me at Facebook my address  is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.


Sample Program Output



Program Listing


Compare_String.java

package hello;


import java.util.Scanner;

public class Compare_String {

public static void main(String args[]) {

String str1, str2;
Scanner input = new Scanner(System.in);
System.out.println("Compare Two String in Java");
System.out.println();
System.out.print("Enter First String : ");
str1 = input.nextLine();
System.out.print("Enter Second String : ");
str2 = input.nextLine();

if (str1.compareTo(str2) > 0)
{
System.out.println();
System.out.println("The first string is greater than the second string.");
}
else if (str1.compareTo(str2) < 0)
{
System.out.println();
System.out.println("The first string is smaller than the second string.");
}
else 
{
System.out.println();
System.out.println("Both Strings are equal.");
}
System.out.println();
System.out.println("\t End of Program");
}
}