Sunday, July 17, 2016

Centimeter To Kilometer Program in Rust

A simple program that I wrote that will ask the user to give length in centimeter and then it will convert into kilometer equivalent 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

kilometer.rs


// Centimeter To Kilometer 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!("\tCentimeter To Kilometer Program in Rust");
       println!("\n");

    let cm: f32 = grab_input("Give length in centimeter ")
        .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_km = cm / 100000.0;
                  
    println!("\n"); 
    println!("The length in centimeter is {:.2} cm its equivalent in kilometer(s) is {:.2} km.",cm,solve_km);
    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)
}




Centimeter To Meter Converter Using Rust

A simple program that I wrote that will ask the user to give length in centimeter and then it will convert into Meter equivalent 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

meter.rs


// Centimer To Meter 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!("\tCentimeter To Meter Program in Rust");
       println!("\n");
    let cm: f32 = grab_input("Give length in centimeter ")
        .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_meter = cm / 100.0;
                 
    println!("\n"); 
    println!("The length in centimeter is {:.2} its equivalent in meters is {:.2}.",cm,solve_meter);
    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)
}



Celsius To Fahrenheit Program in Rust

A simple program that I wrote that will ask the user the temperature Celsius and then it will convert into Fahrenheit equivalent 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

// Celsius To Fahrenheit 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!("\tCelsius To Fahrenheit Program in Rust");
       println!("\n");

    let celsius: f32 = grab_input("Give temperature in Celsius  ")
        .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_fahrenheit = (celsius * 1.8) + 32.0;
                 
    println!("\n"); 
    println!("The temperature in Celsius is {:.2} its equivalent in Fahrenheit is {:.2}.",celsius,solve_fahrenheit);
    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)
}


Fahrenheit To Celsius Program in Rust

A simple program that I wrote that will ask the user the temperature in Fahrenheit and then it will convert into Celsius equivalent 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

fahrenheit.rs

// Fahrenheit To Celsius 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!("\tFahrenheit To Celsius Program in Rust");
       println!("\n");
 
    let fahren: f32 = grab_input("Give temperature in Fahrenheit  ")
        .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_celsius = (fahren-32.0)* 5.0/9.0;
                
    println!("\n"); 
    println!("The temperature in Fahrenheit is {:.2} its equivalent in Celsius is {:.2}.",fahren,solve_celsius);
    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 Octal Converter Using 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 octal 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 Octal 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 Octal 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 Octal value of {} is {:o}.",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 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)
}