Wednesday, February 15, 2017

Accessing Arrays and Pointers in C

In this article I would like to share with you a sample program that I wrote using C language that will ask the user to give five numbers and then our program will display the list of number being provided by our user using arrays and pointers as our data structure.

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

/* Author: Mr. Jake R. Pomperada,MAED-IT */
/* Date  : February 15, 2017             */
/* Language : C                          */

#include <stdio.h>

int main()
{
    int data[5], a=0;
    printf("\n\n");
    printf("\n\tACCESS ARRAYS AND POINTERS IN C");
    printf("\n\n");
    printf("Give Elements : ");
     for (a=0; a<5; ++a) {
        scanf("%d",data+a);
        }
    printf("\n\n");
    printf("List of Values you have given ");
    printf("\n\n");
      for (a=0; a<5; ++a) {
            printf("%d\n",*(data+a));
     }
    printf("\n\n");
    printf("\n\t   END OF PROGRAM");
    printf("\n\n");
}



Pyramid of Numbers in C

In this article I would like to share with you a sample program that will display a pyramid of numbers image using C as my programming language it uses three for loop statements in order to achieve the pyramid image. I am using CodeBlocks as my text editor and Dev C++ as my C and C++ compiler.

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

/* Author: Mr. Jake R. Pomperada,MAED-IT */
/* Date  : February 15, 2017             */
/* Language : C                          */

#include <stdio.h>

int main()
{
    int a=0,b=0,c=0;

    printf("\n\n");
    printf("\n\tPYRAMID OF NUMBERS IN C");
    printf("\n\n");

    for (a=1; a<=9; a++) {
        for (c=a; c<=9; c++)  {
            printf("  ");
        }
        for (b=1; b<=a; b++) {
            printf(" %2d ",b);
        }
        printf("\n");
    }
    printf("\n\n");
    printf("\n\t   END OF PROGRAM");
    printf("\n\n");
}


Tuesday, February 14, 2017

Binary To Octal Converter in C

Here is a simple program that I wrote using C as my programming language that will ask the user to give binary number and then our program will convert the given binary number into octal equivalent.

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

#include <stdio.h>
#include <math.h>

int Binary_Octal(long long binaryNumber)
{
    int octalNumber = 0, decimalNumber = 0, i = 0;

    while(binaryNumber != 0)
    {
        decimalNumber += (binaryNumber%10) * pow(2,i);
        ++i;
        binaryNumber/=10;
    }

    i = 1;

    while (decimalNumber != 0)
    {
        octalNumber += (decimalNumber % 8) * i;
        decimalNumber /= 8;
        i *= 10;
    }

    return octalNumber;
}

int main()
{
    long long binaryNumber;
    printf("\n==============================");
    printf("\nBinary To Octal Converter in C");
    printf("\n==============================");
    printf("\n\n");
    printf("Give a value in Binary : ");
    scanf("%lld", &binaryNumber);
    printf("\n\n");
    printf("The result is %lld in Binary = %d in Octal Value.", binaryNumber, Binary_Octal(binaryNumber));
    printf("\n\n");
    printf("THANK YOU FOR USING THIS PROGRAM");
    printf("\n\n");
}






Password Security in C

Hi guys in this article I would like to share with you a sample program that I wrote that will ask the user to give a password and check if the given password is valid or not. What is good about this program it does not display the password while the user is type it instead it display the asterisk symbol in order to hide the real password to the user. The code is very simple and short I hope you will find my work useful.  I am using Dev C++ as my C++ compiler in this 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


#include <stdio.h>
#include <string.h>
#include <conio.h>

int main()
{
    char buffer[256] = {0};
    char password[] = "admin";
    char c;
    int pos = 0;

    printf("\n==============================");
    printf("\nPassword Security in C");
    printf("\n==============================");
    printf("\n\n");

     printf("%s", "Give Your Password: ");
    do {
        c = getch();

        if( isprint(c) )
        {
            buffer[ pos++ ] = c;
            printf("%c", '*');
        }
        else if( c == 8 && pos )
        {
            buffer[ pos-- ] = '\0';
            printf("%s", "\b \b");
        }
    } while( c != 13 );

    if( !strcmp(buffer, password) )

    {
        printf("\n\n");
        printf("Password is Accepted.");
        printf("\n\n");
    }
    else
         {
        printf("\n\n");
        printf("Intruder has been detected.");
        printf("\n\n");
    }
        printf("\n\n");
        printf("THANK YOU FOR USING THIS PROGRAM");
        printf("\n\n");
}





Sunday, February 12, 2017

Count Words in C

In this article I would like to share with you a sample program that will ask you to give a string and then our program will count the number of words in the given by the user using C as our programming language. The code is very short and easy to understand. 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
 
word.c

#include <stdio.h>
#include <string.h>

#define NIL ' '

int main()
{

    char str[200];
    int count=0,a=0;

    printf("\t COUNT WORDS IN C PROGRAM");
    printf("\n\n");
    printf("\t Written By: Mr. Jake R. Pomperada, MAED-IT");
    printf("\n\n");
    printf("Give a String : ");
    scanf("%[^\n]s",&str);
     for (a=0;str[a] !='\0'; a++)
     {
        if (str[a]==NIL)
            {
              count++;
            }
     }
     printf("\n\n");
     printf("\t Display Results ");
     printf("\n\n");
     printf("The number of words in the given string is %d.",count+1);
     printf("\n\n");
     printf("\t End of Program ");
     printf("\n\n");
     return 0;
}

Sunday, February 5, 2017

Age Checker Using Classes in C++

Here is a sample program that will ask the user to give his or her age and then our program will check and determine if the user is an already an adult or still a minor using classes in C++.

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.


Program Listing


#include <iostream>

using namespace std;

class age {
    int ages;
    public:
     int getdata();
     void display(void);
};


int age:: getdata()
{
    cout << "Enter the age of the person : ";
    cin >> ages;
    if (ages >= 18) {
        cout <<"\n The person is Already an Adult.";
    }
    else
     {
        cout <<"\n The person is Still a Minor.";
    }
 cout << "\n\n";
 system("pause");
}

void age:: display(void)
{
    int value;
    value = getdata();
}


main()
{
    age start;
    start.display();
}



Payroll System in C++ Using Classes

Here is a sample payroll program that I wrote for my programming class before a long time ago that uses object oriented programming approach it uses class to declare, use and process variables in our program. I hope my work is useful to your learning in C++ programming.

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.



Program Listing

#include <iostream>
#include <iomanip>

using namespace std;


class payroll {

    private:

    string name;
    int days_work;
    float rate;
    float solve;

    public :

      int get_info();
      void display_info();
};

 int payroll :: get_info()
 {
     cout << "\t\t Simple Payroll System Using OOP in C++";
     cout << "\n\n";
     cout << "Enter Employees Name     : ";
     getline(cin,name);
     cout << "Enter No. of Days Worked : ";
     cin >> days_work;
     cout << "Enter Daily Rate         : ";
     cin >> rate;
     cout << fixed << setprecision(2);
     solve = (days_work * rate);
 }

 void payroll ::display_info()
    {

     cout << "\n\n";
     cout << "==== DETAILED REPORT =====";
     cout << "\n\n";
     cout << "\nEmployees Name     : " << name;
     cout << "\nEmployees Salay is : $" << solve;
     cout << "\n\n";
     system("pause");
    }


    main() {
        payroll emp;
        emp.get_info();
        emp.display_info();

    }



Swapping of Two Numbers in C++

Here is a sample program that I wrote a long time ago while I'm working as a college professor teaching C++ programming subjects. This type of program will ask the user to give two numbers and then it will swap or interchange the arrangement of the two numbers given by our user. I am using CodeBlocks as my C++ editor and Dev C++ as my C++ compiler all of them are free to download over the Internet. 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.


Program Listing

#include <iostream>

using namespace std;

 int temp=0;


class swapping {

    public :
 int values[1];

    int swap_number(int a, int b)
    {
      temp = values[0];
     values[0] =values[1];
     values[1] = temp;
    }
};

 main() {
     swapping numbers;

      cout << "\t\t Swapping of Values 1.0";
    cout << "\n\n";
    cout << "Enter first number : ";
    cin >> numbers.values[0];
    cout << "Enter second number : ";
     cin >> numbers.values[1];
     cout << "Before the Swapping of values ";
     cout << "\n\n";
    cout << numbers.values[0] << " " << numbers.values[1];

     numbers.swap_number(numbers.values[0],numbers.values[1]);

     cout << "\n\n";
     cout << "After the Swapping of values ";
     cout << "\n\n";
     cout << numbers.values[0] << " " << numbers.values[1];
     cout << "\n\n\n";
     system("PAUSE");
}




Saving two values in text file in C++

Here is a simple program that I wrote that will save the two values in a text file using C++ as our 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.


Program Listing

#include <iostream>
#include <fstream>

 using namespace std;

  class test {
      public:

       int x,y;
  };

  main() {
      test values;
      int solve=0;
   ofstream myfile("result.txt");
  cout << "Enter two numbers : ";
  cin >> values.x >> values.y;
  cout << "\n\n";
  solve = (values.x) + (values.y);
  cout << "The sum is " << solve;
  cout << "\n\n";
  myfile << "\t Result";
  myfile << "\n\n";
  myfile << "The sum is " << solve << ".";
  myfile.close();
  }

Sum of Digits in Visual Basic Net

In this article I would like to share with you a sample program that will ask the user to give a series of numbers and then our program will compute the total sum of digits based on the given number by our user using Visual Basic NET. 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

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim n, sum, r As Integer

        n = Val(TextBox1.Text)

        sum = 0
        While n <> 0
            r = n Mod 10
            sum += r
            n \= 10
        End While
        Label2.Text = " The Sum of Digits is " + sum.ToString() + "."
   End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub
End Class





Leap Year Checker in Visual Basic NET

Here is a simple program that I wrote in Visual Basic NET that will ask the user to give a year and then our program will check if the given year is a leap year or not a leap year. 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

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim y As Integer

        y = Val(TextBox1.Text)

        If y Mod 100 = 0 Then
            If y Mod 400 = 0 Then
                Label2.Text = " The year " + y.ToString + " is a Leap Year."
            Else
                Label2.Text = " The year " + y.ToString + " is NOT a Leap Year."
            End If
        Else
            If y Mod 4 = 0 Then
                Label2.Text = " The year " + y.ToString + " is a Leap Year."
            Else
                Label2.Text = " The year " + y.ToString + " is NOT a Leap Year."
            End If
        End If

        
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        End
    End Sub
End Class