You are on page 1of 11

Department of CSE &IT

MIT SCHOOL OF ENGINEERING


Dept. of First Year

SUBJECT NAME

17CS112: Programming Laboratory


Class: -F.E., Semester: - II

MIT School of Engineering, Pune 1


Department of CSE &IT

LIST OF ASSIGNMENTS
Sr. Title of Assignment
No.
GROUP A: Basics needed: printing, scanning, data types,
variables (Any one)

1 On day one of college, two students were interacting with each other. Write a program
to display the communication between them.

2 Consider user as a student and program as professor, write a program for introduction
of a student. Professor is asking following questions:
1. Welcome to First year engineering.
2. What is your name?
3. Tell me your native place.
4. You are staying in a hostel?
5. Tell me your 12th percentage.
6. Tell me your 10th percentage.

Personal Information :
3 Design a program that displays the following information:
1. Your name
2. Your address, with city, state, and ZIP
3. Your telephone number
GROUP B: Basics needed: Operators (Any one)

4 Riya wants to learn basic calculation, help her for following operations by program:
Addition of 2 numbers
1. Subtraction of 2 numbers
2. Division operation of 2 numbers
3. Multiplication of 2 numbers
4. Find the remainder
5. Calculation of percentage
5 Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of
basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate
his gross salary.
6 Distance Traveled :
Assuming there are no accidents or delays, the distance that a car travels down the
interstate can be calculated with the following formula:
Distance = Speed × Time
A car is traveling at 60 miles per hour. Design a program that displays the following:
1. The distance the car will travel in 5 hours
2. The distance the car will travel in 8 hours
3. The distance the car will travel in 12 hours
7 A father said to his son, "I was as old as you are at the present at the time of your
birth". Ask user to enter a father’s age and display the five years back age of son.
GROUP C: Basics needed: Conditions logic (Any two -assignment 12 is
compulsory)

MIT School of Engineering, Pune 2


Department of CSE &IT

8 Scientists measure an object’s mass in kilograms and its weight in Newtons. If you
know the amount of mass of an object, you can calculate its weight, in Newtons, with
the following formula:
Weight = Mass × 9.8
Design a program that asks the user to enter an object’s mass, and then calculates its
weight. If the object weighs more than 1,000 Newtons, display a message indicating
that it is too heavy. If the object weighs less than 10 Newtons, display a message
indicating that it is too light.
9 Serendipity Booksellers has a book club that awards points to its customers based on
the number of books purchased each month. The points are awarded as follows:
▪ If a customer purchases 0 books, he or she earns 0 points.
▪ If a customer purchases 1 book, he or she earns 5 points.
▪ If a customer purchases 2 books, he or she earns 15 points.
▪ If a customer purchases 3 books, he or she earns 30 points.
▪ If a customer purchases 4 or more books, he or she earns 60 points.
Design a program that asks the user to enter the number of books that he or she has
purchased this month and displays the number of points awarded.
10 Color Mixer :
The colors red, blue, and yellow are known as the primary colors because they cannot
be made by mixing other colors. When you mix two primary colors, you get a
secondary color, as shown here:
▪ When you mix red and blue, you get purple.
▪ When you mix red and yellow, you get orange.
▪ When you mix blue and yellow, you get green.
Design a program that prompts the user to enter the names of two primary colors to
mix. If the user enters anything other than “red,” “blue,” or “yellow,” the program
should display an error message. Otherwise, the program should display the name of
the secondary color that results.
11 Time Calculator :
Design a program that asks the user to enter a number of seconds, and works as
follows:
1. There are 60 seconds in a minute. If the number of seconds entered by
the user is greater than or equal to 60, the program should display the
number of minutes in that many seconds.
2. There are 3,600 seconds in an hour. If the number of seconds entered by
the user is greater than or equal to 3,600, the program should display the
number of hours in that many seconds.
3. There are 86,400 seconds in a day. If the number of seconds entered by
the user is greater than or equal to 86,400, the program should display
the number of days in that many seconds.
12 An Insurance company follows following rules to calculate premium.
1. If a person’s health is excellent and the person is between 25 and 35
years of age and lives in a city and is a male then the premium is Rs. 4
per thousand and his policy amount cannot exceed Rs. 2 lakhs.
2. If a person satisfies all the above conditions except that the sex is
female then the premium is Rs. 3 per thousand and her policy amount
cannot exceed Rs. 1 lakh.
3. If a person’s health is poor and the person is between 25 and 35 years of
age and lives in a village and is a male then the premium is Rs. 6 per
thousand and his policy cannot exceed Rs. 10,000.
4. In all other cases the person is not insured.
Write a program to output whether the person should be insured or not, his/her

MIT School of Engineering, Pune 3


Department of CSE &IT

premium rate and maximum amount for which he/she can be insured.

GROUP D: Basics needed: Repetition (Any two)


13 Calculating the Factorial of a Number
In mathematics, the notation n! represents the factorial of the non negative integer n.
The factorial of n is the product of all the non negative integers from 1 up through n.
For example:
7! = 1 × 2 × 3 × 4 × 5 × 6 × 7 = 5,040 and
4! = 1 × 2 × 3 × 4 = 24
Design a program that asks the user to enter a non negative integer and then displays
the factorial of that number.
Average Rainfall :
14 Design a program that uses nested loops to collect data and calculate the average
rainfall over a period of years. The program should first ask for the number of years.
The outer loop will iterate once for each year. The inner loop will iterate twelve
times, once for each month. Each iteration of the inner loop will ask the user for the
inches of rainfall for that month. After all iterations, the program should display the
number of months, the total inches of rainfall, and the average rainfall per month
for the entire period.
15 If a five-digit number is input through the keyboard, write a program to print a new
number by adding one to each of its digits. For example, if the number that is input is
12391 then the output should be displayed as 23402.
GROUP E: Basics needed: Array (Any one)
16 Design a program that asks the user to enter a series of 20 numbers. The program
should store the numbers and then display the following data:
1. The lowest number in the array
2. The highest number in the array
3. The total of the numbers in the array
4. The average of the numbers in the array
17 Rainfall Statistics :
Design a program that lets the user enter the total rainfall for each of 12 months. The
program should calculate and display the total rainfall for the year, the average
monthly rainfall, and the months with the highest and lowest amounts.
18 Design a program that has two parallel arrays: one for storing the names of seven of
your friends, and other for storing the friends’ phone numbers. The program should
allow the user to enter a person’s name (or part of a person’s name). It should then
search for that person in the people array. If the person is found, it should get that
person’s phone number from the phone Numbers array and display it. If the person is
not found in the people array, the program should display a message indicating so. The
program allows you to search for a person’s name in the people array. If the name is
found, it displays that person’s phone number. [optional: Modify the program so it uses
the binary search algorithm instead of the sequential search algorithm.]

GROUP F: Basics needed: Modular Programming (Any one)


19 Calories from Fat and Carbohydrates :
A nutritionist who works for a fitness club helps members by evaluating their diets. As
part of her evaluation, she asks members for the number of fat grams and carbohydrate
grams that they consumed in a day. Then, she calculates the number of calories that
result from the fat, using the following formula:
Calories from Fat = FatGrams × 9

MIT School of Engineering, Pune 4


Department of CSE &IT

Next, she calculates the number of calories that result from the carbohydrates, using
the following formula:
Calories from Carbs = CarbGrams × 4
The nutritionist asks you to design a modular program that will make these
calculations.
20 Fat Gram Calculator :
Design a program that asks for the number of fat grams and calories in a food item.
Validate the input as follows:
▪ Make sure the number of fat grams and calories are not less than 0.
▪ According to nutritional formulas, the number of calories cannot exceed
fatgrams*9. Make sure that the number of calories entered is not greater
than fatgrams*9.
Once correct data has been entered, the program should calculate and display the
percentage of calories that come from fat. Use the following formula:
Percentage of calories from fat = (Fatgrams*9) ÷ Calories
Some nutritionists classify a food as “low fat” if less than 30 percent of its calories
come from fat. If the results of this formula are less than 0.3, the program should
display a message indicating the food is low in fat.
21 Paint Job Estimator :
A painting company has determined that for every 115 square feet of wall space, one
gallon of paint and eight hours of labor will be required. The company charges $20.00
per hour for labor. Design a modular program that asks the user to enter the square
feet of wall space to be painted and the price of the paint per gallon. The program
should display the following data:
1. The number of gallons of paint required
2. The hours of labor required
3. The cost of the paint
4. The labor charges
5. The total cost of the paint job
GROUP G: Basics needed: Use Defined Data Type(Any one)
22 Write a program to store and print the roll no., name, age and marks of a student and
Display it Using Structure.
23 Enter the marks of 5 students in Chemistry, Mathematics and Physics (each out of 100)
named Marks having elements roll no., name, chem_marks, maths_marks and
phy_marks and then display the percentage of each student.
24 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.
1. Write a function to print the Account number and name of each
customer with balance below Rs. 100.
2. 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”.
25 An automobile company has serial number for engine parts starting from AA0 to FF9.
The other characteristics of parts to be specified in a structure are: Year of
manufacture, material and quantity manufactured.
1. Specify a structure to store information corresponding to a part.
2. Write a program to retrieve information on parts with serial numbers
between BB1 and CC6.

MIT School of Engineering, Pune 5


Department of CSE &IT

GROUP H: Referencing(Any one)


26 Take two numbers from the user in two variables and interchange their addresses by
means of external module. Display the result from main function.
27 Program to print a string using pointer.
GROUP I: File Handling (Any one)
28 Write a program to read a file and display contents with its line numbers.
29 Write a program to copy one file to another. Display the content of new file.
GROUP J: Miscellaneous: (For practice – no lab hours)
30 Factorial of each element in Fibonacci series
Input : limit = 20
Output : 1 1 1 2 6 120 40320 6227020800
Explanation :
Fibonacci series in this range is 0, 1, 1, 2, 3, 5, 8, 13.
Factorials of these numbers are 1, 1, 1, 2, 6, 120, 40320, …
1. Find the factorial of any given number
2. Print the Fibonacci series upto 20 numbers.
3. Print the Fibonacci series in triangular pattern.
4. Find the factorial of each element of Fibonacci series.
31 The Summerville Telephone Company charges 10 cents per minute for all calls outside
the customer’s area code that last over 20 minutes. All other calls are 13 cents per
minute. Design a flowchart or pseudocode for the following:
1. A program that accepts the following data about one phone call:
customer area code (three digits), customer phone number (seven
digits), called area code (three digits), called number (seven digits), and
call time in minutes (four digits). Display the calling number, called
number, and price for the call.
2. A program that continuously accepts data about phone calls until a
sentinel value is entered, and displays all the details only about calls
that cost over $10.
3. A program that continuously accepts data about phone calls until a
sentinel value is entered, and displays details only about calls placed
from the 212 area code to the 704 area code that last over 20 minutes.
4. A program that prompts the user for a three-digit area code from which
to select phone calls. Th en the program continuously accepts phone call
data until a sentinel value is entered, and displays data only for phone
calls placed to or from the specified area code.
GROUP K: Case Studies: (Any one -1 lab session)
32 Driver’s License Exam :
The local driver’s license office has asked you to design a program that grades the
written portion of the driver’s license exam. The exam has 20 multiple choice
questions.
Here are the correct answers:
1. B 6. A 11. B 16. C
2. D 7. B 12. C 17. C
3. A 8. A 13. D 18. B
4. A 9. C 14. A 19. D
5. C 10. D 15. D 20. A
1. Your program should store these correct answers in an array.
2. The program should ask the user to enter the student’s answers for each

MIT School of Engineering, Pune 6


Department of CSE &IT

of the 20 questions, which should be stored in another array.


3. After the student’s answers have been entered, the program should
display a message indicating whether the student passed or failed the
exam. (condition: A student must correctly answer 15 of the 20
questions to pass the exam.)
4. It should then display the total number of correctly answered questions,
5. the total number of incorrectly answered questions,
6. a list showing the question numbers of the incorrectly answered
questions.
Should store details of at least 10 students and their result
33 Overweight is having extra body weight from muscle, bone, fat, and/or water. Obesity
is having a high amount of extra body fat. Body mass index (BMI) is a useful measure
of overweight and obesity. To calculate BMI, the fitness instructor should first measure
the client’s height in metres and weight in kilogrammes. The client’s weight is then
divided by the client’s height squared.
For example, a client who is 1.8m tall and weighs 80kg:
1.8 x 1.8= 3.24, 80kg ÷ 3.24= 24.7

This result should then be cross-referenced to a BMI table.


 Below 18.5 = underweight
 Between 18.5 and 25= ideal
 Between 25 and 30 = overweight
 From 30 to 35 = category 1 obese
 From 35 to 40 = category 2 obese
 40+ = morbidly obese

1. Calculate the square of the height.


2. Calculate and display the BMI of client.
3. Show the BMI result on the screen with the name of client.
4. Calculate and display the BMI of 05 clients.
5. Find out the obese and ideal client.
34 Resistor circuits that combine series and parallel resistors networks together are
generally known as Resistor Combination or mixed resistor circuits. The method of
calculating the circuits equivalent resistance is the same as that for any individual
series or parallel circuit and hopefully we now know that resistors in series carry the
same current and that resistors in parallel have the same voltage across them.
The formula for calculating equivalent resistance of three resistors is given below:
Series: Rs = R1 + R2 + R3

Parallel: 1/Rp = 1/R1 + 1/R2 + 1/R3 i.e. Rp = (1/R1 + 1/R2 + 1/R3)−1


for example:
The values of R1, R2, and R3 (in Ohm): 3, 4 and 5
Equivalent Resistance (in series): 12 Ohm
Equivalent Resistance (in parallel): 1.2766 Ohm

1. Accept the values of Resistors from user.


2. Calculate Rs and Rp. (Assume all are non-zero numbers)
3. Accept n resistors to calculate equivalent resistance in both cases.
4. Comment on equivalent output for each set of Inputs (Is series better than

MIT School of Engineering, Pune 7


Department of CSE &IT

parallel, justify and display comment).


5. Display message if equivalent resistance is less than threshold value (hint:
set the threshold value in program).

Text Books:
1. Brian W. Kernighan, Dennis M. Ritchie, “The C Programming Language”, Prentice Hall, ISBN
0131103628, Second Edition.

2. E. Balguruswamy, “Programming in ANSI C”, Tata Mc-Graw Hill

References:
1. Joyce Farell, “Programming Logic and Design- Comprehensive”, Sixth Edition, Cengage
Learning.
2. Tony Gaddis, “Programming Logic & Design”, Third Edition, Pearson Education.
3. Herbert Schildt, “C – The Complete Reference”, Tata McGraw Hill Publishing Company,Fourth
Edition,New Delhi, 2010.

ASSIGNMENT NO.1

MIT School of Engineering, Pune 8


Department of CSE &IT

AIM: Consider user as a student and program as professor, write a program for
introduction of a student. Professor is asking following questions:
1. Welcome to First year engineering.
2. What is your name?
3. Tell me your native place.
4. You are staying in a hostel?
5. Tell me your 12th percentage.
6. Tell me your 10th percentage.

PROBLEM DEFINITION :
To understand the basic structure of a C program.

THEORY:
A C program basically consists of the following parts −
 Preprocessor Commands
 Functions
 Variables
 Statements & Expressions
The first line of the program #include <stdio.h> is a preprocessor command, which tells a C
compiler to include stdio.h file before going to actual compilation.
 The next line int main() is the main function where the program execution begins.

 The next line printf(...) is another function available in C which causes the message to be
displayed on the screen.

 The next line return 0; terminates the main() function and returns the value 0.

PROBLEM SOLUTION:
Algorithm:

FLOWCHART

FAQs

1. What do you mean by preprocessor directives?


2. Explain various Data Types.
3. What is use of Standard input output library functions?

CONCLUSION: In this assignment, we get to learn about data types, variables, input/output
directives.

ASSIGNMENT NO: 2

MIT School of Engineering, Pune 9


Department of CSE &IT

AIM: Distance Travelled


Assuming there are no accidents or delays, the distance that a car travels down the
interstate can be calculated with the following formula:
Distance = Speed × Time
A car is traveling at 60 miles per hour. Design a program that displays the following:
1. The distance the car will travel in 5 hours
2. The distance the car will travel in 8 hours
3. The distance the car will travel in 12 hours
PROBLEM DEFINITION:
To explain the working of arithmetic operators.
THEORY:
The programming languages supports various arithmetic operators for all floating-point and integer
numbers. These operators are + (addition), - (subtraction), * (multiplication), / (division), and %
(modulo). The following table summarizes the binary arithmetic operations in the Java
programming language. The binary operators falling in this category are:
Operator Use Description
+ op1 + op2 Adds op1 and op2; also used to concatenate strings
- op1 - op2 Subtracts op2 from op1
* op1 * op2 Multiplies op1 by op2
/ op1 / op2 Divides op1 by op2
% op1 % op2 Computes the remainder of dividing op1 by op2

These operations are commonly called arithmetic operations. Arithmetic is the oldest and most
elementary branch of mathematics. In this and other related lessons we will briefly explain basic
math operations.
The ones falling into the category of unary arithmetic operators are:
 Increment: The ‘++’ operator is used to increment the value of an integer. When placed
before the variable name (also called pre-increment operator), its value is incremented
instantly. For example, ++x. And when it is placed after the variable name (also called post-
increment operator), its value is preserved temporarily until the execution of this statement
and it gets updated before the execution of the next statement. For example, x++.
 Decrement: The ‘–‘ operator is used to decrement the value of an integer. When placed
before the variable name (also called pre-decrement operator), its value is decremented
instantly. For example, –x. And when it is placed after the variable name (also called post-
decrement operator), its value is preserved temporarily until the execution of this statement
and it gets updated before the execution of the next statement. For example, x–.

PROBLEM SOLUTION:
ALGORITHM:

FLOWCHART:

FREQUENTLY ASKED QUESTIONS:


1. What is operator?

MIT School of Engineering, Pune 10


Department of CSE &IT

2. What are the various types of operators?


3. Explain the working of Mod operation.

CONCLUSION: In this assignment, the concept of selection statement (For Loop) and Branching
Statement (IF/ELSEIF) is used to calculate summation and average of numbers using Mod
Operation.

MIT School of Engineering, Pune 11

You might also like