11.1

Write a program that reads a text file and creates another file that is identical except that every sequence of consecutive blank spaces is replaced by a single space.

Answer

Note: Before you run this program you just create a ‘.txt’ document to a particular drive where your compiler was installed.

11.2

A file contains a list of telephone numbers in the following form

John 23456

Ahmed 9876

…………… …………

the names contain only one word and the names and telephone numbers are separated by white spaces. Write program to read this file and output the list in two columns. The names should be left justified and the numbers should be right justified.

Answer

Note: You just create a ‘.txt’ document like as question no 11.1 which contains peoples name and phone number.

OUTPUT

Enter your desired name to find mobile number : john
john 23456

11.3

Write a program that will create a data file containing the list of telephone numbers given in exercise in 11.2. Use a class object to store each set of data.

Answer

Note: When you run this program, It will create a txt document named ‘phone’.

11.4

Write an interactive, menu-driven program that will access the file created in exercise 11.3 and implement the tasks:

  • (a) Determine the telephone number of the specified person.
  • (b) Determine the name if a telephone number is known.
  • (c) Update, the telephone number, whenever there is a change.
Answer

During First Run :

OUTPUT

Press 1 to find mobile number of specified person
Press 2 to find name of specified number
Press 3 to update number
What is your option ?: 1
Enter the desired name : john
john 23456

During Second Run :

OUTPUT

Press 1 to find mobile number of specified person
Press 2 to find name of specified number
Press 3 to update number
What is your option ?: 3
Enter the name whose number have to change : Ahmed
Enter changed mobile number of Ahmed : 9876


Next Previous