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

PF Assignment

The document provides instructions for 20 assignments related to algorithms and programming. It includes assignments on topics like prime number checking, sorting arrays, stacks, queues, strings, file operations, and phone bill generation. Students are asked to write algorithms to solve the problems and submit their work on the recommended learning platform. The course mentor will provide feedback and communicate which assignments should be completed.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

PF Assignment

The document provides instructions for 20 assignments related to algorithms and programming. It includes assignments on topics like prime number checking, sorting arrays, stacks, queues, strings, file operations, and phone bill generation. Students are asked to write algorithms to solve the problems and submit their work on the recommended learning platform. The course mentor will provide feedback and communicate which assignments should be completed.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

[11:48 PM] Soumya S Patil (Guest)

Instructions
Solve the assignments and submit on the recommended platform. Discuss with your course mentor for
feedback and improvements. During the faculty connect session, the course mentor will communicate
how many and which assignments from the following set are expected to be uploaded on the learning
platform/shared location.

Assignments
Mandatory

1) Write down an algorithm that reads in a positive integer x and tests if it is a prime number. 

Note: (1) A number is prime if it is only divisible by 1 and itself.

          (2) The integer 1 is defined as non-prime.

2) Write down an algorithm tofind out smallest and largest amongst 3 elements.

3) Modify the above algorithm so that it will work with N elements where N is accepted from the
user.

4) Write down an algorithm to read in an integer between 0 and 99 and output the value in
English.  For example, if the input is 28, it should output “twenty-eight”. 

Recommended

5) Write down an algorithm to get the weight (in kilograms) and height (in meters) of a person.
Then calculate and print the Body Mass Index (BMI) according to the formula:

            BMI = weight / (height*height)

The BMI should be printed with 3 decimal places.  You should choose an appropriate data types
and names for your variables.   

6) Write down an algorithm to read in a temperature in Celsius and convert it to Fahrenheit.  The
relationship between Celsius and Fahrenheit is

            C =  (F-32)*5/9.

7) Write down an algorithm to find out roots of a quadratic equation. Please note that roots can
be imaginary.

8) Write down an algorithm that reads in the number of seconds and converts it to hours,
minutes and seconds.  A sample output of your program is as follows.  Don’t bother with the
singular or plural forms of the nouns.
Please enter the number of seconds --> 500500 seconds = 0 hours 8 minutes 20 seconds
Hint: Use the / and % operators.

9) Write down an algorithm that reads in a mark of a student (which is an integer between 0 and
100) and prints the corresponding grades (A-F).  The mark-to-grade conversion table is as
follows:

Grade A B C D F
Range ≥80 65-79 50-64 40-49 <40
1. Modify the program to allow user-specified grade boundaries.  You may need to define
more variables.
2. Modify the program so that it checks if the input is between 0 and 100.  If not, it should
ask the user to input again until the input is in the correct range.  Use while statements.
3. Modify the program so that it repeats the above computation on 50 students.  Use while
statements.

10) Write down an algorithm which will perform following functionality

Read an integer array

Display above array

Find out sum of all elements of an array

Find out mean of an array

Find out standard deviation of an array

Find out probability of occurrence of every element in an array

Draw histogram

extra needed mean only

11) Write down an algorithm to

Read and display Float array

Reverse an array

Check whether array is a palindrome


Sort an array

Search an element in an array

Find out how many times a given element is appearing in an array

12) Write an algorithm to perform following operations on an array :-

Insert element at nth position in an array. Please note it should insert and not overwrite.

Delete an element at a given position

Display an array. Take care of proper validations.

13) A “password” file contains username and password. Write an algorithm to accept the
username and password and crosscheck it with the password file and display appropriate
message.

14) Write down an algorithm to simulate a stack.

It should allow following operations on stack :-

Pushing an element onto stack

Popping an element on stack

Display TOS

Check whether stack is full or empty. Let the stack be a stack of Characters.

15) Write down an algorithm to simulate a Queue. It should allow following operations on
Queue.

Adding an element into queue at the end

Deleting an element on queue from front

Display Contents of queue 4) Check whether queue is full or empty. Let the Queue be a Queue
of Employee where Employee is user defined data type.

[11:58 PM] Soumya S Patil (Guest)

16) Write down an algorithm to read a set of sentence from user till user enters a sentence
QUIT.

Find out following statistical data such as number of characters, words and sentences.
17) In above algorithm only perform following modification. Reverse ordering of sentences as
well as reverse ordering of character within a sentence.

18) Write an algorithm to perform an encryption as well as decryption of a file. Use any
algorithm to perform above said activity. Simplest possible algorithm is to read every character,
add 128 to it and stores it while performing an encryption and do reverse step while performing
a decryption.

19) Write down an algorithm to:-

Display contents of a file

Copy a file to another file

Compare two files

20) Write down an algorithm to merge two sorted STRING arrays to create third sorted STRING
array.

[Yesterday 11:59 PM] Soumya S Patil (Guest)

21) Write down an algorithm to accept string consisting of anything between ‘o’ to ‘9’ and
convert it into corresponding integer. Don’t assume any inbuilt function. 

22) Write an algorithm to perform any five operations on string such as :-

String Length

Changing case

Reversing a string

Checking for palindrome etc.


[Yesterday 11:59 PM] Soumya S Patil (Guest)

23) A file contains AAAAABBCCCDD. Write an algorithm to read such file and find out run
length of every character in above file. For example, in above case A is appearing 5 times, B 2
times and so on. So the output should look like as follows:

                                    A5B2C3D2

Also write down another program which will read above output and come out with original data
such as AAAAABBCCCDD. By the way this is very preliminary algorithm used in compression
and is known as RunLength Coding.

1.
1. 24) Task
You are to write an algorithm for a telephone company (Company A) to generate the phone bills
for its customers. The input to the program is a sequence of call records, one for each
customer.  Each call record consists of a customer ID, followed by the start and end time of
each call made by that customer during the last month. The program should calculate the
charge on each call and then sum up the total for each customer.
To attract more customers, the company has promised to offer the cheapest rate compared with
2 other rival companies, B and C.  That is, for each call, it will calculate the charges for all 3
companies and take the cheapest one.  The rates for the 3 companies are shown in the
following table:
Company A $0.80/min  
Company B $1.00/min during 9:00 – 21:00 $0.60/min during 21:00 – 9:00
Company C $0.90/min for the first hour $0.70/min for the rest

1.
1.
1. Your program should
2. Input the number of customers (at most 99999).
3. For each customer, input his/her call record consisting of:

a. The customer ID (an integer between 10000 and 99999).


b. For each call made by the customer, the start time and end time of the call. (We
assume that no calls have duration more than 23 hrs 59 mins.)
c. After the last call, there is a special time value (-1:-1) to signify the end of the list
of calls.
4. For each customer, output his/her billing information consisting of:
a. The customer ID.
b. For each call, the start time, duration (in minutes) and the charge (in dollars).
c. The total duration (in minutes) and total charge (in dollars) for that customer. 
(We assume that the total duration is at most 99999.)
5. There should be one blank line after the billing information of each customer.

* You cannot use array and self-defined function for this assignment.
1. Output Format
2. Time: Each time value is represented in the format hh:mm where hh is an integer
between 0 and 23, and mm is an integer between 0 and 59.
3. Call Duration: It should be printed in a field of width 7, right-justified.
4. Money: Each monetary value should be printed with a ‘$’ sign followed by a decimal
value in fixed-point notation with 2 decimal places.  The decimal value should occupy a
field of width 7, right-justified.

Sample Input/Output

Observe carefully the special cases as well as the spacing/format of the input/output.

You might also like