Description
Problem Solving and Program Design Using C
(CSE 3942)
Department of Computer Science & Information Technology
Faculty of Engineering & Technology (ITER)
Bhubaneswar, Odisha – 751030
Lab Assignment-1
1. Programming Projects on Overview of C
1.1 Write a program that calculates mileage reimbursement for a salesperson at a rate of $.35 per mile. Your program should interact with the user in this manner:
MILEAGE REIMBURSEMENT CALCULATOR
Enter beginning odometer reading=> 13505.2
Enter ending odometer reading=> 13810.6 You traveled 305.4 miles. At $0.35 per mile, your reimbursement is $106.89.
1.2 Write a program to assist in the design of a hydroelectric dam. Prompt the user for the height of the dam and for the number of cubic meters of water that are projected to flow from the top to the bottom of the dam each second. Predict how many megawatts (1MW = 106W) of power will be produced if 90% of the work done on the water by gravity is converted to electrical energy. Note that the mass of one cubic meter of water is 1000 kg. Use 9.80 meters/second2 as the gravitational constant g . Be sure to use meaningful names for both the gravitational constant and the 90% efficiency constant. For one run, use a height of 170 m and flow of 1.30 × 103 m3/s. The relevant formula ( w = work, m = mass, g = gravity, h = height) is: w = mgh.
1.3 Write a program that estimates the temperature in a freezer (in °C) given the elapsed time (hours) since a power failure. Assume this temperature ( T ) is given by
where t is the time since the power failure. Your program should prompt the user to enter how long it has been since the start of the power failure in whole hours and minutes. Note that you will need to convert the elapsed time into hours. For example, if the user entered 2 30 (2 hours 30 minutes), you would need to convert this to 2.5 hours.
1.4 Write a program to convert a temperature in degrees Fahrenheit to degrees Celsius.
DATA REQUIREMENTS Problem Input
int fahrenheit /* temperature in degrees Fahrenheit */ Problem Output
double celsius /* temperature in degrees Celsius */ Relevant Formula celsius = 5/9 ( fahrenheit – 32)
1.5 Hospitals use programmable pumps to deliver medications and fluids to intravenous lines at a set number of milliliters per hour. Write a program to output information for the labels the hospital pharmacy places on bags of I.V. medications indicating the volume of medication to be infused and the rate at which the pump should be set. The program should prompt the user to enter the quantity of fluid in the bag and the number of minutes over which it should be infused. Output the VTBI (volume to be infused) in ml and the infusion rate in ml/hr.
Sample run:
Volume to be infused (ml) => 100
Minutes over which to infuse => 20
VTBI: 100 ml
Rate: 300 ml/hr
1.6 Write a program that predicts the score needed on a final exam to achieve a desired grade in a course. The program should interact with the user as follows:
Enter desired grade> B
Enter minimum average required> 79.5
Enter current average in course> 74.6 Enter how much the final counts as a percentage of the course grade> 25
You need a score of 94.20 on the final to get a B.
In the example shown, the final counts 25 percent of the course grade.
1.7 Write a program that calculates how many BTUs of heat are delivered to a house given the number of gallons of oil burned and the efficiency of the house’s oil furnace. Assume that a barrel of oil (42 gallons) has an energy equivalent of 5,800,000 BTU. ( Note: This number is too large to represent as an int on some personal computers.) For one test use an efficiency of 65 percent and 100 gallons of oil.
1.8 Metro City Planners proposes that a community conserve its water supply by replacing all the community’s toilets with low-flush models that use only 2 liters per flush. Assume that there is about 1 toilet for every 3 persons, that existing toilets use an average of 15 liters per flush, that a toilet is flushed on average 14 times per day, and that the cost to install each new toilet is $150. Write a program that would estimate the magnitude (liters/day) and cost of the water saved based on the community’s population.
1.9 Write a program that takes the length and width of a rectangular yard and the length and width of a rectangular house situated in the yard. Your program should compute the time required to cut the grass at the rate of two square feet a second.
1.10 Write a program that outputs the equation of the perpendicular bisector of the line segment between two points. Your program should
• prompt for and input the coordinates of the two points [for example, try the points (2.0, -4.0) and (7.0, -2.0)];
• compute the slope of the line between those two points;
• compute the coordinates of the midpoint of the line segment between the two points by averaging the two x coordinates and the two y coordinates;
• compute the slope of the perpendicular bisector by taking the negative reciprocal of the slope of the line segment;
• compute the y intercept of the perpendicular bisector (you now have the slope m of the bisector and a point ( xmid , ymid ) on the bisector, so the y intercept is ymid – m xmid ); and
• output with labels the original two points, and output in y = mx + b format the equation of the perpendicular bisector. The below mentioned Figure illustrates the sample line segment mentioned above and its perpendicular bisector.
Test your program to be sure it works on different pairs of points. However, there will be some pairs of points for which you can’t make your program work (at least not at this stage). Think about what points will cause your program to fail, and write a paragraph describing which points fall in this category.
1.11 The Pythagorean theorem states that the sum of the squares of the sides of a right triangle is equal to the square of the hypotenuse. For example, if two sides of a right triangle have lengths of 3 and 4, then the hypotenuse must have a length of 5. Together the integers 3, 4, and 5 form a Pythagorean triple. There are an infinite number of such triples. Given two positive integers, m and n, where m > n, a Pythagorean triple can be generated by the following formulas:
side1 = m2− n2
side2 = 2mn hypotenuse = m2 + n2
The triple ( side1 = 3, side2 = 4, hypotenuse = 5) is generated by this formula when m = 2 and n = 1. Write a program that takes values for m and n as input and displays the values of the Pythagorean triple generated by the formulas above.
1.12 Write a program that calculates the acceleration (m/s2 ) of a jet fighter launched from an aircraft-carrier catapult, given the jet’s takeoff speed in km/hr and the distance (meters) over which the catapult accelerates the jet from rest to takeoff. Assume constant acceleration. Also calculate the time (seconds) for the fighter to be accelerated to takeoff speed. When you prompt the user, be sure to indicate the units for each input. For one run, use a takeoff speed of 278 km/hr and a distance of 94 meters. Relevant formulas ( v = velocity, a = acceleration, t = time, s = distance)
Reviews
There are no reviews yet.