Sunday, December 11, 2016

Palindrome Checker in C#

In this article I would like to share with you a simple program that will ask the user to give a word or a string and then our program will check if the given word or a string is a palindrome or not a palindrome. I am using C# as my programming language in this sample program. Thank you.

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

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output


Program Listing

using System;

namespace palindrome_checker
{
    class palindrome_check
    {
        static void Main(string[] args)
        {
            string string_given, reverse_string = "";
            string string_upper;
            Console.Write("\n\n");
            Console.Write("\t    Palindrome Checker in C#");
            Console.Write("\n\n\n");
            Console.Write("\tGiven Any Word or String : ");
            string_given = Console.ReadLine();
            for (int a = string_given.Length - 1; a >= 0; a--) 
            {
                reverse_string += string_given[a].ToString();
            }

            string_upper = reverse_string.ToUpper();

            if (reverse_string == string_given)
            {
                Console.Write("\n\n");
                Console.WriteLine("\tThe given word or a string {0} is a Palindrome.",string_upper);
            }
            else
            {
                Console.Write("\n\n");
                Console.WriteLine("\tThe given word or a string {0} is Not a Palindrome.",string_upper);
            }
            Console.Write("\n\n");
            Console.Write("\tThank You For Using This Software.");
            Console.Write("\n\n");
            Console.ReadKey();
        }
    }
}





Factorial Solver in C#

To all my visitors and followers of my website thank you for visiting even though I'm not earning any money here but still I want to spread the message to share the knowledge in computer programming to all. Anyway in this article I would like to share with you a sample program that I used using C# to accept a number from our user and then our program will compute the factorial equivalent of the given number by our user. The code is very short and easy to understand.

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

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace factorial
{
    class factorial
       { 
           /* Program : Factorial Solver                       */
           /* Author  : Mr. Jake R. Pomperada, MAED-IT         */
           /* Date    : Noverber 26, 2016  Saturday  10:59  AM  */
           /* Tools   : C#                                     */

        static void Main(string[] args)
        {
            int num=0, a=0, fact = 1;
            Console.Write("\n\n");
            Console.Write("  ===== FACTORIAL SOLVER ===== ");
            Console.Write("\n\n");
            Console.Write("Give a Number : ");
            num = int.Parse(Console.ReadLine());
            for (a= num; a >= 2; a--){
                fact *= a;
            }
            Console.Write("\n\n");
            Console.Write("The Factorial Values of {0} is {1}.", num, fact);
            Console.Write("\n\n");
            Console.Write("  End of Program ");
            Console.Write("\n\n");
            Console.ReadLine();
        }
    }
}







Saturday, December 3, 2016

Fractional Knapsack Algorithm in C#

Hi there in this article I would like to share with you the code that is written by a close friend of mine, a fellow software engineer and Expert C# developer Mr. Alfel Benvic G. Go. Thank you very much Sir Bon for sharing your code in your website to share the knowledge to other developers around the world.  


In this article Sir Bon share his sample program that is called Fractional Knapsack Algorithm written entirely in C# programming language.

According to Wikipedia.org Factional Knapsack Program is defined as In theoretical computer science, the continuous knapsack problem (also known as the fractional knapsack problem) is an algorithmic problem in combinatorial optimization in which the goal is to fill a container (the "knapsack") with fractional amounts of different materials chosen to maximize the value of the selected materials. It resembles the classic knapsack problem, in which the items to be placed in the container are indivisible; however, the continuous knapsack problem may be solved in polynomial time whereas the classic knapsack problem is NP-hard.[1] It is a classic example of how a seemingly small change in the formulation of a problem can have a large impact on its computational complexity.

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

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.



Sample Program Output










Number Counter in C#

Hi there in this article I would like to share with you the code that is written by a close friend of mine, a fellow software engineer and Expert C# developer Mr. Alfel Benvic G. Go. Thank you very much Sir Bon for sharing your code in your website to share the knowledge to other developers around the world.  


In this article Sir Bon share his sample program that is called Number Counter written in C# programming language. Kindly see the problem description below.

Problem

Write a program that reads in an array of type Int32. You may assume that there are 16 entries in the array. Your program determines how many entries are used. The output is to be a two-column list. The first column is a list of the distinct array elements; the second column is the count of the number of occurrences of each element. The list should be sorted on entries in the first column, largest to smallest.

Note:

• Variables are preferred to be of type Int32 for ease and convenience.
• You might need to create some helper functions to at least easily solve the problem.

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

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com


My mobile number here in the Philippines is 09173084360.



Sample Program Output



Program Listing

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NumberCounter
{
    class Program
    {
        private static Int32[] numArr = new Int32[16];

        public static void paxNum(Int32[] x)
        {
            Int32 n = x.Length, temp;
            for (Int32 i = 1; i < n; i++)
            {
                for (int j = 0; j < n - i; j++)
                {
                    if (x[j] < x[j + 1])
                    {
                        temp = x[j];
                        x[j] = x[j + 1];
                        x[j + 1] = temp;
                    }
                }
            }
        }

        public static void countNumbers(Int32[] elements)
        {
            Int32 number, count_num;
            String compOne, compTwo;

            paxNum(elements);

            for (Int32 i = 0; i < elements.Length; i++)
            {
                number = 0;
                count_num = 1;
                compOne = "" + elements[i];
                for (int j = 0; j < elements.Length; j++)
                {
                    compTwo = "" + elements[j];
                    if (j >= i)
                    {
                        if (compOne.Equals(compTwo) && j != i)
                        {
                            count_num++;
                        }
                    }
                    else if (compOne.Equals(compTwo))
                    {
                        number = 1;
                    }
                }

                if (number != 1)
                {
                    Console.WriteLine(" " + elements[i] + "\t-    " + count_num);
                }
            }
        }


        static void Main(string[] args)
        {
            Int32 i, num;
            Console.WriteLine("Enter 16 numbers  [duplicates allowed]     ");

            for (i = 0; i < 16; i++)
            {
                Console.Write("Enter a number" + "   " + "[ " + (i + 1) + " ]:" + "  ");
                num = Convert.ToInt32(Console.ReadLine());
                numArr[i] = num;
            }
            Console.WriteLine("\n N           COUNT");
            countNumbers(numArr);
            Console.ReadLine();
        }
    }
}

Round Robin Scheduling in C#

Hi there in this article I would like to share with you the code that is written by a close friend of mine, a fellow software engineer and Expert C# developer Mr. Alfel Benvic G. Go. Thank you very much Sir Bon for sharing your code in your website to share the knowledge to other developers around the world.  

In this article Sir Bon share with us a Round Robin Scheduling program that he wrote in C#.  Here is the meaning of Round Robin Scheduling according to Wikipedia.org. Round-robin (RR) is one of the algorithms employed by process and network schedulers in computing. As the term is generally used, time slices (also known as time quanta) are assigned to each process in equal portions and in circular order, handling all processes without priority (also known as cyclic executive). Round-robin scheduling is simple, easy to implement, and starvation-free. Round-robin scheduling can also be applied to other scheduling problems, such as data packet scheduling in computer networks. It is an operating system concept.

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

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.


Sample Program Output



Login System With Three Attempts in C# and Microsoft Access

Hi there in this article I would like to share with you the code that is written by a close friend of mine, a fellow software engineer and Expert C# developer Mr. Alfel Benvic G. Go. Thank you very much Sir Bon for sharing your code in your website to share the knowledge to other developers around the world.  

About the code it is written in C# and the backend is Microsoft Access. Why this code is different from other login system is that it disable the account of the user if the user give wrong username and password three times. If the user successfully login for example in the morning our program will greet the user good morning, the same in the afternoon and evening. In addition he also added administration page to enable the disable user account, it can also add, edit, delete and view user account as well.

I hope you will find the work of Mr. Go useful in your learning C# database development.

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

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.







Sample Program Output





Login With Username Display In PHP and MySQL

I has been a while since I updated my website because of my heavy and  very hectic work schedule. Anyway guys I'm back in this article I would like to share with you a login system that is database driven in PHP and MySQL. This login system will identify the user's name after the user successfully login to the system by displaying the name of the user in the welcome page. Actually this problem it takes a while for me to solve this one it is a very simple SQL query just to retrieve the name of the user in the database I hope you will like my work. Feel free to use my code in your project that uses PHP and MySQL.  In this article I include the complete source code and it's complete database and table structure. Thank you.

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

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.
















Sample Program Output



Database and Table Structure


SQL Dumb File

users.sql

-- phpMyAdmin SQL Dump
-- version 4.5.1
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 28, 2016 at 11:42 AM
-- Server version: 10.1.16-MariaDB
-- PHP Version: 5.6.24

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `login`
--

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

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` varchar(200) NOT NULL,
  `password` varchar(200) NOT NULL,
  `lastname` varchar(200) NOT NULL,
  `firstname` varchar(200) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `password`, `lastname`, `firstname`) VALUES
(1, 'jake', 'jake', 'POMPERADA', 'JAKE'),
(2, '123', '123', 'POMPERADA', 'JACOB SAMUEL'),
(3, 'iya', 'iya', 'POMPERADA', 'JULIANNA RAE'),
(4, 'allie', 'allie', 'POMPERADA', 'MA. JUNALLIE'),
(5, 'bill', 'bill', 'GATES', 'WILLIAM'),
(6, 'peter', 'peter', 'NORTON', 'PETER');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


Program Listing

connect_to_database.php


<?php
mysql_connect("localhost","root","") or die(mysql_error()); 
mysql_select_db("login");
?> 


home.php

<?php
include 'connect_to_database.php'; //connect the connection page

if(empty($_SESSION)) // if the session not yet started 
   session_start();

if(!isset($_SESSION['username'])) { //if not yet logged in
   header("Location: login.php");// send to login page
   exit;
?>
<html>
<body>
<style>
body {
    background-color: lightgreen;
    font-family:arial;
    font-size:20px;
    }
input, button, select, option, textarea {
    font-size: 100%;
}
</style>
<br>
<H2> Main Page </H2>
<br>
Welcome  <b> <?php echo $_SESSION['firstname']. " ".$_SESSION['lastname']."."; ?>  </b>
<br><br>
 <a href="logout.php">Logout</a> 
</body>
</html> 

login.php


<?php
include 'connect_to_database.php'; //connect the connection page
if(empty($_SESSION)) // if the session not yet started 
   session_start();


if(isset($_SESSION['username'])) { // if already login
   header("location: home.php"); // send to home page
   exit; 
}

?>
<html>
<head></head>
<body>
<style>
body {
    background-color: lightgreen;
    font-family:arial;
    font-size:20px;
}
   input, button, select, option, textarea {
    font-size: 100%;
}

</style>
<br>
<h2> Login System </h2>
<form action = 'login_process.php' method='POST'>
  Enter   Username:   &nbsp;
 <input type="text" name="username" />  <br><br>
    Enter Password: &nbsp;
 <input type="password" name="password" />
<br> <br>
<input type = "submit" name="submit" value="Ok" />  
</form>
</body>
</html>

login_process.php



<html>
<body>
<style>
body {
    background-color: lightgreen;
    font-family:arial;
    font-size:20px;
}
</style>
<?php
error_reporting(0);
include 'connect_to_database.php'; //connect the connection page
  
if(empty($_SESSION)) // if the session not yet started 
   session_start();
if(!isset($_POST['submit'])) { // if the form not yet submitted
   header("Location: login.php");
   exit; 
}
//check if the username entered is in the database.
$test_query = "SELECT * FROM users WHERE username = '".$_POST[username]."'";
$query_result = mysql_query($test_query);

// query to get the users lastname and firstname to be display in the main page
$test_query2 = "SELECT lastname,firstname FROM users WHERE  username = '".$_POST[username]."'";
$query_result2 = mysql_query($test_query2);

//conditions
if(mysql_num_rows($query_result)==0) {
//if username entered not yet exists
    echo "<font name='arial'> <font size='5'>";
    echo "<br>";
    echo "The username that you have given is invalid. Please try again.";
    echo "<br><br>";
    echo "<a href='logout.php'>Return To Login Page</a> " ;
    echo "</font></font>";
}else {
//if exists, then extract the password.
    while($row_query = mysql_fetch_array($query_result)) {
        // check if password are equal
        if($row_query['password']==$_POST['password']){
        
        while($row_query2 = mysql_fetch_array($query_result2)) {
  
            $_SESSION['username'] = $_POST['username'];
            // This two line of code will able us to retrieve the lastname
                 // and firstname of the user we just login.
                 $_SESSION['lastname'] = $row_query2['lastname'];
            $_SESSION['firstname']= $row_query2['firstname'];
                 header("Location: home.php");
                 exit;
            }  
        } else{ // if not a valid user  
            echo "<br>";
            echo "<h2> Invalid Password !!! Try Again </h2>"; 
            echo "<br>";
            echo "<font name='arial'> <font size='5'>";
            echo "<a href='logout.php'>Return To Login Page</a> " ;
            echo "</font></font>";
        }
    }
}
?>

</body>
</html>


logout.php

<?php
session_start();
unset($_SESSION['username']);
session_destroy();

header("Location: login.php");
exit;
?>