08.01.2023 Views

Learn to Program with C_ Learn to Program using the Popular C Programming Language ( PDFDrive )

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 5 ■ Programs with Repetition Logic

6. Assume that the fixed charge and the rate per unit are the same for all customers

and are given on the first line. This is followed by the data for the customers. Each

set of data consists of two lines: a name on the first line and the meter readings

on the second line. The “name” xxxx ends the data. Print the information for the

customers under a suitable heading. Also,

• Count how many customers were processed

• Print the total due to the electricity company

• Find the customer whose bill was the highest

7. A file contains data for several persons. The data for each person consists of their

gross salary, deductions allowed and rate of tax (e.g., 25, meaning 25%). Tax is

calculated by applying the rate of tax to (gross salary minus deductions). Net pay is

calculated by gross salary minus tax.

Under an appropriate heading, print the gross salary, tax deducted, net pay, and the percentage

of the gross salary that was paid in tax.

For each person, the data consists of two lines: a name on the first line and gross salary,

deductions allowed and rate of tax on the second line. The “name” xxxx ends the data. Also,

• Count how many persons were processed

• Print totals for gross salary, tax deducted and net pay

• Find the person who earned the highest net pay

8. Write a program that reads several lengths in inches and, for each, converts it to

yards, feet and inches. (1 yard = 3 feet, 1 foot = 12 inches). For example, if a length

is 100, the program should print 2 yd 2 ft 4 in. Choose an appropriate endof-data

marker.

9. Each line of data in a file consists of two lengths. Each length is given as two

numbers representing feet and inches. A line consisting of 0 0 only ends the data.

For each pair of lengths, print their sum. For example, if the lengths are 5 ft. 4

in. and 8 ft. 11 in., your program should print 14 ft. 3 in. The line of data for this

example would be given as

5 4 8 11

10. You are given a file containing an unknown amount of numbers. Each number

is one of the numbers 1 to 9. A number can appear zero or more times and can

appear anywhere in the file. The number 0 indicates the end of the data. Some

sample data are:

5 3 7 7 7 4 3 3 2 2 2 6 7 4 7 7

2 2 9 6 6 6 6 6 8 5 5 3 7 9 9 9 0

Write a program to read the data once and print the number that appears the most in

consecutive positions and the number of times it appears. Ignore the possibility of a tie.

For the above data, output should be 6 5.

137

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!