0% found this document useful (0 votes)
3 views24 pages

Assignment Computer Programmingfinal

The document provides detailed instructions for assignment submission, emphasizing adherence to deadlines, proper formatting, and originality of work. It includes specific steps for submitting assignments, whether in soft or handwritten form, and highlights the importance of academic integrity. Additionally, it presents various programming questions related to type conversion, arithmetic operations, and data processing scenarios.

Uploaded by

yugbabbar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views24 pages

Assignment Computer Programmingfinal

The document provides detailed instructions for assignment submission, emphasizing adherence to deadlines, proper formatting, and originality of work. It includes specific steps for submitting assignments, whether in soft or handwritten form, and highlights the importance of academic integrity. Additionally, it presents various programming questions related to type conversion, arithmetic operations, and data processing scenarios.

Uploaded by

yugbabbar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Instructions for Assignment Submission:

Submission Guidelines
1) Adhere to Deadlines: Submit your assignments on or before the due
date provided by your subject faculty. Late submissions may result in a
penalty or may not be accepted.
2) Mode of Submission: Follow the submission mode specified by your
subject faculty. If the faculty requests a soft copy, submit the source
code. If handwritten submission is required, follow the instructions
accordingly.
3) Proper Formatting: Ensure your solutions are properly indented.
Statements within a block or scope should be indented with one tab.
4) Identification: Include your name, university roll number, program
details, and section on your submission.
5) Original Work: Ensure that all work submitted is your own. Plagiarism
or copying will result in severe academic penalties.

Steps for Submission


1) Read Assignment Details Carefully: Understand the problem
statement and requirements before starting your work. Ask your
instructor if you need any clarifications.
2) Format of Submission: For soft copy submissions, compile your
source code files (.c files) and other necessary documents into a single
compressed (zip) file.
- Name your zip file according to the format:
RollNumber_AssignmentNumber.zip (e.g.,
2415000012_Assignment1.zip).
3) Handwritten Submissions: Ensure your handwritten assignments are
neat and legible.

- Include your name, university roll number, program details, and


section on the top of each page.
4) Verification: Double-check that you have included all required
components in your submission.

- Verify that your code compiles and runs correctly if a soft copy is
submitted.
Academic Integrity
1) Originality: Submit work that is entirely your own. Plagiarism or
copying will result in severe academic consequences.
2) Collaboration: While discussing ideas with classmates is encouraged,
direct sharing of code or solutions is prohibited.

By following these instructions, you will ensure that your assignments


meet the required standards and are submitted correctly. Best of luck
with your assignments, and happy learning!

(Type Conversion)
Question 1: Type Promotion in Expression
In the city of Computerville, a group of engineers is working on a project
to enhance their computing systems. They are trying to evaluate
complex arithmetic expressions where some variables are integers and
others are floating-point numbers. To ensure accuracy, they need to
promote integers to floats before performing operations.
One such task involves calculating the total energy consumption, where
the power in kilowatts (an integer) is multiplied by the time in hours (a
float). Engineers must ensure the integer value of power is promoted
to a float before the multiplication.
Sample Input 1:
- Power: 50 (kW)
- Time: 3.5 (hours)
Sample Output 1:
- Total Energy: 175.0 (kWh)
Sample Input 2:
- Power: 120 (kW)
- Time: 2.2 (hours)
Sample Output 2: Page 3 of 14

- Total Energy: 264.0 (kWh)


Sample Input 3:
- Power: 75 (kW)
- Time: 1.8 (hours)
Sample Output 3:
- Total Energy: 135.0 (kWh)
Question 2: Type Conversion by Assignment
In the village of Agricola, farmers need to convert their crop yield
measurements from floating-point precision to integer values for
reporting purposes. They have highly accurate sensors that give yields
in float, but for official records, they only use the integer part of the
yield.
One farmer, John, harvested his wheat and recorded a yield of 45.75
bushels. He must convert this to an integer value for the report.
Sample Input 1:
- Yield 1: 45.75
- Yield 2: 60.4
Sample Output 1:
- Converted Yield 1: 45
- Converted Yield 2: 60
Sample Input 2: Page 4 of 14

- Yield 1: 32.9
- Yield 2: 58.6
Sample Output 2:
- Converted Yield 1: 32
- Converted Yield 2: 58
Sample Input 3:
- Yield 1: 27.8
- Yield 2: 44.9
Sample Output 3:
- Converted Yield 1: 27
- Converted Yield 2: 44
Question 3: Truncation in Measurements
In the town of Architecton, architects use precise floating-point
measurements to design buildings. However, when constructing, they
often need to use integer measurements. For instance, if an architect
plans a room with a length of 12.8 meters and a width of 7.3 meters,
they need to use the integer part of these measurements to order
materials.
Sample Input 1:
- Length: 12.8
- Width: 7.3 Page 5 of 14

Sample Output 1:
- Integer Length: 12
- Integer Width: 7
Sample Input 2:
- Length: 15.6
- Width: 8.9
Sample Output 2:
- Integer Length: 15
- Integer Width: 8
Sample Input 3:
- Length: 9.4
- Width: 6.1
Sample Output 3:
- Integer Length: 9
- Integer Width: 6
Question 4: Casting Arithmetic Expression
In the industrial city of Manufac, machines perform various arithmetic
operations where precision is critical. Sometimes, integer values need
to be cast to floats to maintain accuracy in calculations. For example,
calculating the total weight of items, where the number of items is an
integer and the weight per item is a float, requires casting the integer
to a float before multiplication. Page 6 of 14

Sample Input 1:
- Number of Items: 20
- Weight per Item: 1.5
Sample Output 1:
- Total Weight: 30.0
Sample Input 2:
- Number of Items: 15
- Weight per Item: 2.4
Sample Output 2:
- Total Weight: 36.0
Sample Input 3:
- Number of Items: 8
- Weight per Item: 3.3
Sample Output 3:
- Total Weight: 26.4

Question 5
Scenario:
In a research laboratory, scientists need to keep track of multiple
experiments conducted daily. Each experiment's duration is recorded
in minutes. The lab assistant must use a `for` loop to calculate the total
time spent on experiments for each day of the week. Each day's data is
collected separately, and the assistant needs to compute the total time
for the week and determine if any day exceeded the 8-hour mark.
The assistant should:
- Use a `for` loop to process daily experiment durations.
- Calculate the total time spent on experiments for each day.
- Determine if the total time for any day exceeds 480 minutes (8 hours).
Sample Input 1:
- Day 1 Durations: 50 60 30 45 70
- Day 2 Durations: 40 55 45 50 60
- Day 3 Durations: 55 65 50 60 45
- Day 4 Durations: 50 60 70 80 90
- Day 5 Durations: 35 40 45 50 55
- Day 6 Durations: 60 70 80 90 100
- Day 7 Durations: 40 50 60 70 80

Sample Output 1:
- Day 1 Total Time: 255 minutes
- Day 2 Total Time: 250 minutes
- Day 3 Total Time: 275 minutes
- Day 4 Total Time: 350 minutes (Exceeded 8 hours)
- Day 5 Total Time: 225 minutes
- Day 6 Total Time: 400 minutes (Exceeded 8 hours)
- Day 7 Total Time: 300 minutes
Sample Input 2:
- Day 1 Durations: 60 45 30 50 55
- Day 2 Durations: 50 40 30 45 60
- Day 3 Durations: 70 60 40 50 65
- Day 4 Durations: 55 75 60 80 90
- Day 5 Durations: 45 55 65 70 80
- Day 6 Durations: 40 55 60 65 70
- Day 7 Durations: 50 60 70 80 90
Sample Output 2:
- Day 1 Total Time: 240 minutes
- Day 2 Total Time: 225 minutes
- Day 3 Total Time: 285 minutes

- Day 4 Total Time: 300 minutes (Exceeded 8 hours)


- Day 5 Total Time: 250 minutes
- Day 6 Total Time: 290 minutes
- Day 7 Total Time: 250 minutes (Exceeded 8 hours)
Sample Input 3:
- Day 1 Durations: 45 50 55 60 65
- Day 2 Durations: 40 55 60 70 80
- Day 3 Durations: 55 65 75 85 90
- Day 4 Durations: 70 80 90 100 110
- Day 5 Durations: 60 70 80 90 100
- Day 6 Durations: 75 85 95 105 115
- Day 7 Durations: 65 75 85 95 105
Sample Output 3:
- Day 1 Total Time: 275 minutes
- Day 2 Total Time: 245 minutes
- Day 3 Total Time: 370 minutes (Exceeded 8 hours)
- Day 4 Total Time: 450 minutes (Exceeded 8 hours)
- Day 5 Total Time: 300 minutes
- Day 6 Total Time: 475 minutes (Exceeded 8 hours)
- Day 7 Total Time: 425 minutes (Exceeded 8 hours)

Question 6
Scenario:
A weather monitoring system records daily temperatures over a week.
The system needs to calculate the average temperature for each day
and determine which day had the highest temperature. The user enters
temperatures for each day, and the system should use a `while` loop to
process this data.
The system should:
- Collect temperature readings for each day until all days are covered.
- Calculate the average temperature for each day.
- Determine the day with the highest average temperature.
Sample Input 1:
- Day 1 Temperatures: 22 25 21 23 24
- Day 2 Temperatures: 30 32 29 28 31
- Day 3 Temperatures: 20 22 23 21 19
- Day 4 Temperatures: 25 27 24 26 28
- Day 5 Temperatures: 18 20 22 21 19
- Day 6 Temperatures: 31 30 29 28 32
- Day 7 Temperatures: 26 27 28 25 24
Sample Output 1:
- Day 1 Average Temperature: 23
- Day 2 Average Temperature: 30
- Day 3 Average Temperature: 21 Page 6 of 20

- Day 4 Average Temperature: 26


- Day 5 Average Temperature: 20
- Day 6 Average Temperature: 30
- Day 7 Average Temperature: 26
- Highest Average Temperature: Day 2 and Day 6 (30 degrees)
Sample Input 2:
- Day 1 Temperatures: 15 16 17 18 19
- Day 2 Temperatures: 20 21 22 23 24
- Day 3 Temperatures: 10 11 12 13 14
- Day 4 Temperatures: 25 26 27 28 29
- Day 5 Temperatures: 30 31 32 33 34
- Day 6 Temperatures: 35 36 37 38 39
- Day 7 Temperatures: 40 41 42 43 44
Sample Output 2:
- Day 1 Average Temperature: 17
- Day 2 Average Temperature: 22
- Day 3 Average Temperature: 12
- Day 4 Average Temperature: 27
- Day 5 Average Temperature: 32
- Day 6 Average Temperature: 37
- Day 7 Average Temperature: 42

- Highest Average Temperature: Day 7 (42 degrees)


Sample Input 3:
- Day 1 Temperatures: 22 23 24 25 26
- Day 2 Temperatures: 20 21 22 23 24
- Day 3 Temperatures: 18 19 20 21 22
- Day 4 Temperatures: 25 26 27 28 29
- Day 5 Temperatures: 30 31 32 33 34
- Day 6 Temperatures: 35 36 37 38 39
- Day 7 Temperatures: 40 41 42 43 44
Sample Output 3:
- Day 1 Average Temperature: 24
- Day 2 Average Temperature: 22
- Day 3 Average Temperature: 20
- Day 4 Average Temperature: 27
- Day 5 Average Temperature: 32
- Day 6 Average Temperature: 37
- Day 7 Average Temperature: 42
- Highest Average Temperature: Day 7 (42 degrees) Page 8 of 20

Question 7
Scenario:
A digital counter in a manufacturing plant tracks the number of items
produced each hour. The counter records the number of items
produced every hour for a shift lasting 12 hours. The plant manager
needs to determine the total number of items produced and identify
any hours where production was less than 50 items. The `do-while` loop
is used to accumulate the production count and check for low
production hours.
The system should:
- Use a `do-while` loop to input production counts for each hour.
- Accumulate the total number of items produced.
- Identify hours with production less than 50 items.
Sample Input 1:
- Hour 1: 60
- Hour 2: 55
- Hour 3: 70
- Hour 4: 45
- Hour 5: 60
- Hour 6: 65
- Hour 7: 50
- Hour 8: 40
- Hour 9: 55
- Hour 10: 60
- Hour 11: 75

- Hour 12: 80
Sample Output 1:
- Total Items Produced: 695
- Low Production Hours: 4, 8
Sample Input 2:
- Hour 1: 30
- Hour 2: 40
- Hour 3: 50
- Hour 4: 60
- Hour 5: 70
- Hour 6: 80
- Hour 7: 90
- Hour 8: 100
- Hour 9: 110
- Hour 10: 120
- Hour 11: 130
- Hour 12: 140
Sample Output 2:
- Total Items Produced: 980
- Low Production Hours: 1, 2

Sample Input 3:
- Hour 1: 55
- Hour 2: 65
- Hour 3: 75
- Hour 4: 85
- Hour 5: 95
- Hour 6: 105
- Hour 7: 115
- Hour 8: 125
- Hour 9: 135
- Hour 10: 145
- Hour 11: 155
- Hour 12: 165
Sample Output 3:
- Total Items Produced: 1,485
- Low Production Hours: None
Question 8: If-Else Ladder in Tax Calculation
Scenario:
GlobalFinance, a leading financial advisory firm, provides tax
consultation services to individuals and businesses. The tax rates for
individuals are based on their annual income. The tax brackets are as
follows: if the income is up to 25000 units, the tax rate is 10%. If the
income is between 25001 and 50000 units, the tax rate is 20%. If the
income is between 50001 and 100000 units, the tax rate is 30%. If the
income is above 100000 units, the tax rate is 40%.
Emily, a tax advisor at GlobalFinance, needs to calculate the tax for
clients based on their annual income using an if-else ladder. This
calculation is crucial for providing accurate tax advice and helping
clients plan their finances effectively.
Accurate tax calculations are essential for compliance with tax laws and
maximizing clients' financial well-being. Emily's work will help clients
manage their taxes efficiently and avoid any legal issues.
Sample Input 1:
Annual Income: 20000 units

Sample Output 1:
Tax: 2000 units

Sample Input 2:
Annual Income: 40000 units

Sample Output 2:
Tax: 8000 units

Sample Input 3:
Annual Income: 120000 units
Sample Output 3:
Tax: 48000 units

Question 9: Decision Making Using Switch in Restaurant Menu


Scenario:
GourmetBite, a popular restaurant, offers a variety of dishes to its
customers. The restaurant uses a code-based system to identify dishes
and their prices. The menu includes the following items: 'B' for Burger
at 150 units, 'P' for Pizza at 200 units, 'S' for Salad at 100 units, 'D' for
Dessert at 80 units, and 'C' for Coffee at 50 units.
Rachel, a cashier at GourmetBite, needs to determine the price of a
dish based on its code using a switch statement. This system helps in
quickly identifying the price and processing orders efficiently.
Accurate price determination is crucial for maintaining customer
satisfaction and ensuring smooth operations at the restaurant. Rachel's
work will help provide prompt service to customers and enhance their
dining experience.
Sample Input 1:
Dish Code: B

Sample Output 1:
Price: 150 units

Sample Input 2:
Dish Code: P
Sample Output 2:
Price: 200 units

Sample Input 3:
Dish Code: D

Sample Output 3:
Price: 80 units

Question 10: -If-Else Ladder in Utility Bill Calculation


Calculate the total electricity bill for customers based on their type and
consumption.
Input:
- customer_type (integer): 1 (Residential), 2 (Commercial), 3
(Industrial)
- units_consumed (integer): units consumed in kWh
Rates:
- Residential (1): 5 units/kWh
- Commercial (2): 8 units/kWh
- Industrial (3): 10 units/kWh
Sample Inputs and Outputs:

| Input | | Output |
| customer_type = 1, units_consumed = 100 | total_bill = 500 |
| customer_type = 2, units_consumed = 500 | total_bill = 4000 |
| customer_type = 3, units_consumed = 1000 | total_bill = 10000 |
Task:
Write a program to calculate the total bill using an if-else ladder or
switch statement.
Constraints:
- customer_type will always be 1, 2, or 3.
- units_consumed will always be a non-negative integer.
Evaluation Criteria:
- Accuracy of bill calculation
- Correct usage of if-else ladder or switch statement
- Code readability and maintainability

Question 11: Binary Converter


Story: Tom is a computer science student who needs to convert decimal
numbers to binary for his programming project. He wants to write a
program that takes a decimal number as input and outputs its binary
representation.
Task: Write a C program to convert a given decimal number to its binary
representation.
Explanation:
- Read a decimal number from the user.
- Convert the decimal number to binary using iterative division by 2.
- Print the binary representation
Sample Input1
12
Sample Output1
1100
Sample Input2
25
Sample Output2
11001
Sample Input3
7
Sample Output3
111
Sample Input4
0
Sample Output4
0
Question 12: Leap Year Finder
Story: Rachel is a historian researching leap years for her thesis. She
wants to write a program that finds all leap years within a given range
of years.
Task: Write a C program to find all leap years within a given range of
years.
Explanation:
- Read the start and end years from the user.
- Iterate through each year in the range.
- Check if the year is a leap year (divisible by 4, but not by 100, unless
also divisible by 400).
- Print the leap years.
Sample Inputs and Outputs:
Sample Input1
2000-2020
Sample Ouput1
2000, 2004, 2008, 2012, 2016, 2020
Sample Input2
1900-1999
Sample Ouput2
1904, 1908, 1912, 1916, 1920, ...
Sample Input3
1800-1899
Sample Ouput3
1804, 1808, 1812, 1816, 1820, ...
Question 13: Positive Number Sum

Story: Alex is a data analyst who needs to calculate the sum of positive
numbers from a list of numbers. He wants to write a program that reads
numbers until -1 is encountered and outputs the sum of positive
numbers.
Task: Write a C program using a do-while loop to read numbers (positive
and negative) until -1 is encountered. Also, find the sum of only positive
numbers.
Explanation:
- Initialize a sum variable to 0.
- Read numbers from the user using a do-while loop until -1 is
encountered.
- Check if each number is positive; if so, add it to the sum.
- Print the sum of positive numbers.
Sample Inputs and Outputs:
Sample Input1
5, 2, -3, 4, -1
Sample Ouput1
11
Sample Input2
10, -5, 3, 2, -1
Sample Ouput2
15
Sample Input3
-2, -4, 1, -1
Sample Ouput3
1
Sample Input4
0, 0, -1
Sample Ouput4
0
Question 14: Vowel or Consonant Checker

Story: Emily is an English teacher who wants to write a program to


check whether a given character is a vowel or consonant.
Task: Write a C program to check whether an input character is a vowel
or consonant for both uppercase and lowercase alphabets.
Explanation:
- Read a character from the user.
- Check if the character is a vowel (a, e, i, o, u, A, E, I, O, U).
- If vowel, print "Vowel"; otherwise, check if the character is a
consonant (alphabet letter).
- If consonant, print "Consonant"; otherwise, print "Invalid input".
Sample Inputs and Outputs:
Sample Input1
e
Sample Output1
Vowel
Sample Input2
b
Sample Output2
Consonant
Sample Input3
A
Sample Output3
Vowel
Sample Input4
1
Sample Output4
Invalid input
Sample Input5
!
Sample Output5
Invalid input

You might also like