Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Graphics Programs: Draw Circle using Polynomial Method

Source Code
/**********************************************************
* Program : Simple Circle Drawing Algorithm
* Author : Vijay Kumar Verma (VJY) | MCA
* Website : vjysoftworx.com
* Date : 25-Jan-2014
***********************************************************/
#include ‹iostream.h›
#include ‹conio.h›
#include ‹graphics.h›
#include ‹math.h›
int main(){
  int dr=DETECT, md;
  initgraph(&dr,&md,"c:\\tc\\bgi");
  int h, k, r, x, y, xe,col;
  cout<<"Enter co-ordinate of center(h,k): ";
  cin>>h>>k;
  cout<<"Enter radius: ";
  cin>>r;
  cout<<"Enter Color code(0-15): ";
  cin>>col;
  x= 0;
  xe = (int)r/sqrt(2)+0.5;  //calculate the end point of x
  y = r;                     //add the value of r to y
  while(x <= xe){
   putpixel(x+h,y+k, col);
   putpixel(x+h,-y+k,col);
   putpixel(y+h,-x+k, col);
   putpixel(-y+h,-x+k, col);
   putpixel(-x+h,-y+k, col);
   putpixel(-x+h,y+k, col);
   putpixel(-y+h,x+k, col);
   putpixel(y+h,x+k, col);
   x++;
   y = (int)sqrt(r*r-x*x)+0.5;  //calculate the value of y
  }
 getch();
 closegraph();
 return 0;
}
Output:
Read More

Simple Magix 0.12 download

here is a small project work in Visual Basic 6.0. I did some thing for fun but I enjoined to complete this task. Here I am posting the link I hope all of you like this program. And Yes!! please give your feedback about my program how it was and what should be improved.


Click on This link to...  
Read More

An Introduction of Programming with JAVA


History and Origin of Java

All of us must do programming but when any one talk about Java, Then all of them say - Java is an Awesome language as compare to other in most of the feature. Why Java is popular and secure language and every programmer want to program in java.
The seeds of Java were planted in 1990 by Sun Microsystems patriarch and chief researcher, Bill Joy. That time Sun was competing with the workstation market with other eminent company like Microsoft, IBM or other. But Sun missed the most of the important thing of Pc evolution. Then Joy was committed to the idea of accomplishing complex task with the simple software and found a small work group Sun Aspen as here Java origin was started. The most important and notable member of the Aspen was James Gosling who will be remembered as the father of Java. He is also known for author of the first Linux Emacs editor. Emacs was written in C on Unix Platform.

The First Person team worked on developing software for information appliances, such as cellular phones and personal digital assistants (PDAs). The goal was to enable the transfer of information and real-time applications over cheap infrared and packet-based networks. Memory and bandwidth limitations dictated small, efficient code. Gosling and his teammates began programming in C++, but they soon found themselves confounded by a language that was too complex, unwieldy, and insecure for the task. They decided to start from scratch, and Gosling began working on something he dubbed "C++ minus minus."
With the foundering of the Apple Newton, it became apparent that the PDA's ship had not yet come in, so Sun shifted First Person's efforts to interactive TV (ITV). The programming language of choice for ITV set-top boxes was to be the near ancestor of Java, a language called Oak. Even with its elegance and ability to provide safe interactivity, Oak could not salvage the lost cause of ITV at that time. Customers didn't want it, and Sun soon abandoned the concept.

At that time, Joy and Gosling got together to decide on a new strategy for their innovative language. It was 1993, and the explosion of interest in the Web presented a new opportunity. Oak was small, safe, architecture-independent, and object-oriented. As it happens, these are also some of the requirements for a universal, Internet-savvy programming language. Sun quickly changed focus, and, with a little retooling, Oak became Java.

I will post the more feature of Java in Next blog post keep tuning here and follow with us
Reference:
# Learning Java By Jonathan Knudsen, Patrick Niemeyer
# Introduction to Computing & Programming in Java By Mark Guzdial, Barbara Ericson 
# Wikipedia
# Google



Read More

An introduction of Programming with C++


Introduction

It's amazing experiences to write program in c++ after programming in C. C++ is successor of C but initially it was not referred as C++ as we know today. C++ (Pronounced as See Plus Plus) was developed in the same place where one of the best ever programming language C was developed, That place is AT & T Bell Lab, USA around 1983. 

Bjarne Stroustrup, you hear this name before. No! Don't worry i am explaining about them. Actually he is the person who is responsible to developed the C++ programming language, which is second best language after C. This name is important in programming and software industry but seems complex to pronounce it, I have also problem pronounce the name and this problem can be solved by just read following. You have to read this-

                   Bee-yarn-eh Strow-strup

History

I think you can pronounce correctly. Lets know history of C++. Ones upon a time there was a computer, Which was too bulky and costly. To made it functioned perfectly a medium is required called Computer and Programming Language. Initially around 1940s we had Machine language and after then Assembly language was developed around 1950s. These were two complex to code the program. Then Programmer think about some easiest way to write program for computer hence High Level Language was introduced.

"To complete the difficult task, I hire the Lazy people because they always want to find the easiest  way to complete the task"                  -Bill Gates

One of the oldest high level programming Language was widely used at the time of 1960s was ALGOL (Algorithm Language), which was developed in Cambridge University. It was first structural Programming Language . Then, CPL (Combined Programming Language) in Cambridge University. But these can not the last and most popular. 1970-80s was the best era where many important programming languages were developed. In Bell Lab, Some extra research was continuing to made our computer system more efficient and reliable. And as a result Martin Richards developed the Language influenced by CPL called BCPL(Basic Combined Programming Language). BCPL is intend to write portable software and compiler. But not widely used. After then Language B was developed by Ken thompson with the help of Dennis ritchie. All this development was continued just for made our computer more reliable and efficient.


Next major development of this sequence is Programming language C which is milestone in programming field. C was developed by Dennis Ritchie between 1969-1973. It is developed to write the one of the best Operating System UNIX. Initially C was developed on UNIX and next Whole UNIX was developed in C. C is very popular in programming and software industry but have some drawback and lack of functionality that was solved by Bjarne Stroustrup and developed and new Programming language C++ in 1973. Initially Stroustrup called it "C with class". C++ was suggested by Rick Mascitti and first used in 1983. ++ (plus plus) is taken from increment operator of C.

"Language shapes the way we think. and determines what we can think about."                                                                                     -B.L.Whorf
Next»
Read More

C Programming: Lession 1

Introduction with History

The Word C is the third Letter of our Alphabets. Do you know about it? I am just joking. Actually C is Strange Word in the Computer Field for those people who just start the programming but all the experienced programmer as well as beginners like to program in C. Then let us introduce it with and from where C was origin.

Many years ago there was Machine language to work with computer. These languages have lack of portability between different computer leds to the development of High level language. The first known High level language Plankalkul developed by Konard Zuse around 1948. After then Grace hoper invented a language called FORmula TRANslator (FORTRAN) in 1952-1954, widely used by Scientist and Engineer. Next LISP and then COBOL, ALGOL, APL, PL/1,BASIC  and many more. But all of them have some complexity and drawback.

To solve all this complexity some scientist working for creating new language – called “C”. C was invented and first implemented by Dennis Ritchie on a DEC PDP-11 that used the UNIX operating system (1971-73). C was developed by using the basic features of some old language -ALGOL, BCPL and B – and adding new important features in all of them.
The Name C was given by Dennis Ritchie because it was came after B. BCPL developed by Martin Richards and it influenced a language called B, was developed by Ken Thompson. B leds the development of C in the 1970s.

C was developed on UNIX platform. UNIX is best known for Network Operating System. Normally UNIX was implemented in Assembly Language but after some time whole UNIX OS was again implemented in C Language.

Many version and flavor of C is being used. Around 1973, when Kernighan and Ritchie released their book “The C Programming Language ”, It become very popular and This very version of C was widely referred K & R C. Earlier C was open that means any can use this language and also can customized its functionality. It was the cause when standard of C was going to be reduce continuously. Then Standardization process of C continue after the establishment of ANSI around 1983. It took six year to Standardize the C and finally ANSI adopted it and version ANSI C was released in December 1989. C was also adopted by ISO(International Standard organization) and this version was called ANSI/ISO C.

In 1995 some changes were included in C ,Version of C defined by the 1989 standard is commonly referred to as C99. After the development of C++ around 1983, to made C popular all time Standardization of C again worked and add the some new feature from C++ in 1999, This version of C was known as C99.

Latest Standardization and modification released the version CX1 (also called C11) around 2007. 

Now days, C is the first choice of any programmer and widely adopted by Software companies because of their important features.

Many company introduce the compiler and IDE for C language some of them are
Turbo C, Borland C, GCC and more

C compiler itself written in totally C language today
Some other language influenced by C-  C++, Java, Simula,

Reference: 
C the complete Reference by Herbert schildt
O' Reilly Practical C programming
wikipedia
google

Please give your important suggestion to improve the content




Read More

Programming introduction

What is Program?
              Programming is nothing but making the computers think the same way a human thinks. Programs are made for obtaining a specific solution which can even be solved by humans which when solved by us may consume time. So one thing is clear that man can do all things that a computer can do where in turn a computer can not do all things that a man can do. Even though the computers are fast,reliable, and robust they are simply current consuming machines unless they are programmed.

What is programming?
                 Normally the process to write program for computer is called programming.

What is programer?
                 Person who is responsible to write the program and manage is called programmer. Actually a programmer is advance user who solve the problems with the computer.
Read More

Algorithm: A Beginner to Advance Guide of Programming

An algorithm, named after the ninth century scholar Abu Jafar Muhammad Ibn Musu Al-Khowarizmi, is defined as follows: Roughly speaking:
  • An algorithm is a set of rules for carrying out calculation either by hand or on a machine.
  • An algorithm is a finite step-by-step procedure to achieve a required result.
  • An algorithm is a sequence of computational steps that transform the input into the output.
  • An algorithm is a sequence of operations performed on data that have to be organized in data structures.
  • An algorithm is an abstraction of a program to be executed on a physical machine (model of Computation).

The most famous algorithm in history dates well before the time of the ancient Greeks: this is the Euclid's algorithm for calculating the greatest common divisor of two integers. This theorem appeared as the solution to the Proposition II in the Book VII of Euclid's "Elements." Euclid's "Elements" consists of thirteen books, which contain a total number of 465 propositions.

 The Classic Multiplication Algorithm
1. Multiplication, the American way:
Multiply the multiplicand one after another by each digit of the multiplier taken from right to left.

                                          981
                                        1234
                                -------------
                                        3924
                                      2943
                                    1962
                                    981
                                ------------
                                  1210554


 2. Multiplication, the English way:
Multiply the multiplicand one after another by each digit of the multiplier taken from left to right.

                                           981
                                        1234
                                ---------------
                                    981
                                    1962
                                      2943
                                        3924
                                ----------------
                                  1210554
Algorithmic is a branch of computer science that consists of designing and analyzing computer algorithms
1. The “design” pertain to
i. The description of algorithm at an abstract level by means of a pseudo language, and
ii. Proof of correctness that is, the algorithm solves the given problem in all cases.

2. The “analysis” deals with performance evaluation (complexity analysis).

We start with defining the model of computation, which is usually the Random Access Machine (RAM) model, but other models of computations can be use such as PRAM. Once the model of computation has been defined, an algorithm can be describe using a simple language (or pseudo language) whose syntax is close to programming language such as C or java.

Algorithm's Performance

Two important ways to characterize the effectiveness of an algorithm are its space complexity and time complexity. Time complexity of an algorithm concerns determining an expression of the number of steps needed as a function of the problem size. Since the step count measure is somewhat coarse, one does not aim at obtaining an exact step count. Instead, one attempts only to get asymptotic bounds on the step count. Asymptotic analysis makes use of the O (Big Oh) notation. Two other notational constructs used by computer scientists in the analysis of algorithms are Θ (Big Theta) notation and Ω (Big Omega) notation.
The performance evaluation of an algorithm is obtained by totaling the number of occurrences of each operation when running the algorithm. The performance of an algorithm is evaluated as a function of the input size n and is to be considered modulo a multiplicative constant.

The following notations are commonly use notations in performance analysis and used to characterize the complexity of an algorithm.

Θ-Notation (Same order)

This notation bounds a function to within constant factors. We say f(n) = Θ(g(n)) if there exist positive constants n0, c1 and c2 such that to the right of n0 the value of f(n) always lies between c1 g(n) and c2 g(n) inclusive.

In the set notation, we write as follows:

Θ(g(n)) = {f(n) : there exist positive constants c1, c1, and n0 such that 0 ≤ c1 g(n) ≤ f(n) ≤ c2 g(n) for all n ≥ n0}

We say that is g(n) an asymptotically tight bound for f(n).

Graphically, for all values of n to the right of n0, the value of f(n) lies at or above c1 g(n) and at or below c2 g(n). In other words, for all n ≥ n0, the function f(n) is equal to g(n) to within a constant factor. We say that g(n) is an asymptotically tight bound for f(n).

In the set terminology, f(n) is said to be a member of the set Θ(g(n)) of functions. In other words, because O(g(n)) is a set, we could write

f(n) ∈ Θ(g(n))

to indicate that f(n) is a member of Θ(g(n)). Instead, we write

f(n) = Θ(g(n))

to express the same notation.

Historically, this notation is "f(n) = Θ(g(n))" although the idea that f(n) is equal to something called Θ(g(n)) is misleading.

Example: n2/2 − 2n = (n2), with c1 = 1/4, c2 = 1/2, and n0 = 8.


Ο-Notation (Upper Bound)

This notation gives an upper bound for a function to within a constant factor. We write f(n) = O(g(n)) if there are positive constants n0 and c such that to the right of n0, the value of f(n) always lies on or below c g(n).

In the set notation, we write as follows: For a given function g(n), the set of functions

Ο(g(n)) = {f(n): there exist positive constants c and n0 such that 0 ≤ f(n) ≤ c g(n) for all n ≥ n0}

We say that the function g(n) is an asymptotic upper bound for the function f(n). We use Ο-notation to give an upper bound on a function, to within a constant factor.

Graphically, for all values of n to the right of n0, the value of the function f(n) is on or below g(n). We write f(n) = O(g(n)) to indicate that a function f(n) is a member of the set Ο(g(n)) i.e.

f(n) ∈ Ο(g(n))

Note that f(n) = Θ(g(n)) implies f(n) = Ο(g(n)), since Θ-notation is a stronger notation than Ο-notation.

Example: 2n2 = Ο(n3), with c = 1 and n0 = 2.

Equivalently, we may also define f is of order g as follows:

If f(n) and g(n) are functions defined on the positive integers, then f(n) is Ο(g(n)) if and only if there is a c > 0 and an n0 > 0 such that

| f(n) | ≤ | g(n) | for all n ≥ n0

Historical Note: The notation was introduced in 1892 by the German mathematician Paul Bachman. 

Ω-Notation (Lower Bound)

This notation gives a lower bound for a function to within a constant factor. We write f(n) = Ω(g(n)) if there are positive constants n0 and c such that to the right of n0, the value of f(n) always lies on or above c g(n).

In the set notation, we write as follows: For a given function g(n), the set of functions

Ω(g(n)) = {f(n) : there exist positive constants c and n0 such that 0 ≤ c g(n) ≤ f(n) for all n ≥ n0}

We say that the function g(n) is an asymptotic lower bound for the function f(n).

The intuition behind Ω-notation is shown above.

Example: √n = (lg n), with c = 1 and n0 = 16.

Algorithm Analysis

The complexity of an algorithm is a function g(n) that gives the upper bound of the number of operation (or running time) performed by an algorithm when the input size is n.

There are two interpretations of upper bound.

Worst-case Complexity
The running time for any given size input will be lower than the upper bound except possibly for some values of the input where the maximum is reached.
Average-case Complexity
The running time for any given size input will be the average number of operations over all problem instances for a given size.

Because, it is quite difficult to estimate the statistical behavior of the input, most of the time we content ourselves to a worst case behavior. Most of the time, the complexity of g(n) is approximated by its family o(f(n)) where f(n) is one of the following functions. n (linear complexity), log n (logarithmic complexity), na where a ≥ 2 (polynomial complexity), an (exponential complexity).

 Optimality

Once the complexity of an algorithm has been estimated, the question arises whether this algorithm is optimal. An algorithm for a given problem is optimal if its complexity reaches the lower bound over all the algorithms solving this problem. For example, any algorithm solving “the intersection of n segments” problem will execute at least n2 operations in the worst case even if it does nothing but print the output. This is abbreviated by saying that the problem has Ω(n2) complexity. If one finds an O(n2) algorithm that solve this problem, it will be optimal and of complexity Θ(n2).

Reduction

Another technique for estimating the complexity of a problem is the transformation of problems, also called problem reduction. As an example, suppose we know a lower bound for a problem A, and that we would like to estimate a lower bound for a problem B. If we can transform A into B by a transformation step whose cost is less than that for solving A, then B has the same bound as A.

The Convex hull problem nicely illustrates "reduction" technique. A lower bound of Convex-hull problem established by reducing the sorting problem (complexity: Θ(n log n)) to the Convex hull problem.

Read More

C Language : Pointer Fundamental

Pointer Fundamental

In the simplest term pointer is a nearly integer variable which stores a memmory address of a computer which may contain other variable or even another pointer.

If a variable contains address of another variable than it is said that first variable points to second. Pointer can also be represented as a refrence to another variable but there is very subtle diffrence in the two statements which is mostly dependent upon situation and enviorment.

Pointer is generally of size of integer on the machine but it may be of different type which indicates the type of variable the pointer is pointing to decides pointers properties and behaviour. Pointer of one type cannot be implicitly converted from one type to another but can be explicitly converted using type casting. In such a conversion a pointer always assumes that it is point to a object of its type but reality may differ and if used incorrectly may lead to disasters including permanent machine damage.

Also it is important to note that all operation perform on pointers are done through two operators '*' (Star) and '&' (Ampercent). '&' is a unary operator that returns a memmory address of a variable. '*' is complement of '&' and return value stored at a memmory location stored in a pointer. '*' can interpreted as statement "at address" while '&' can be interpreted as statement "address of".


Pointer Variable

Declaring a pointer variable is quite similar to declaring an normal variable all you have to do is to insert a star '*' operator before it.


General form of pointer declaration is -

type* name;

where type represent the type to which pointer thinks it is pointing to.

Pointers to machine defined as well as user-defined types can be made.

Multiple pointers of similar type can be declared in one statement but make sure you use * before every one otherwise they will become a variable of that type.

Pointer Assignment

This is a type of expression used to assign value of one pointer to another using assignment operator '=' . In this value of right hand side points to memmory address of variable stored in left hand side pointer. As a result both pointers point to same memmory location after this expression.

Pointer of similar type can be used in expression easily as shown below but for diffrent type pointers you need to type cast them as shown in next section.

//
#include ‹stdio.h›
int main ()
{
   char ch = a;
   char* p1, *p2;
   p1 = &ch;
   p2 = p1; // Pointer Assignement Taking Place 
   printf (" *p1 = %c And *p2 = %c", *p1,*p2); // Prints 'a' twice
   return 0;
}
Read More