TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Mike Bates 5598 Computer_Systems <[log in to unmask]>
Reply To:
Date:
Wed, 3 Mar 1999 10:06:00 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (50 lines)
If you want to make the contrast more dramatic, add some plain text, a
variable-length string, and an integer in hexadecimal.

How many lines does it take to do this in Ada, C++, or Java:

      printf("The result for %-30s is %10.2f (%08x)\n", x, y, z);

My question: Has anyone written good Ada equivalents to printf and
scanf?

On Wed, 3 Mar 1999 09:28:37 -0500  [log in to unmask] wrote:
> > I thought you might enjoy this recent post by Cay Horstmann to the
> > Advanced Placement in Computer Science list.
>
> Let's include Ada in chronological order:
>
> > How do you print a floating-point number with field width 10 and two digits
> > after the decimal point, using only the standard library?
> >
> > C
> >    printf("%10.2f", x);
> >
> >
> > Ada
> >    Put (Item => X,
> >         Fore => 7,  -- width = Fore + Aft + 1 (the point)
> >         Aft  => 2,
> >         Exp  => 0);
> >
> >
> > C++
> >    cout << setw(10) << setprecision(2) << showpoint << x;
> >
> >
> > Java
> >    java.text.NumberFormat formatter
> >       = java.text.NumberFormat.getNumberInstance();
> >    formatter.setMinimumFractionDigits(2);
> >    formatter.setMaximumFractionDigits(2);
> >    s = formatter.format(x);
> >    for (int i = s.length(); i < 10; i++)
> >       System.out.print(' ');
> >    System.out.print(s);

-------------------------------------------------------------------------
Mike Bates                                 FlightSafety Simulation
Staff Engineer          [log in to unmask]  2700 North Hemlock Circle
Computer Systems Group  918-259-5598       Broken Arrow, Oklahoma 74012
-------------------------------------------------------------------------

ATOM RSS1 RSS2