Sunday, July 10, 2016

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");
}
}


Saturday, July 2, 2016

Alert Dialog Box in Android

When I started learning how to create an application in Android I came across of idea to add quit button which allows our user to quit the program within our application in this article I will complete the functionality of our application Sum and Product Program in Android. I will added the alert or quit dialog box that will ask the user if the user want to quit or return to our program. The code is very simple and easy to understand I enjoy every moment of it working with this simple application program in Android I hope you will find my work useful too.

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

MainActivity.java

package com.example.servo.add;

import android.view.View;
import android.widget.EditText;
import android.support.v7.app.ActionBarActivity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.content.Context;

public class MainActivity extends ActionBarActivity {

    final Context context = this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

        public void quit(View arg0) {

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    context);

             alertDialogBuilder.setTitle("Quit Program?");

                alertDialogBuilder
                    .setMessage("You want to quit program?")
                    .setCancelable(false)
                    .setPositiveButton("Yes",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                                    int id) {

                                    MainActivity.this.finish();
                                }
                            })
                    .setNegativeButton("No",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog,
                                                    int id) {
                                    dialog.cancel();
                                }
                            });

            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }

    public void sum_and_product(View view) {

        EditText editText2 = (EditText) findViewById(R.id.editText2);
        EditText editText3 = (EditText) findViewById(R.id.editText3);
        EditText editText4 = (EditText) findViewById(R.id.editText4);
        EditText editText = (EditText) findViewById(R.id.editText);


        int first = Integer.valueOf(editText2.getText().toString());
        int second = Integer.valueOf(editText4.getText().toString());

        int add = first + second;

        int product = first * second;


        editText3.setText(Integer.toString(add));
        editText.setText(Integer.toString(product));
    }


    public void clear(View view) {
        EditText editText2 = (EditText) findViewById(R.id.editText2);
        EditText editText3 = (EditText) findViewById(R.id.editText3);
        EditText editText4 = (EditText) findViewById(R.id.editText4);
        EditText editText = (EditText) findViewById(R.id.editText);

        editText2.setText("");
        editText2.requestFocus();
        editText2.setText("");
        editText3.setText("");
        editText4.setText("");
        editText.setText("");

    }

}


activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"
    android:id="@+id/myRelativeLayout"
    android:background="#ff1dffb7">


    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText2"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:inputType="number"
        android:layout_above="@+id/textView2"
        android:layout_alignLeft="@+id/editText4"
        android:layout_alignStart="@+id/editText4"
        android:textColor="#ff0918ff" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText3"
        android:inputType="number"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:clickable="false"
        android:cursorVisible="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_alignBottom="@+id/textView3"
        android:layout_alignLeft="@+id/editText"
        android:layout_alignStart="@+id/editText"
        android:textColor="#ff142eff" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText4"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:inputType="number"
        android:textColor="#ff1024ff"
        android:layout_below="@+id/textView"
        android:layout_alignRight="@+id/button2"
        android:layout_alignEnd="@+id/button2" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ok"
        android:id="@+id/button"
        android:onClick="sum_and_product"
        android:textStyle="bold"
        android:layout_alignTop="@+id/button2"
        android:layout_alignRight="@+id/textView3"
        android:layout_alignEnd="@+id/textView3" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Clear"
        android:id="@+id/button2"
        android:onClick="clear"
        android:textStyle="bold"
        android:layout_below="@+id/editText"
        android:layout_alignRight="@+id/textView5"
        android:layout_alignEnd="@+id/textView5"
        android:layout_marginTop="37dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="First Number"
        android:id="@+id/textView"
        android:textStyle="bold"
        android:layout_marginTop="50dp"
        android:layout_below="@+id/textView5"
        android:layout_alignLeft="@+id/textView4"
        android:layout_alignStart="@+id/textView4"
        android:textColor="#ff0e16ff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Second Number"
        android:textStyle="bold"
        android:id="@+id/textView2"
        android:layout_below="@+id/textView"
        android:layout_alignLeft="@+id/textView"
        android:layout_alignStart="@+id/textView"
        android:layout_marginTop="42dp"
        android:textColor="#ff1121ff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="The product is"
        android:textStyle="bold"
        android:id="@+id/textView6"
        android:layout_marginTop="34dp"
        android:textColor="#ff0a1eff"
        android:layout_below="@+id/textView3"
        android:layout_alignLeft="@+id/textView3"
        android:layout_alignStart="@+id/textView3" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="The total sum is"
        android:textStyle="bold"
        android:id="@+id/textView3"
        android:layout_centerVertical="true"
        android:layout_alignLeft="@+id/textView2"
        android:layout_alignStart="@+id/textView2"
        android:textColor="#ff1624ff" />


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sum and Product of Two Numbers"
        android:textStyle="bold"
        android:textSize="18dp"
        android:textColor="#ff0d19ff"
        android:id="@+id/textView4"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:shadowColor="#ffac0dff" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Created By: Mr. Jake R. Pomperada"
        android:textSize="16dp"
        android:textColor="#ff0c26ff"
        android:textStyle="bold"
        android:id="@+id/textView5"
        android:layout_marginTop="38dp"
        android:layout_below="@+id/textView4"
        android:layout_centerHorizontal="true" />

    <EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/editText"
        android:inputType="number"
        android:width="100dp"
        android:textSize="25dp"
        android:textStyle="bold"
        android:clickable="false"
        android:cursorVisible="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_alignBottom="@+id/textView6"
        android:layout_alignRight="@+id/button2"
        android:layout_alignEnd="@+id/button2"
        android:textColor="#ff0f27ff" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Quit"
        android:id="@+id/button3"
        android:onClick="quit"
        android:layout_marginTop="20dp"
        android:textStyle="bold"
        android:layout_below="@+id/button"
        android:layout_toRightOf="@+id/button"
        android:layout_toEndOf="@+id/button" />
</RelativeLayout>


strings.xml

<resources>
<string name="app_name">Sum and Products</string>
<string name="action_settings">Settings</string>
</resources>


AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.servo.add" >

    <application
        android:allowBackup="true"
        android:title="Sum and Product of Two Numbers"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>