Saturday, December 3, 2016

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;
?>





Saturday, November 26, 2016

Multiplication Table in C#

In this article I would like to share with you I simple program that will generate a multiplication table using C# programming language. 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;

namespace multiplication_table
{
    class multiplication_table
    {
        static void Main(string[] args)
        {
            int a = 2;
            int b = 1;
            int num=0;

            System.Console.Write("\n\n");
            System.Console.Write("  ===== MULTIPLICATION TABLE ===== ");
            System.Console.Write("\n\n");
            Console.Write("    ");

            while (a <= 10)
            {
                num = (a * b);
                Console.Write(num.ToString());
                switch (num.ToString().Length)
                {
                    case 1:
                        Console.Write("   ");
                        break;
                    case 2:
                        Console.Write("  ");
                        break;
                    case 3:
                        Console.Write(" ");
                        break;
                    default:
                        break;
                }
                if (a != 10)
                {
                    a = a + 1;
                }
                else if (b < 10)
                {
                    Console.WriteLine();
                    a = 1;
                    b = b + 1;
                }
                else break;
            }
            Console.Write("\n\n");
            Console.Write("\t   End of Program");
            Console.Write("\n\n");
            Console.ReadLine();
        }
    }
}



Number of Digits in C#

Hi there in this article I would like to share with you a sample program that will ask the user to give a number and then our program will count how many digits that can be found in the given number by our user. The code uses while loop statement and it is very easy to understand and use.

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 multiplication_table
{
    class multiplication_table
    {
        /* Program : Number of Digits                       */
        /* Author  : Mr. Jake R. Pomperada, MAED-IT         */
        /* Date    : Noverber 24, 2016  Thursday  10:12 AM  */
        /* Tools   : C#                                     */

        static void Main(string[] args)
        {

            int num=0,original_value=0, count_num = 0;
            Console.Write("\n\n");
            Console.Write("  ===== NUMBER OF DIGITS ===== ");
            Console.Write("\n\n");
            Console.Write("Give a Number : ");

            num= int.Parse(Console.ReadLine());

            original_value = num;
            while (num != 0)
            {
                num /= 10;
                count_num++;
            }
            Console.Write("\n\n");
            Console.WriteLine("The number of digits in {0} is {1}." ,original_value,count_num);
            Console.Write("\n\n");
            Console.Write("  End of Program ");
            Console.Write("\n\n");
            Console.ReadLine();
        }
    }
}



Find Odd Numbers in C#

Here this article I would like to share with you a very simple program that I wrote using C# as my programming language that will ask the user to give a number and then our program will generate the list of odd number based on the given number by our user. I hope you will find my work useful in learning how to program in C#. 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

odd.cs

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

namespace multiplication_table
{
    class multiplication_table
    {    
        /* Program : Find Odd Numbers                               */
        /* Author  : Mr. Jake R. Pomperada, MAED-IT         */
        /* Date    : Noverber 24, 2016  Thursday  10:12 AM  */
        /* Tools   : C#                                                            */

        static void Main(string[] args)
        {

            int num = 0;
            Console.Write("\n\n");
            Console.Write("  ===== FIND ODD NUMBERS ===== ");
            Console.Write("\n\n");
            Console.Write("Give a Number : ");

            num= int.Parse(Console.ReadLine());
            Console.Write("\n");
            Console.Write("\t ===== LIST OF ODD NUMBERS ===== ");
            Console.Write("\n\n");
            for (int a = 0; a <= num; a++)
            {
                if (a % 2 !=0)
                {
                    Console.Write(" {0} ",a);
                }
            }
            Console.Write("\n\n");
            Console.Write("\t       End of Program     ");
            Console.Write("\n\n");
            Console.ReadLine();
        }
    }
}





Square and Cube a Number in C#

In this article I would like to share with you a very simple program that I wrote using C# that will ask the user to give a number and then our program will compute the square and cube equivalent of the number based on the given number by our user.

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 square_cube
{
    class square_cube
    {
        /* Program : Square and Cube Numbers                */
        /* Author  : Mr. Jake R. Pomperada, MAED-IT         */
        /* Date    : Noverber 24, 2016  Thursday  11:20 AM  */
        /* Tools   : C#                                     */

        static void Main(string[] args)
        {

            int num = 0,square=0,cube=0;
            Console.Write("\n\n");
            Console.Write("  ===== SQUARE AND CUBE NUMBERS ===== ");
            Console.Write("\n\n");
            Console.Write("Give a Number : ");

            num= int.Parse(Console.ReadLine());
            Console.Write("\n");
            Console.Write("===== DISPLAY RESULTS ===== ");
            Console.Write("\n\n");
            while (num != 0)
            {
                square = num * num;
                cube = num * num * num;
                Console.Write("The Square of {0} is {1} and Cube of {0} is {2}.",num, square, cube);
                break;
            } 
            Console.Write("\n\n");
            Console.Write("     End of Program     ");
            Console.Write("\n\n");
            Console.ReadLine();
        }
    }
}