Sunday, July 17, 2016

Decimal To Hexadecimal Converter in Rust

A simple program that I wrote in Rust programming language that will ask the user to give a number and then our program will convert the number given by our user into hexadecimal equivalent.

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

// Decimal To Hexadecimal Program 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!("\tDecimal To Hexadecimal Program in Rust");
       println!("\n");

    let number: 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));

        
    println!("\n"); 
    println!("The Hexadecimal value of {} is {:X}.",number,number);
    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)
}



Decimal To Binary in Rust

A simple program that I wrote in Rust programming language that will ask the user to give a number and then our program will convert the number given by our user into binary equivalent.

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

binary.rs

// Decimal To Binary Program 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!("\tDecimal To Binary Program in Rust");
       println!("\n");

    let number: 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));

        
    println!("\n"); 
    println!("The binary value of {} is {:b}.",number,number);
    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)
}






Average of Numbers in Rust

A simple program that will compute the average value of five numbers that is being provided by the user using Rust Programming language.

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

average.js

// Average of Number Program 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!("\tAverage of Number Program in Rust");
       println!("\n");
 
    let num1 : i32 = grab_input("Enter Value No. 1 ")
        .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 num2 : i32 = grab_input("Enter Value No. 2 ")
        .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 num3 : i32 = grab_input("Enter Value No. 3 ")
        .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 num4 : i32 = grab_input("Enter Value No. 4 ")
        .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 num5 : i32 = grab_input("Enter Value No. 5 ")
        .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  solve_average = (num1+num2+num3+num4+num5) / 5;
     
    println!("\n"); 
    println!("The average of {},{},{},{} and {} is {}."
           ,num1,num2,num3,num4,num5,solve_average);
    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)
}

Square a Number in Rust

This sample program will ask the user to give a number and then it will compute its square value equivalent using Rust as our programming language.

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

square.rs

// Square a Number Program 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!("\tSquare a Number Program in Rust");
       println!("\n");
 
    let number: 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));

    let  solve_square = number * number;
     
    println!("\n"); 
    println!("The square value of {} is {}.",number,solve_square);
    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)
}


Payroll Program in Rust

In this article I would like to share with you a simple program that I wrote using Rust programming language a Payroll Program. This payroll program will ask the the numbers of day work of an employee and then the daily rate of salary of the employee. 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.





Sample Program Output


Program Listing

payroll.rs

// Payroll Program 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!("\tPayroll Program in Rust");
       println!("\n");
 
    let days_worked: f32 = grab_input("How many days worked?  ")
        .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 rate_per_day: f32 = grab_input("Rate Per Day?  ")
        .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  salary = days_worked * rate_per_day;
     
    println!("\n"); 
    println!("The salary of the employee is $ {:.2}. ",salary);
    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)
}

Product of Two Numbers in Rust

A simple program that I wrote using Rust programming language that will ask the user to give two numbers and then our program will find its product. 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.




Sample Program Output


Program Listing

product_two.rs

// Product 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!("\tProduct 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 product = value1 * value2;

    println!("\n"); 
    println!("===== DISPLAY RESULTS =====");
    println!("\n"); 
    println!("The product of {} and {} is {}. ",value1,value2,product);
    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)
}




Simple Calculator in Rust

A  simple math calculator I wrote using Rust as my programming language what does the program will do is to ask the user to give two numbers and then our program will compute for the sum, product, different and quotient of the given  numbers. I hope you will find my work useful in learning rust 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

calc.rs

// Simple Calculator 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!("\tSimple Calculator 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;

    let subtract = value1 - value2;

    let product = value1 * value2;

    let quotient = value1 / value2;

    println!("\n"); 
    println!("===== DISPLAY RESULTS =====");
    println!("\n"); 
    println!("The sum of {} and {} is {}. ",value1,value2,sum);
    println!("\n"); 
    println!("The difference between {} and {} is {}. ",value1,value2,subtract);
    println!("\n"); 
    println!("The product of {} and {} is {}. ",value1,value2,product);
    println!("\n"); 
    println!("The quotient of {} and {} is {}. ",value1,value2,quotient); 
    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)
}

Factorial of Number in Rust

This sample program will ask the user to give a number and then it will compute its factorial equivalent based on the number being provided by the user using Rust as my programming language.

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

factorial.rs

// Factorial of 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 factorial (n: i32) -> i32 {
    match n {
        0 => 1,
        _ => n * factorial(n-1)
    }
}

fn main() {
       println!("\n");
       println!("\tFactorial 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));

    println!("\n"); 
    println!("The factorial values of {} is {}.",value, factorial(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)
}

Leap Year Checker in Rust

This sample program that I wrote using Rust as my programming language will ask the user to give a year and then our program will determine whether the given year by our user is leap year or not a leap year.

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

leap_year.rs

// Leap Year 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!("\tLeap Year Checker in Rust");
       println!("\n");

    let year: i32 = grab_input("Enter a Year ")
        .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 year % 400 == 0 {
    println!("\n"); 
    println!("The year {} is a leap year.",year);
    }
 else if year % 100 == 0 {
    println!("\n"); 
    println!("The year {} is a leap year.",year);
   }
 else if year % 4 == 0 {
    println!("\n"); 
    println!("The year {} is a leap year.",year);
   }
   else {
    println!("\n"); 
    println!("The year {} is not a leap year.",year);
   }
  
  
    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)
}



Hello World in Rust

In this article I would like to share with you a very classic sample program hello world using Rust as our programming language. To give you some idea Rust programming language was developed and promote by Mozilla Foundation it is a system programming language similar to C and C++ programming languages and open source. Learning how to program in Rust is not difficult but easy to understand once you have a basic understanding on C or C++ programming.

This sample program will display hello world and welcome to rust programming message on the screen. I hope this program will give you a first hand experience how to start write a program in Rust programming language.

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

fn main() {
  println!("\n");
  println!("Hello, world!");
  println!("\n");
  println!("\t Welcome To Rust Programming");
  }