Microsoft Office Tutorials and References
In Depth Information
F.5 Pascal
Visual C++ is a marriage between the C++ programming language and the Windows graphical
environment. Visual C++ is not nearly as user-friendly as Visual Basic. This is due in part to the
nature of the underlying language (C is less friendly than BASIC), in part to the fact that C++ is a
fully object-oriented language and therefore naturally more complicated, and in part to the fact
that Visual C++ is designed to control the Windows environment at a more fundamental level than
Visual Basic. For instance, Visual Basic does not provide ways to create a text box whose text can
use more than one color, set the tabs in a list box, or change the color of the caption in a command
button, and so on. Simply put, when programming in VB (or VBA), we must sacrifice power in
some directions in favor of power in other directions and a simpler programming environment.
F.5 Pascal
Pascal was developed by Niklaus Wirth (pronounced "Virt") in the late 1960s and early 1970s.
The goal was to produce a language that could be easily implemented on a variety of computers
and that would provide students with a model teaching language. That is to say, Pascal is full of
features that encourage well-written and well-structured programs. Indeed, many universities
teach Pascal to their computer science students as a first language. Pascal has also migrated to the
personal computer arena, first with Borland's Turbo Pascal and more recently with Borland's
visual programming environment called Delphi.
For contrast, here is how our program to compute the average would look in Pascal. Text
contained within curly braces ({,}) are comments that are ignored by the computer.
{ Pascal program to compute the average
of a set of at most 100 numbers }
program average (input, output);
{ Declare some variables }
var
Num, i : integer;
Ave, Sum, NextNum : real;
begin
{ Ask for the number of numbers }
writeln('Enter the number of numbers');
readln(Num);
{ If Num is between 1 and 100 then proceed }
if ((Num > 0 ) and (Num <= 100)) then
begin
Sum := 0;
{ Loop to collect the numbers to average }
for i := 1 to Num do
begin
{ Ask for next number }
writeln('Enter next number');
readln(NextNum);
{ Add the number to the running sum }
Sum := Sum + NextNum;
end
{ Compute the average }
Ave := Sum / Num;
{ Display the average }
writeln('The average is: ', Ave);
end
end
 
Search JabSto ::




Custom Search