0% found this document useful (0 votes)
16 views

LabExercises Module1

The document describes 20 programming exercises involving writing functions and algorithms to: 1) Calculate taxes and net pay based on hours worked 2) Calculate profit from ticket sales and costs for a movie theater 3) Convert between units of length measurement for the English and metric systems 4) Calculate the volume and surface area of cylinders 5) Compute sums of series and find numbers with most divisors 6) Convert decimal numbers to binary coded decimal 7) Multiply numbers by halving and accumulating 8) Sort buckets of colored pebbles 9) Remove multiple blanks from paragraphs 10) Find words matching a prefix 11) Implement a stack using a character array 12) Print numbers with commas for formatting

Uploaded by

Muthu Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

LabExercises Module1

The document describes 20 programming exercises involving writing functions and algorithms to: 1) Calculate taxes and net pay based on hours worked 2) Calculate profit from ticket sales and costs for a movie theater 3) Convert between units of length measurement for the English and metric systems 4) Calculate the volume and surface area of cylinders 5) Compute sums of series and find numbers with most divisors 6) Convert decimal numbers to binary coded decimal 7) Multiply numbers by halving and accumulating 8) Sort buckets of colored pebbles 9) Remove multiple blanks from paragraphs 10) Find words matching a prefix 11) Implement a stack using a character array 12) Print numbers with commas for formatting

Uploaded by

Muthu Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

TCS Elective

List of Exercises
Module I
Design the following programs by developing the Contract, Purpose, Header,
Example and Algorithm. Validate your algorithm by doing a dry run.

1. Utopias tax accountants always use programs that compute income taxes even
though the tax rate is a solid, never-changing 15%. Define the program tax, which
determines the tax on the gross pay. Also define netpay. The program determines
the net pay of an employee from the number of hours worked. Assume an hourly
rate of $12.
2. An old-style movie theater has a simple profit program. Each customer pays $5
per ticket. Every performance costs the theater $20, plus $.50 per attendee.
Develop the program total-profit. It consumes the number of attendees (of a
show) and produces how much income the attendees produce.
3. The United States uses the English system of (length) measurements. The rest of
the world uses the metric system. So, people who travel abroad and companies
that trade with foreign partners often need to convert English measurements to
metric ones and vice versa. Here is a table that shows the six major units of
length measurements of the English system: Develop the programs inches->cm,
feet->inches, yards->feet, rods->yards, furlongs->rods, and miles->furlongs. Then
develop the programs feet->cm, yards->cm, rods->inches, and miles->feet.
Develop the programs inches->cm, feet->inches, yards->feet, rods->yards,
furlongs->rods, and miles->furlongs. Then develop the programs feet->cm,
yards->cm, rods->inches, and miles->feet. Hint: Reuse programs as much as
possible. Use variable definitions to specify constants.
4. Develop the program volume-cylinder. It consumes the radius of a cylinders base
disk and its height; it computes the volume of the cylinder.
5. Develop area-cylinder. The program consumes the radius of the cylinders base
disk and its height. Its result is the surface area of the cylinder.
6. Write a program to compute the sum of the first n terms (n >=1) of the series s =
1-3+5-7+9-.
7. Write a program to find the number that has most divisors for the integers in the
range 1 to 100
8. Write a program that accepts as input a decimal number and converts it to the
binary coded decimal representation. In the BCD scheme each digit is
represented by a 4 bit binary code
9. It is possible to multiply two numbers x and y by repeatedly halving y (integer
division) when it is even and reducing it by 1 when its odd. When y is odd the
current value of x is accumulated. When y is even x is doubled. Write a program
to implement this operation
10. The problem of Dutch national flag involves starting out with a row of n
buckets, i.e. bucket [1...n], each bucket containing a single pebble that is red,
white or blue. The task is to arrange the pebbles so that all reds occur before all
whites which in turn occur before all blue pebbles. Write a program to implement
the Dutch national flag problem.
11. Write a program to remove multiple blanks other than those at the start of new
paragraphs
12. Write a program that prints a list of all words in the text that contain the search
word as a prefix
13. Implement push and pop procedures that manipulate variable length strings stored
on a stack consisting of a fixed length character array.
14. Write a function called printWithCommas that takes a single nonnegative long
integer argument and displays it with commas inserted properly.
For example: printWithCommas(12045670); displays 12,045,670
printWithCommas(1); displays 1
15. Write a function to compute the distance between two points and use it to
develop another function that will compute the area of the triangle whose vertices
are A(x1, y1), B(x2, y2), and C(x3, y3). Use these functions to develop a
function which returns a value 1 if the point (x, y) lines inside the triangle ABC,
otherwise a value 0.
16. Given three variables x, y, z write a function to circularly shift their values to
right. In other words if x = 5, y = 8, z = 10 after circular shift y = 5, z = 8, x =10
after circular shift y = 5, z = 8 and x = 10. Call the function with variables a, b, c
to circularly shift values.
17. If x hashes to location k and the value there occurs alphabetically later than x,
then interchange the roles of x and table[k] and repeat the process until an empty
location is found. This has the effect of letting x take precedence in ordering over
keys that were inserted earlier but occur alphabetically later. Write a program to
implement the above
18. Create a structure to specify data of customers in a bank. The data to be stored is:
Account number, Name, Balance in account. Assume maximum of 200 customers
in the bank. (a) Write a function to print the Account number and name of each
customer with balance below Rs. 100. (b) If a customer request for withdrawal
or deposit, it is given in the form: Acct. no, amount, code (1 for deposit, 0 for
withdrawal) Write a program to give a message, The balance is insufficient for
the specified withdrawal.
19. Write a menu driven program that depicts the working of a library. The menu
options should be: 1. Add book information 2. Display book information 3. List
all books of given author 4. List the title of specified book 5. List the count of
books in the library 6. List the books in the order of accession number 7. Exit
Create a structure called library to hold accession number, title of the book,
author name, price of the book, and flag indicating whether book is issued or not.
20. Write a program that merges lines alternately from two files and writes the
results to new file. If one file has less number of lines than the other, the
remaining lines from the larger file should be simply copied into the target file.
************

You might also like