Computer engineering - C# php asp .Net SAP SQL: C#
Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Monday, May 26, 2008

DFA logic - Dterministic Finite Automata

The code below is to create a deterministic finite automata. It just builds the logic of a dfa. The gui can be created very easily.

import javax.swing.JOptionPane;
import javax.swing.*;
import java.util.*;
public class dfa {

static String alphabet,son,retrn;
static int comma=0;
static int acomma=0;
static int number=0;
static String[][] st=new String[50][50];
public static void main(String args[]){


alphabet=JOptionPane.showInputDialog(null,"Alphabet?");

for( int i=0; i if( alphabet.charAt(i) == ',' )
comma++;
}

String states=JOptionPane.showInputDialog(null,"# of states");
number=Integer.parseInt(states);

for(int i=0; i int k=0;
for(int j=0; j<(alphabet.length()-comma);j++)
{

st[i][j]=JOptionPane.showInputDialog(null,"q"+i+","+alphabet.charAt(k));


System.out.print("q"+i+"--"+alphabet.charAt(k)+"-->"+"q"+st[i][j]+"\n");

k=k+2;
}

}


String start = JOptionPane.showInputDialog(null,"starts state?");
int start1=Integer.parseInt(start);
String accept = JOptionPane.showInputDialog(null,"accept states?");

for( int i=0; i if( accept.charAt(i) == ',' )
acomma++;
}

int[] accepts= new int[(accept.length()-acomma)];

int l=0;
for(int i=0; i<(accept.length()-acomma); i++){
accepts[i]=Integer.parseInt(Character.toString(accept.charAt(l)));
l=l+2;
System.out.print(accepts[i]);
}

System.out.println("start state"+start);
System.out.println("Accept state"+accept);

String strng=JOptionPane.showInputDialog(null,"String?");
System.out.println(strng);

int[] durums=new int[strng.length()];

for(int i=0; i if(i==0){
durums[i]=dfa(start1,strng.charAt(i));
}
else{
durums[i]=dfa(durums[i-1],strng.charAt(i));
}
System.out.println(durums[i]);
}

int kontrol=durums[(strng.length()-1)];

int kabuluzun=accepts.length;

for(int i=0; i if(kontrol==accepts[i]){
System.out.println("ACCEPTED!!!");
break;
}
else if(kontrol!=accepts[i]){
System.out.println(" NOT ACCEPTED!!!");
break;
}
}

//DFA METHOD!!!
public static int dfa(int durum, char deger ){

int deger1=0;
int sondurum=0;
for(int i=0;i

if(deger==alphabet.charAt(i)){
deger1=i;}

else{
for(int j=0; j<(alphabet.length()-comma-1);j++){

i=i+2;
if(deger==alphabet.charAt(i)){
deger1=i-1;
break;
}
}
}

sondurum=Integer.parseInt(st[durum][deger1]);

}
return sondurum;
}
}

Monday, March 31, 2008

Thin and Fat Client Model

There are two type models of the client-server architecture.

Thin-client model
In a thin-client model, all of the application processing and data management is carried out on the server. The client is simply responsible for running the presentation software.

Fat-client model
In this model, the server is only responsible for data management. The software on the client implements the application logic and the interactions with the system user.



Thin CLient Model:
-Used when legacy systems are migrated to client server architectures.
-The legacy system acts as a server in its own right with a graphical interface implemented on a client.
-A major disadvantage is that it places a heavy processing load on both the server and the network.

Fat Client Model:

-More processing is delegated to the client as the application processing is locally executed.
-Most suitable for new C/S systems where the capabilities of the client system are known in advance.
-More complex than a thin client model especially for management. New versions of the application have to be installed on all clients.

Thursday, March 27, 2008

Adding a Large and Small Number Error

The initial terms in such series are often relatively too large in comperison with the following ones. So after a few terms, we have been adding very small number to too large numbers.The error here is caused by the chopping of the computer while calculating the series.

By the definiton above we examine the problems below:

Problem 3:

F(N)= Σ 1/(n*n) where n=1 to n=N

Compute the series by adding with the variable n=1 to 10,000 and by adding the varieble n=10,000 to n=1.Compare the results.

This is the code solution program of the problem in Java:


import javax.swing.JOptionPane;
public class series{
public static void main(String args[]){
double x =0.0;
double y=0.0;
for(double i=1.0; i<10001.0; i++){
x += 1.0/(i*i);
}
for(double i=10000.0; i>0.0; i--){
y +=1/(i*i);
}

JOptionPane.showMessageDialog(null,"The sum begined from n=1 :"+x+'\n'+"The sum begined from n=10,000 :"+y);
}
}

And these are the outputs:

Wednesday, March 26, 2008

Machine Epsilon

Machine epsilon is the smallest number when it is added to 1 your computer assumes it 1 briefely. It depends the physical features of your computer. After this definition let us create the pseudocode of a program that computes your machines' epsilons.




epsilon=1
DO
IF(1+epsilon<=1) EXIT
epsilon=epsilon/2
END DO
epsilon=epsilon*2

The code above is the pseudocode of a machine epsilon algorythm. I guess you know about pseudocode :) If you do not know do not be sorry since it is nothing :P It is a description of an algorythm that is language independent.YOu just write on what you think to do. That is it!

Now let me give you the Java code of that algorythm and the output of it.

import javax.swing.JOptionPane;

public class epsilon{
public static void main(String args[]){
double epsilon = 1.0;
for(int i=1; i<100000; i++){

if(epsilon+1.0<=1.0){
break;
}
else{
epsilon=epsilon/2.0;
}
}
epsilon=2*epsilon;
JOptionPane.showMessageDialog(null,"The epsilon of the machine is:"+epsilon);
}
}

Since i have explained each line of a java code example i think you can understand the steps and pseudocode helps you in this issue as well.

So my output is in the figure below. But do not be confused if you have not got the same output since it depends the physical features of your PC!



I will keep giving some java examples as well. Using Java in mathematic will suprise you or mathematics will suprise you ;)

Tuesday, March 25, 2008

Activity Diagram

Activity diagrams are used for to show a subprocess of a system by figures. Big black dot means the start and the Black dot and a circle outside it means end. Also the arrows represent yes and no answer to the process.That means if yes process done if no can not be done. The diamond are the process steps.
We still continue on the example we examined at last two articles. Here are the some examples from the dynamic web site system:

Activity diagram for use case of Adminstrator to send and receive mails.



Activity diagram for use case of all users to post messages.



Activity diagram for use case of Student to add comments.

Monday, March 24, 2008

Use Case Diagram

Use case diagrams are known as the information about whole system with drawn syntax.The article just before that i have talked about a system: a dynamic web site system the use case diaram below belongs to the same example.

Also some explanations about the diagram as:

Use Case UC1 : Upload&Download Process
Primary Actor : Administrator
Steakholders & Interests:

1. Administrator : Wants all rights to manage the site in minimal time and effort. Also their need is to achieve the site to manage it from every computer they want which by they can access to the Internet.
2. Student : Wants reach to the documentations that he/she needs to download, and add comments to the annocuments also posting messages to the admins. These process needed to be done in a small time period.
3. Invited Speaker : Wants the rights for to add the documantations for their class in minimal effort.To get these rights they need to enter the web site by their user names and mail adresses that they reported to the admins before.
4. Guest : Just can read the page and post messages. Also become a member of the site with his/her student number.

Preconditions : Administrator has logged in to the site by using their username and password.
Success Guarantee (Postconditions) : Text is uploaded succesfully. Web site updated.


Main Success Scenario:

1. Administrator opens his/her control panel.
2. Administartor writes down the address of the document that he/she want to upload.
3. Database stores the document file.
4. Student/Invited Speaker /Guest reads the document from website.
5. Student & Invited Speaker downloads the document.
6. Administrator delete the document link from website.

Extensions:

At any time system fails:
3.a. Database can not stores the file.
3.b. Wrong document file’s address entry by Administrator.
5. Student & Invited Speaker can not dowload the file since the system errors.

For next article the activity diagram of the same example will be axplained.

Sunday, March 23, 2008

Class Diagrams

Consider about a web site that is a course specific web site. As most of us related with it i mean with most of us as students :) A web site that has a user entry and admins as professors and tha assitants of them. Also there are invited speakers whom have been invited to the classes and whom are in the software development market. As i did not said yet the site is the web site of the sofware programming course! See the below explaniations as example to the class diagram of the system:

There are five classes in the system.



The description is as follows:



And at last the class diagram:




Most info about class diagram will be explained in the following article. ALso some other diagrams activity or use case diagram infos and examples for the same system will be added to it.
See yas:))

Friday, March 14, 2008

PhpTriad

In this article i want to introduce you my favorite software tool PhpTriad :) I love it since it is easy and free to download and install. You can find lots of versions of PhpTriad for your platform. This is a link for you to download PhpTriad

http://www.sourceforge.net.

But there are many sources that you can download it from if you search on Google you will see :)

So what is PhpTriad? Php Triad is a complex tool of Php, MySQL and Apache that are your general requirements for coding in Php. Installation is very very easy. But i will explain althpugh it is just clicking the button install and done after the installation completed.

So then you installed the program let's start to using it. Fİrstly you need to click on the icon "winmysqladmin" at the adres c:/apache/mysql/bin and then you will type your user name and the password. Please choose a good one since you will need it for oyur databases and it can be setted just at the installation.If the installation is completed succsfully an icon at at the right bottom of your screen that looks like traffic lights.So it need to be green to represent of working.

It did not finished yet :) It is not easy as i said :P We have a little more work then by clicking to start at the programs, you will see a segment called 'Programs' when you click on this menu please start the program: Programs/PhpTriad/Apache Console/Start Apache. this is for to boot Apache. Wen you run the program an command console will appear at your screen which states that 'Running Apache'. Please be sure that the program is always running while you want to run the website you are coding.You need to put your files that you want to show in : C:apachehtdocs. after all of these PhpTriad is ready to use! Just run your browser and write to the adress http://localhost/filename.php ;)

I wish you to have good coding :)
Good Luck!!!

Sunday, March 9, 2008

Php Kitbag

Althuogh i wrote an article about the php programs i think an article with more explaniation will be more helpfull. But it will be by parts since i have not got lots of time for once :)

Firstly as i said the kitbag of php has the components:


  1. PHP 5

  2. Apache Web Server

  3. MySQL or MSSQL

  4. PHPMyAdmin

As i have said before you can get the PHP 5 program from www.php.net .


You can get the Apache from www.apache.org . From this address you can click on HTTP Servers and then download the last version of Apache. After download we are starting to installation of Apache first. By double click on the folder you have downloaded (.msi) you start to install Apache.


Friday, March 7, 2008

Introduction to PHP 2

Firstly PHP is a SSS(Server Side Script). This means if a user enter the site that is prepared by using PHP can only see the HTML output. For instance we have written a program and create an executable code. Then the executable code generates an output to the screen and you can not see the real codes of the program. This is the process of SSS. It generates an output to the screen.

So at last this is our first PHP code example :))

< html >
< body >

< ?php

echo "Hello Web!!!";

? >

< /body >
< /html >

< ?php is the code piece that the PHP codes start. PHP when realizes the sign < ? it interprets the codes until ?> sign. It does not executes the rest of the code. Since that the output of the code i have written above is that:

< html >
< body >

Hello Web!!!

< /body >
< /html >

So this is the process... As you see echo is a function like the print functions in C/C++ or Java.

See you at next article...

Monday, March 3, 2008

Introduction to PHP

PHP means "Personel Home Page Tools" which invented by Rasmus Lerdorf nearly in 1995 or earlier. It is a SSS (Server Side Script) which he needs strong on database and answers to dynamic site design needs. After the expansion of PHP had became "PHP is a Hypertext Pre-Processor".If you want more detail about history of PHP take a look at http://www.php.net/manual/en/history.php .

Now let's start to understand the capablities of PHP.For me it is capable for every work :) Since it is developed more and more it is good for everything you want to do.

  • You can create your own graphics by PHP.
  • You can create Flash documents without any need to Flash and some kind software.
  • PHP is good for interwork with every database system such as MS SQL, MySQL etc.
  • And if you can not find something you need you can write it on your own and can share it.

And it is time to explain how you can use PHP now. PHP is an platform independent web language.Firstly you need to decide on which web server you will use. I recommend you Apache which is a platform dependent server as well. If you are a Windows platform user it is nice for you to use PHPTriad. It includes both Apache, MySql and PHP. Also PHPTriad is called as sokkit after its 2nd version which you can acces from http://www.sokkit.net .

After you do this wait for your PHP codes and explainings of them and wait for next article:)

Sunday, March 2, 2008

Where to Execute Our Codes?

Although most of object oriented programming languages are mostly platform dependent we generally use soma programms to execute them. For instance JCreator is mostly known one taht you can access from http://www.jcreator.com.
And the other program is Microsoft Visual Studio. By it you can work on many languages. One of them is the newest C# which i will show examples later.

In this article i will give an example code in Java again.

import javax.swing.JOptionPane;
public class hmwrk4_1 {
public static void main (String[] args) {
System.out.println("Feet Meters\n---- ------");
for(double i=1.0; i<=10.0; i++) {
double meter=footToMeter(i);
if(i==10.0) {
System.out.println(i+" "+meter); }
else System.out.println(i+" "+meter); }
System.out.println("\nMeters Feet\n------ ----");
for(double i=20.0; i<=65.0; i+=5){
double foot=meterToFoot(i);
String s1=String.valueOf(foot);
if(foot>99.999){
String s2=s1.substring(0,7);
System.out.println(i+" "+s2); }
else{ String s2=s1.substring(0,6); System.out.println(i+" "+s2); } } }
public static double footToMeter(double foot){
double meter=0.305*foot;
return meter;}
public static double meterToFoot(double meter){
double foot=meter/0.305; return foot;}}

In comment you can write on what the program does. I will add it on the article later

Friday, February 29, 2008

Introduction to Programming in Java

I will explain programming in Java on an example. In this example we will calculate the roots of an equation whose solution is not a complex root.Our program will give an output if the root of the equation is complex as COMPLEX ROOT!!! User will enter the coefficients of the equation.

Let us start to examine the code of the program:

import javax.swing.JOptionPane; --> This code is to activate JOptionPane function of Java.

public class hmwrk2_1{ ---> Firstly we create our class which our object will be included

public static void main (String[] args) { --->We are starting to write the main function of our code

int a, b, c; ---> Now we declare our variables which i have explained in Programming Languages article

a=Integer.parseInt(JOptionPane.showInputDialog(null,"ax^2 + bx + c \n please enter the coefficient a:")); ---> We are assigning variable a to the value which user enters




b=Integer.parseInt(JOptionPane.showInputDialog(null,"ax^2 + bx + c \n please enter the coefficient b:")); --->we are assigning the value which user enters to the variable b again

c=Integer.parseInt(JOptionPane.showInputDialog(null,"ax^2 + bx + c \n please enter the constant c:")); --->same process as above.

double x1,x2; ---> We are declaring 2 double values for roots of the equation

double delta=(b*b)-(4*a*c); --->We are declaring double delta and setting it to a equation in formula

if(delta<0){> If delta value that we calculated by the values user have entered is smaller than zero we we get the warning complex root!!!

JOptionPane.showMessageDialog(null,"COMPLEX ROOT!!!"); }


else if (delta==0){ --->If delta value equals to zero
x1 = x2 = -b/(2*a); ---> We calculate the roots as in formula.

JOptionPane.showMessageDialog(null,"root= "+x1);---> And printing one of them to the screen


}

else { ---> If the value of delta is bigger than zero
x1=(-b+(Math.sqrt(delta)))/(2*a); ---> We set x1 and x2 variables as in formula.

x2=(-b-(Math.sqrt(delta)))/(2*a);

JOptionPane.showMessageDialog(null,"root1= "+x1+"\nroot2= "+x2); ---> And printing both of them to the screen


}
}
}

Thursday, February 28, 2008

Programming Languages

Instead there is another old languages the most popular programming languages are object oriented ones such as C++ and Java. ın these two more independent one is Java since it is platform independency. Java programs can be executable on every platform since it structure.
While using these languages you define some object by creating classes and you can improve that classes by inheritance. I mean first you write a class than you get all the features of the class and adding new features to it you create a new class. For instance you create a Car class that has just gas varible (a variable is a memory area that stores the gas value of the Car you created and you can change the value by programming since it is called variable!) to improve that Car you write a BetterCar class and get the gas variable with the same type and you add DecreaseSpeed variable to it to decrease speed for example.
There is also set-oriented languages as SQL. While using SQL you get a set as output although you get a object as output by using object-oriented languages. SQL cammands are used to create a database and improve it. Adding it datas deleting datas from the database and so on. Also you can has the data set as output to your any command.In SQL the commands are called as Query. There are three platforms that you can use SQL. These are MySQL, MS SQL and ORACLE. These three are really near to each other some syntax differences occurs between them.
I have tried to explain programming languages in a general format that i can. By adding some code examples and explaining them these things that i wrote are gonna be more clear. :)

Tuesday, February 26, 2008

Data Storage

In this article i will begin with Bits and Their Storage.

Inside today's computers the datas are stored as pattern of 0's and 1's. Every 0 and 1 is called as a bit. These patterns sometime represents a numeric value or a character from the alphabet. Some boolean operations can be implemented by them.The basic operations are AND, OR. AND operation is represented with a '.' and OR operation is represented with a '+'.

AND OR
0.0=0 0+0=0
0.1=0 0+1=1
1.0=0 1+0=1
1.1=1 1+1=1

These operations are made on physically on gates which can be produced from elctrical circuits. And the level of the voltage applied to these circuits represents 1 and 0. The voltage is the input of the gate and the output is a voltage again. These two gates has two inputs and one output. Also there is another structure called as flip flop which stores the past output value and represents a new output related to it and the inputs. Another and old storage technique is core which is donut shaping ring of magnetic metarial. The more recent method is capacitor that has two small matelic plates positioned parallel. A capacitor can be charged or discharged. So one situation represents 0 and another one 1. Also a chip consist of millions of capacitors. And in conclusion the most modern method is the flash memories. In this method bits are stored by trapping electrons in champers of silicon dioxide.Full champer and empty champer represents 1 or 0.

Introduction to Computer Science

A large outline of the working principle of the computer and networks can be analised in 10 parts as:

  1. Data storage
  2. Data manipulation
  3. Operating system
  4. Network
  5. Internet
  6. Algorithms
  7. Programming languages
  8. Software engineering
  9. Data abstraction
  10. Database systems

I will explain these parts in seperate articles.

Sunday, February 24, 2008

What is computer engineering firstly ?

Composite study of electronical engineering and computer science is called as computer engineering which provides you the knowledge of both harware and software components of a computer in detail. Generally takes 4 years to gradurate. At the 4th year of the education students have to complete one or two projects on an issue that they can decide on their own. They get help from their instructors as well.By these 4 years students become an engineer and deeply expert on these core knowledge areas below:

  • Circuits and signals
  • Digital logic design
  • Electronics
  • Computer architectures
  • Algorythms
  • Different type of programming languages
  • Algorithms
  • Data Structures
  • Operating systems
  • Database design and management
  • Computer organiztions
  • Software engineering
  • Information systems and analysis
  • Computer networks
  • Embeded systems
  • Social and professional issues