Monday, July 26, 2010

To find the greatest common factor?

How do you write a program in Java to find the greatest common factor?

import java.util.Scanner;

public class Gcd
{

public static void main(String args[])
{
int temp=0,i;

Scanner s=new Scanner(System.in);

System.out.println("enter 2 numbers");

int a=s.nextInt();

int b=s.nextInt();

for(i=2;i<=a;i++)
{
if(a%i==0)
{
if(b%i==0)

temp=i;

}//end of if

}//end of for

System.out.println("Gcd is:");

System.out.println(temp);

}//end of main

}//end of class

Java

What is a Java program that finds the greatest common factor of two integers?

If you're interested only in solving the problem, and not in performance, then the simplest way is to simply start by trying to divide one number by the other. If they divide evenly, then that number is the GCF, else subtract it by one and keep trying.


public static int GCF(int a, int b) {

// current will start off as the lesser of the two numbers.
// after each attempt to find a common factor, decrement current
int current = Math.min(a,b);

// loop until current is 1. if this happens, all other possibilities have been
// eliminated and thus a and b share no common factors other than 1
while( current > 1) {

// check factors
if( (a%current) == 0 ) {// check if current is a factor of a
if( (b%current) == 0) { // check if current is a factor of b
// if current is a factor of both a and b, then current
// is the GCF and we can break out of the loop
break;
}
}

--current;
}

return current;

}

// or for a slightly more concise version...
public static int GCF(int a, int b) {

for(int current = Math.min(a,b); current > 1; --current) {

if( (a%current)==0 && (b%current==0) ) {

return current;

}

}


return 1;

}


Again, both of these algorithms perform in O(n) time, which can be quite terrible for large numbers and/or slow machines.

Introduction to Database

INTRODUCTION TO DATABASE with MS Access 2003

Databases are used every day, sometimes without us realizing. They are everywhere. The most basic example is a telephone book or a library card index. They can store all sorts of information, from phone numbers to map grids and references, score cards from sports games, report cards, etc. They allow quick searching and are great for keeping historical data, for example weather history. Most websites run using a combination of a database and a CMS (content management system).

At the most basic level, databases contain tables. Database tables are used to hold information, for example you may have a database table about ‘authors’ or ‘news’.
Inside a table, you have fields. Table fields tells us what information is being kept in the database. In an authors table, for example, you may keep the person’s name and email address.
Microsoft Access is a computer application used to create and work with databases. that means it’s a Database Management System or DBMS.

A Microsoft Access database is a single file with the file extension *.mdb and is often referred to as a database application.

A database is basically a collection of data or pieces of information. Whether you know it or not, you use databases all of the time. Some examples of commonly used databases might be:
• Address book
• Library catalogue
• Telephone directory
• Stock list

A database isn’t necessarily contained on a computer. A telephone directory is still a database even if it’s in the form of a huge book sitting next to your phone.

Databases are intended for storing and maintaining large amounts of information. The following are examples of the sort of information that can be kept in a database:

• Inventory control
• Payroll systems
• Personnel records
• Music collection catalogue
• Phone and address lists

Database is a collection of related information or data.

DATA VS. INFORMATION

Data – a collection of facts made up of text, numbers and dates:
          Murray       35000       7/18/86
Information - the meaning given to data in the way it is interpreted:
        Mr. Murray is a sales person whose annual salary is $35,000 and whose hire date is July 18, 1986.

•    Data are facts about people, places, things or events. – unprocessed facts
•    Information is a processed data.

BASIC DATABASE CONCEPTS

Table - A set of related records (a set of one or more records)
Record - A collection of data about an individual item
Field - A single item of data common to all records

ACCESS 2003 STRUCTURE
What is Microsoft Access?
•    Powerful Relational Database Management System (RDBMS) design to run in Microsoft Windows. Data can be organized as a set of related tables
•    Integration with other Office applications allows seamless exchange of data with centralized database
What is an Access Database?
•    Collection of data objects stored with filename extension .mdb (Microsoft database)
•    Main Access data objects ( Tables, Queries, Forms, Reports, Macros, Modules, Pages)

DATABASE WINDOW   
•    Main database design/management window
•    Displayed when creating or opening an Access database
•    You can use the Objects toolbar to access the different objects that make up a database

TABLES
What is table
•    Basic container for data, arranged as a grid of rows and columns
•    Each row contains a single record
•    Each column represents a field within the record
Access tables
•    Fundamental data objects in Access
–    Forms, queries and reports are all based on tables
•    Table Wizard provides automated table creation
•    Tables can also be created manually for more precise specification
FORMS
What is form
•    Electronic version of paper form
•    Used to simplify entry of data into an Access database

QUERIES
What is a Query?
•    A question asked of the database
•    Used to extract specific information from database
•    Used to extract specific information from database
–    Example:What is the three top-selling products in our company’s product line?
•    Queries are composed of structured query language(SQL) statements
–    Example:
                SELECT Products.[Product #], Products.[Product Name], Products.Price    FROM Products
                WHERE (((Products.Price)<4.75));
•    Access allows queries to be created graphically
•    Hides complexity of SQL language

REPORT
What is report?
–    Formatted template used to print reports of database or query results
–    Allows user to specify fields, grouping levels, arrangement of printed data
MACROS
What is access macro?
–    User-defined sequence of actions to be performed by Access 2000
–    Macros will not be covered
MODULES
What is a module?
–    User-created sections of code which provide sophisticated automation of Access functions
–    Written in Visual Basic for Application(VBA)

CREATING A NEW TABLE IN DESIGN VIEW
For each field in new DATABASE, specify the following items
–    FIELD NAME
•    Descriptive name of field to be used in table
–    64-character maximum
–    Prohibited characters:period(.), accent grave(‘), square brackets([]), exclamation point(!)
–    DATA TYPE
•    Drop-down list displays available data types
–    Number, Date/Time, Currency,Auto number, Yes/No, OLE Object, Hyperlink, Lookup Wizard
–    DESCRIPTION
•    Comment describing details of field.  Appears on the status bar in Datasheet view when you click a row in the field's column

SETTING A PRIMARY KEY
What is a primary key?
–    Main index for table
–    Must be unique for each record in table
•    Example: Product number, Employee number, etc.
–    If no such field exist, create a new field with the data type “Autonumber” and specify it as the primary key
•    Access will automatically create unique numbers for this field
Assigning a field as the primary key
–    Select field
–    Click on Primary Key button on toolbar (or use “Edit /Primary Key”)
•    A key symbol will appear next to selected field

Thursday, July 22, 2010

Seminar

Seminar Workshop in Research Capability Enhancement for BSCS Students
Little Theater, Notre Dame of Midsayap College
July 31, 2010

Monday, July 19, 2010

Introduction to Computer

IS/CSE/IT 111 Introduction to Computer

What is Computer?
Computer is a device that performs mathematical and logical operations based on the database with a minimal human interpretation.
It is a device that accepts data, processes and store these, and produces a result/output.

Four Basic Functions
1.Input
2.Process
3.Storage
4.Output

Typically, a computer system consists:
1.Input Devices – which allows the users to input data for processing
2.Storage Devices – where the processed information are stored
3.Central Processing Unit – which interprets and executes data or instruction
4.Output Devices – where outcomes are displayed

Three Main Elements of Computer System
1.HARDWARE – refers to the physical components of a computer that you can actually touch, such as keyboard, monitor, central processing unit, mouse and printer.
HARDWARE may be classified into:

1. Input Devices – these are external devices that provide information and instruction to the computer.
Common Example: Keyboard,Touch tone device, mouse, joystick, touch screen, light pen, scanning device, Fax Machine, phone card, digital cameras, sensor
2. Output Devices – these are devices that will communicate the result of processing back to the user by converting electrical signals from the Arithmetic/Logic Unit. Output devices that will produce result/output.
Common Example: monitors, Printer, Plotter, speakers
3. Central Processing Unit (CPU) – performs arithmetic and logical operations on data taken from the primary storage or on information entered through any input devices.

Five basic component of CPU:
1. Main Storage – also called memory/primary storage where instructions and data are stored while processing is done.
Two types of memory inside the main storage:
Random Access Memory (RAM) uses to store given instructions which can later be changed or erased. When data are loaded from the RAM it means WRITING data, when data are accessed it means READING data.
All information stored in it are lost or erased when the computer power is turned off or interrupted. This kind of memory is volatile.
Read Only Memory (ROM) contains stored instructions that a computer requires to be able to do its basic routine operations. The instructions still hold even when there is power interruption or shut-off. This kind of memory are non-volatile. It has a data built in by the manufacturer.
2. REGISTERS – part of the CPU that function as fast-accessed temporary memory locations. The bits of information taken from the main memory and those that will be placed in the main memory are temporarily held in the registers while computation are being performed.
3. BUSES – are bundles of tiny wires that serve as the communication path between components of the CPU. The Three most important buses are the Address, Data and Control Buses.
4. Arithmetic Logic Unit (ALU) – performs all the arithmetic and logical calculations of the CPU.
5. CONTROL UNIT (CU) – is responsible for directing the flow of instructions and data within the CPU. It fetches the instructions from the main memory for execution in the CPU. Aside from controlling the input and output devices, it also passes data to the ALU for computation.
4. SECONDARY STORAGE – where data are stored permanently.
Common example hard disk, optical disk (compact disk read only memory (CD), digital versatile disk (DVD)

Two Classes of Secondary Storage:
1. Direct Access Media – (floppy disk, flash memory(usb)) supports sequential of random access where data can be accessed directly)
2. Sequential Access Media – where data are accessed in a specific order. (magnetic tape – traditional medium for long term storage but slowest in terms of retrieval of data)

2.SOFTWARE – is untouchable. It is a set of instructions used to direct the hardware on how to turn data into useful information for people to use.
A set of instructions or program that tells the computer how to do a specific task.

Two types of Software:

1.SYSTEM SOFTWARE – refers to computer programs of library files whose purpose is to help run the computer system.
Example – Operating System (manage the whole operation of the computer), output devices (provides interface to the hardware) Utility Programs (who manage files), Compilers and interpreters (programs that will translate high-level language programs into object code)

2.APPLICATION SOFTWARE – performs specific functions, which make daily activities easier and facilitate the performance of work efficiently and effectively.

Categories of Application Software:

1.Productivity Tools – eg. Software like Word Processing, Spreadsheet, Database, Presentation Graphics, Personal Information Manager Software and Project Management.
2.Graphics and Multimedia –eg. Software like Computer-Aided Design, Desktop Publishing, Web Page Design, Image Editing, Video/Audio Editing, Multimedia Authoring
3.Home, Personal and Educational Use – eg. Software like Integrated software, Personal Finance software, Clip Art/Image Gallery, Legal Software, Educational Software, Entertainment Software.
4.Communications – eg. Software like E-mail Software, Web Browser, Chat client Software, Newsreader Software, Instant Messenger software, Groupware software, Videoconference software.

Three basic types of application software:
1.COMMERCIAL – comes prepackage and is available from software vendors. It must be purchased.
2.SHAREWARE – are software develop a d released as demonstration versions of their commercial product. Each demonstration copy has an expiration date which gives the user ample time to evaluate and decide whether the purchase the product or not.
3.OPEN SOURCE – software that is created by generous programmers and released to the public domain for free and for public use.

3.PEOPLEWARE – who use the computer system, they are the most important factor in a computer system because they manipulate and program the computer system to make it useful.
- The skilled workers in the Information Technology field.
The major compositions of IT Professionals:
1.Management Group – eg. Computer System Manager
2.Systems and Procedures Group – Computer Scientist, Computer Engineer, System Analyst
3.Programming Group – Computer Programmer
4.Computer Operations Group - Computer Operator, Data Encoder, Data Entry Operator, Computer Librarian

CAPABILITIES OF COMPUTER
1.Computer can do repetitive and routine work.
2.Computer can process large amount of data.
3.Computers are reliable and accurate.
4.Computer can store and retrieve large amount of information.
5.Computers have a self-checking ability.
6.Computer can be self-operating.
7.Computers can do remote processing.

LIMITATIONS OF COMPUTER
1.Computers are dependent on instruction and data.
2.Computers cannot generate information.
3.Computers cannot correct wrong instructions.
4.Computers cannot decide specific task. (except if they are programmed)
5.Computers are vulnerable to a virus attack.

Assignment: Note Book (Reference: Introduction to Information Technology by Albano-Atole and other computer books or use Internet)
1.Classifications Computers
2.History of Computing (from 2000 B.C. to present)