10.1

Write a program to read a list containing item name, item code, and cost interactively and produce a three column output as shown below.

Name Code Cost
Turbo C++ 1001 250.95
C Primer 905 95.70
    … … … …    … … … …    … … … …

Note that the name and code are left-justified and the cost is right justified with a precision of two digits. Trailing zeros are shown.

Answer

OUTPUT

name                                         code                  cost

——————————————————————————

Tarbo C++                             1001                     250.95

C Primer                                 905                      95.70

algorithm                               1111                      120.50

Principle of electronics      2220                    150.85

Solution of balaguruswamy 6666                  145.00

10.2

Modify the above program to fill the unused spaces with hyphens.

Answer

OUTPUT

name                                         code                  cost

—————————————————————————————-

Tarbo C++ ——————– 1001———–250.95

C Primer ———————-905————-95.70

algorithm———————-1111————120.50

Principle of electronics——2220———–150.85

Solution of balaguruswamy–6666——— 145.00

10.3

Write a program which reads a text from the keyboard and displays the following information on the screen in two columns:

  • (a) Number of lines
  • (b) Number of words
  • (c) Number of characters
    Strings should be left-justified and numbers should be right-justified in a suitable field width.
Answer

OUTPUT

Enter text :

santo reads in class five.

He always speak the truth.

He respects his teachers.

He feels shy when I admire him.

I like his morality.
Number of lines       Number of words         Number of characters

5                                        25                                         128

Note: If you press the Enter button two times, the program will terminate.


Next Previous