answersLogoWhite

0

Delphi and Pascal Programming

Pascal was first released in 1970, it is an influential imperative and procedural programming language. It was created by Niklaus Wirth. The language is influenced by the ALGOL programming language.

163 Questions

Why is pascal is not suitable for systems programming?

User Avatar

Asked by Wiki User

What gives you that idea? The entire OS of the UCSD-pSystem & the original version of MAC OS, on the 68000, were written in Pascal. Both worked quite well.

How do you write an algorithm to find the number of permutations or combinations?

User Avatar

Asked by Wiki User

Permutations and combinations are two separate things. Although we often use them interchangeably in English, we need a more precise definition in mathematics, such that ABC and CBA are regarded as being two different permutations of the same combination. In other words, the order of the elements is important in a permutation but is completely irrelevant in a combination.

First we have to define what it means to create a combination or permutation. Typically we have a set from which we must make a subset. The number of elements in the set is typically defined using the variable n while the number of elements in the subset is r. Thus we can formally define a permutation mathematically using the function P(n,r) and a combination as C(n,r).

We must also consider whether elements may be repeated within a combination or a permutation. For instance, when selecting numbers for a lottery, no number may be repeated in any combination but in a 4-digit combination lock, any digit may be repeated in a permutation.

Note that a combination lock is really a permutation lock in mathematics and is the perverse way of remembering the mathematical difference between a combination and a permutation.

Thus we have 4 possible variations to cater for. In order of difficulty, they are:

  1. Permutations with repetition
  2. Permutations without repetition
  3. Combinations without repetition
  4. Combinations with repetition

Let's deal with them one at a time.

1. Permutations with repetition

To calculate P(n,r) with repetitions, for every selection, r, there are always n possibilities, thus we have n^r permutations.

In a 3-digit combination lock, each digit has ten possibilities, 0 through 9, so there are 10^3=10x10x10=1000 permutations. This stands to reason because the permutations form all of the numeric values from 000 through to 999, which is 1000 different values.

In C, we can write this function as:

unsigned long long permutations (unsigned long long n, unsigned long long r) {

return pow(n,r); /* use standard library function */

}

2. Permutations without repetition

To calculate P(n,r) without repetitions we must reduce the set by one element each time we make a selection. If we go back to our 3-digit combination lock, we have 10 choices for the first digit which leaves 9 choices for the next and 8 for the next. So instead of 10x10x10=1000 permutations we only have 10x9x8=720 permutations.

Although fairly simple to work out in this case, we need a formula that is generalised to cater for all cases, just as n^r works for all permutations with repetitions.

We can see that 10x9x8 is the initial product of 10! (factorial 10) which is 10x9x8x7x6x5x4x3x2x1. So we need a formula that ignores everything after the 8. The portion after the 8 is 7x6x5x4x3x2x1 which is 7! and we can calculate that from (n-r)!=(10-3)!=7!

Having determined the portion we need to ignore, the rules of multiplication and division state that if we multiply by x and subsequently divide by x, then the two x's must cancel each other out. Thus we get:

10!/7!=(10x9x8x7!)/7!=10x9x8=720

Using formal notation, P(n,r) without repetition is therefore n!/(n-r)!

In C, we must first write a function to calculate factorials:

unsigned long long factorial (unsigned long long n) {

return (n>1)?factorial(n-1):1; /* recursive function */

}

With that in place, we can now write a function to handle permutations without repetitions:

unsigned long long permutations_norep (unsigned long long n, unsigned long long r) {

return factorial(n)/factorial(n-r);

}

3. Combinations without repetition

C(n,r) without repetition is simply an extension of P(n,r) without repetition. Every combination of r has r! permutations, so if we divide P(n,r) by r! we will get C(n,r). Expressing this formally, C(n,r) without repetition is n!/((n-r)!r!)

Going back to our 3-digits from 10, there are 10!/((10-3)!3!)=10!/(7!3!)=(10x9x8x7!)/(7!3!)=(10x9x8)/3!=720/6=120 combinations without repetition.

Using the factorial function shown above, we can write a C function to handle combinations without repetition:

unsigned long long combinations_norep (unsigned long long n, unsigned long long r) {

return factorial(n)/(factorial(n-r)*factorial(r));

}

4. Combinations with repetition

Combinations with repetition is the hardest concept to wrap your head around.

Going back to our 3-digits from 10, let's begin enumerating all the combinations so we can verify the answer at the end. We start by enumerating all those that combinations that begin with a 0:

000, 001, 002, 003, 004, 005, 006, 007, 008, 009

011, 012, 013, 014, 015, 016, 017, 018, 019

022, 023, 024, 025, 026, 027, 028, 029

033, 034, 035, 036, 037, 038, 039

044, 045, 046, 047, 048, 049

055, 056, 057, 058, 059

066, 067, 068, 069

077, 078, 079

088, 089

099

Note that there is no 010 because it is a permutation of 001. Similarly with 021 which is a permutation of 012. As a result of this, each row has one less combination than the one above. Thus there are 10+9+8+7+6+5+4+3+2+1=55 combinations.

If we now enumerate all those that begin with a 1, we see a similar pattern emerges:

111, 112, 113, 114, 115, 116, 117, 118, 119

122, 123, 124, 125, 126, 127, 128, 129

133, 134, 135, 136, 137, 138, 139

144, 145, 146, 147, 148, 149

155, 156, 157, 158, 159

166, 167, 168, 169

177, 178, 179

188, 189

199

This time we have 9+8+7+6+5+4+3+2+1=45 combinations.

Following the same logic, the next section must have 8+7+6+5+4+3+2+1=36 combinations, followed by 28, 21, 15, 10, 6, 3 and finally 1. Thus there are 220 combinations in total.

The formula to work this out is quite complex, however it becomes simpler when we look at the problem in a different way. Suppose we have 10 boxes and each box holds at least 3 of the same digit. We can number these boxes 0 through 9 according to those digits. Let us also suppose that we can only move in one direction, from box 0 to box 9, and we must stop at every box along the way. This means we must make 9 transitions from one box to the next.

While we along the row, we carry a tray with 3 slots. Whenever we stop at a box (including box 0 where we start from) we can either pick a number from the box or we can move onto the next box. if we pick a number, we place it in the first slot. We can then pick another or we can move on. When we have filled all the slots, we simply move on until we reach box 9. If we reach box 9 and still have slots available, we must pick as many 9s as we need to fill the remaining slots.

It probably sounds far more complex than it really is. By imagining a selection being done this way we can create a convenient binary notation. For instance, if we say that 1 means pick a number and 0 means move onto the next box, the sequence 101010000000 would tell us we selected the combination 123 while the sequence 000000000111 tells us we selected 999. Every combination is therefore reduced to 12-bit value containing exactly three 1s and nine 0s, and it is these specific combinations we are actually looking for.

C(n,r) with repetition is formally expressed as (r+n-1)!/(r!(n-1)!)

If we plug in the actual numbers we find:

=(3+10-1)!/(3!(10-1)!)

=12!/(3!9!)

=(12x11x10x9!)/(3!9!)

=(12x11x10)/3!

=1320/(3x2x1)

=1320/6

=220 combinations with repetition.

This type of problem might be expressed in other ways. For example, how many different ways can we fill a box with 100 sweets from 30 different sweets. C(n,r) is C(30,100) thus we find:

=(100+30-1)!/(100!(30-1)!)

=129!/(100!29!)

=(129x128x127x...x101x100!)/(100!29!)

=(129x128x127x...x101)/29!

=5.3302324527079900778691094496787e+59/8,841,761,993,739,701,954,543,616,000,000

=60,284,731,216,266,553,294,577,246,880 combinations with repetition.

In C we can use the following function in conjunction with the factorial function shown earlier:

unsigned long long combinations (unsigned long long n, unsigned long long r) {

return factorial(n+r-1)/(factorial(r)*factorial(n-1));

}

We might also have similar problems with an additional restriction. For instance, we might be asked to select 100 sweets from 30 different sweets selecting at least 1 of each type. This reduces the number of slots to 100-30=70 but we have the same number of transitions, so we get:

=(70+30-1)!/(100!(30-1)!)

=99!/(70!29!)

=(99x98x97x...x71x70!)/(70!29!)

=(99x98x97x...x71)/29!

=7.7910971370578048745872324992773e+55/8,841,761,993,739,701,954,543,616,000,000

=8,811,701,946,483,283,447,189,128 combinations with repetition.

To accommodate this caveat, we can use the following function instead:

unsigned long long combinations2 (unsigned long long n, unsigned long long r) {

return factorial(n-1)/(factorial(r)*factorial(n-1));

}

How do you convert Pa to cfm?

User Avatar

Asked by Wiki User

You can't.

Pascals (pa) area messurement of pressure. CFM (cubic feet per minute) is a rate of flow. However, there is a device called a manometer which is used to measure either pressure(in pascals) or air flow in(in cubic feet). Most commonly used for blower door tests.

What are the disadvantage and advantage of pascal programming?

User Avatar

Asked by Wiki User

You would be using an obsolete development environment and a pretty old dialect.

What is the difference between read and readln in pascal?

User Avatar

Asked by Wiki User

Readln discards all other values on the same line, but read does not.

What is declaration in pascal programming?

User Avatar

Asked by Wiki User

A "declaration" in computer programming is when you define the properties of variables or functions used in the program. Most programming languages require you to "declare" the variables to be used within the program before they are used in any calculations or other operations. For example, in the C program language, you could define a variable like this: float distance; this declares a variable called "distance" and says that it is a "floating point" variable, that is, a numeric value, with optional decimal places. If we declare two other variables, and give them the names "speed" and "time", we can then use them within the main program, like this: distance = speed * time; (where the "*" is used in C and most other languages to mean multiply). You are free to use abbreviations for the variables, declaring them like this: float D, S, T; and then writing the expression above as: D = S * T; but it is considered "good programming practice" to use longer, "meaningful" names, especially in longer programs, where it would make the programs easier to read, and it would make it easier to remember what the variable names stood for. As well as "float" types (which may be called "real" or "double" in other programming languages), there are also some other types: For example, "int" types (sometimes written as "integer" in other languages) are for declaring a variable to hold a whole number, one without any decimal places. An example of this might be the declarations: int goalsfor, goalsagainst, goaldiff; int points; int won, drawn, lost; which could be used in the expressions: goaldiff = goalsfor - goalsgainst; points = won * 3 + drawn; The reason for declaring the variables as "int" rather than "float" is because, logically, you can't score 1.5 or 2.736 goals, and also, because variables declared as "int" can be stored using less computer memory. Another declaration type might be a "string" or "character" type, used to store text, that is, any mixture of letters and numbers, such as names, addresses, words - anything other than numeric values. In some languages, when you declare such a text variable, you also have to say how many letters are to be allowed. For example, in C, the declarations: char firstname[12], secondname[20]; char address[50]; allows 12 letters for the firstname, 20 for the secondname, and 50 letters/and or numbers for the address. Most computer languages will give an error if you make a mistake in a declaration, or if you forget to declare the variable - this can stop you from making mistakes later. For example if you had the declaration: int numchildren, sons, daughters; and then used the expression: children = sons + duaghters; the computer would show two errors - one because you declared the variable as "numchildren", but used "children" in the expression, and secondly because you mis-spelled "daughters". As stated above, this can also apply to functions (also known as "procedures" or "subroutines"), but this a slightly more complicated topic which could be the subject of another question.

What do you need to start programming using pascal?

User Avatar

Asked by Wiki User

Three simple steps: (1) buy or rent a boook about Pascal, (2) read book and follow the exercised provided in book, (3) write program in Pascal. Honestly. A programming language is in many ways as complex as a human language; there is no simple answer to "how does one speak French, or Spanish, or Pascal, or C++" However, in all those cases, an abundance of books is available. Since they all vary not just in quality, but also with regards to the expectation to your background knowledge, its typicaly best to go into a bookstore and compare a few.

What is the full form of PASCAL?

User Avatar

Asked by Wiki User

PASCAL has 3 definitions actually. They are:-

1. Programming Language Based For Blaise Pascal.

2. Pedantry and Strictness Created A Language.

3. Philips Automatic Source Calculator.

What are the codes for pascal triangle by using pascal compiler?

User Avatar

Asked by Dommy1987

the logic i have used is nCr => n!/(r!*(n-r)!) for example the outer loop counter is 'n' and the inner loop counter is 'r' , then the corresponding element of the pascal's triangle will be nCr. keep in mind that both the loops will have to start from zero. #include<stdio.h> main()

{

int num,i,j,k,space;

int difffact=1,diff,n,r,x,y,comb=0,nfact=1,rfact=1;

printf("please enter the number of lines\n");

scanf("%d",&num); k=num-1;

space=num-1;

for(i=0;i<num;i++)

{

k=space--;

for(;k>0;k--)

{

printf(" ");

}

for(j=0;j<=i;j++)

{

comb=0;

nfact=1;

rfact=1;

difffact=1; for(n=i;n>=1;n--)

nfact=nfact*n; for(r=j;r>=1;r--)

rfact=rfact*r; diff=i-j;

for(;diff>=1;diff--)

difffact=difffact*diff; comb=(nfact/(rfact*difffact));

printf("%d ",comb);

}

printf("\n");

}

}

What are the features of pascal programming language?

User Avatar

Asked by Wiki User

There are many features that can be considered, and to go through all of them is a big undertaking.

What I however consider the most important is its logical buildup.

It's most logical way of working mean that the threshold for learning and using it is very low.

Anybody can have a look at source code, and start writing Pascal Software.

It is a compiling language also. The source code makes assembler code when compiled. This provides for the highest speed during execution.

What are the advantages and disadvantages of a compiler?

User Avatar

Asked by Wiki User

The advantages are that the compiler can see each translation unit as a whole and can therefore optimise the resultant machine code accordingly. For instance, trivial functions that are accessed often, such as array suffix operators, can benefit from inline expansion, thus eliminating the need for an otherwise costly function call.

Also, constant expressions can be evaluated at compile time using compile-time evaluation. For instance, consider the following code:

constexpr int fac (constexpr num) {

return num==1?1:fac (num-1);

}

void f() {

int x {fac (7)};

// ...

}

A good compiler will replace the recursive function call fac(7) with the constant value 5040.

In addition, compilers (along with the corresponding linker) help eliminate many common errors such as static type errors, syntax errors and linkage errors. They can also test programmer's assumptions through static assertions. The more errors detected and eliminated at compile time, the fewer errors there will be at runtime, which will primarily consist of logic errors.

The disadvantage of compilers is that compilation can take a long time, particularly with large projects. Each time the program is modified, it must be recompiled. compilation times can be reduced by precompiling headers that are not expected to change very often, creating intermediate files that are much faster to compile. There is also no need to recompile translation units that are unaffected by changes in code, most of which only occur due to changes with a common header. Nevertheless, a non-trivial application can still take several minutes to produce a working executable and the more time spent compiling the less time you can spend debugging the runtime logic.

Interpreted languages are executed in real-time without the need for compilation. However, execution times are very much slower due to the need to constantly translate high-level source code into low-level machine code.

There are, however, languages that are both compiled and interpreted. Java is a typical example. The source code is first compiled to an intermediate code known as Java byte code which can then be interpreted by the Java virtual machine to produce the machine code. Unlike traditional compilers which produce native machine code that only runs one the architecture it was intended for, Java byte code is completely portable and can be executed upon any machine with a suitable Java virtual machine implementation, which is pretty much everything these days. However, interpreted languages (including Java) are not suitable for low-level programming, they are only suitable for applications programming. Compiled languages such as C and C++ are suitable for all types of programming, hence they are termed general purpose languages.

What is Delphi known for?

User Avatar

Asked by Wiki User

Delphi is the name of the commercial Integrated Development Environment (IDE) for RAD created by Borland (see www.borland.com). Borland sold out Delphi and other RAD tools in the year 2008 to a company called Embarcadero Technologies which is now focusing on the newer versions of Delphi and other tools.

RAD stands for Rapid Application Development, meaning that common develoment tasks, such as creating user interfaces, have been made much easier. For instance, without RAD you would have to specify XY coordinates for every button and screen element, RAD allows you to drag and drop buttons onto screens using your mouse similar to a Mr. Potato Head.

The programming language in Delphi was Object Pascal, which is similar to the old "Structured" Pascal created by Niklaus Wirth in 1970. Though earlier their was a distinction made between Object Pascal being used as the language of Delphi and Delphi being considered as the IDE for the object pascal language but according to the definition used in the help files in Delphi 7 versions onwards we can see that infact Borland itself rebranded Delphi itself as a language. So, Delphi now becomes a language with a dedicated IDE available for it.

Delphi allows you to create Standard windows programs, ISAPI applications (web applications), Web Services, NT Services, console applications, DLL's, ActiveX controls, and COM objects.

The last version of the software "Delphi" was the Delphi 8 for .NET. After this it become sold as a part of the Borland Developer Studio (or simple BDS) in the versions 2005 and 2006, with the ability to compile for other platforms. At this time, the language stops to calls itself Object Pascal, but Delphi Language instead due the Microsoft .NET Framework support.

There is also a limited-but-free version of the BDS 2006 called Turbo Delphi. Its price is more attractive, but it does not have all the features that your Big Brother has: the languages that it supports aren't integrated, there are separated versions for each language and they can't be installed at the same machine (there is a protection to avoid this). There is another protection that doesn't let you to install additional "features" (Components) in the IDE, but this protection can be removed at a little charge.

The newest version of Delphi as of now is Delphi XE with its launch in 2010 it provides various capabilities to the language. However, there are still certain things missing with Delphi that its competing cousins are having which are - 64 bit support for application development, mobile phone application development and cross platform development to name a few. Though Embarcadero suggests that the Delphi compiler is going to undergo a complete overhaul and restructuring in the coming up releases so people might be seeing 64 bit support in Delphi in not much time. The 64 bit version is promised to be out in the first half of 2011.

PASCAL language full form?

User Avatar

Asked by Wiki User

Pedantry And Strictness Created A Language

What is turbo pascal programming language?

User Avatar

Asked by Wiki User

Every Pascal program must follow a basic structure. While this structure is very similar to Karel programming, there are several differences. Below is the basic structure that every Pascal program must follow.

PROGRAMProgramName;

VAR VariableName : VariableType; VariableName : VariableType; ...

PROCEDUREProcedureName;

variables here if necessary BEGIN

Some Code;

END;

FUNCTIONFunctionName(variableList): VariableType;

variables here if necessary

BEGINSome Code if necessary; FunctionName := some expression More Code if necessary;

END; ... more functions and procedures if necessary ...

BEGIN the main program block. It should be small and all work should be delegated to the procedures and functions. It often consists of a WHILE loop that calls in turn procedures and functions in the appropriate order. END.

Who is the creator of the PASCAL language?

User Avatar

Asked by Wiki User

Niklaus Wirth invented Pascal, along with other programming languages.

Why was turbo pascal programming named after the french mathematician blaise pascal?

User Avatar

Asked by Wiki User

Pascal programming was invented by Niklaus E. Wirth, a Swiss computer scientist in 1968. It was named in honour of Blaise Pascal (1623-1662) because he invented the first automatic adding machine.

What is the input alphabet of pascal?

User Avatar

Asked by Wiki User

I assume you want to ask what is the command from people to type in a input.

First of all you need a VAR (variable), variables can be defined as:

1. Boolean (True or False)

2. integer (have limit)

3. real (accept decimal places)

4. char (ONE character)

5. string (sentence)

then you need the READLN(var),

such as the variable is N then you need readln(n);

Hope I can solve your question.

What are enumerated data types in pascal?

User Avatar

Asked by Wiki User

Pascal has 4 primitive data types: integer; boolean; char and; real. These 4 provide the basic building blocks for more complex types.

What do you mean by procedure?

User Avatar

Asked by Wiki User

A procedure is a specified series of actions or operations which have to be executed in the same manner in order to always obtain the same result under the same circumstances (for example, emergency procedures). Less precisely speaking, this word can indicate a sequence of activities, tasks, steps, decisions, calculations and processes, that when undertaken in the sequence laid down produces the described result, product or outcome. A procedure usually induces a change. It is in the scientific method. So it is in Particular!