Вы находитесь на странице: 1из 8

Collage of Engineering (COE) EEEB114: Programming For Engineers

LAB 2: Problem Solving


Student Name: Student ID: Section:

2.1) LEARNING OBJECTIVES


By the end of this lab session, you should be able to:
To learn basic problem solving method.

2.2) PRE LAB ASSIGNMENT


Read 2.3

2.3) BACKGROUND
Engineers and scientists are problem solvers!
According to Arvid Eide et al. in Engineering Fundamentals and Problem Solving, as part of the
problem solving activity, engineers and scientist will have to follow these problem analysis
steps:
1. Recognize and understand the problem,
2. Accumulate facts,
3. Select the appropriate theory or principle,
4. Make necessary assumptions,
5. Solve the problem,
6. Verify and check results.

In designing software or programming in general:


1. Problem Requirements,
2. Analysis,

Page 1 of 8
Prepared By Aiman Bin Ismail May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

3. Design,
4. Implementation,
5. Verification and Testing.
Note: Failure is part of the process, so just chill!

Case study: Finding the area and circumference of a circle

Step 1: Problem Requirements


In order to solve the problem, we first have to understand the problem we want to solve
(obviously). So READ the problem statements carefully!
In this case study, the requirement is to find the area of a circle and its circumference.

Step 2: Analysis
In this step, we are going to determine what are the inputs, outputs and appropriate theories
related to our problem.
Input(s): Ask yourself, if you are required to solve the problem by your boss for example, what
information do you need? Clearly in this case, we need to request the radius of the circle from
the boss.
Output(s): Based on the problem, we are required to calculate the area and the circumference
of a circle. Hence, these are the only outputs we are going to deliver. Nothing less, nothing
more
Relevent Theories: Based on our knowledge of geometry, to calculate a circles area, the
formula is Area = r2 while the formula to calculate its circumference is given as
Circumference = 2r. From these equations, we need to have the value of the constant (PI),
which is equal to 3.14159

Page 2 of 8
Prepared By Aiman Bin Ismail May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

Data requirements
Problem Constant:
PI 3.14159
Problem Input:
Radius /* radius of a circle */
Problem Outputs:
Area /* area of a circle */
Circumference /* circumference of a circle */
Relevant Formulas:
Area of circle = r2
Circumference of circle = 2r

Step 3: Design
Next is to list the steps needed to solve the problem. The initial algorithm as follows:
Get circle radius value
Calculate area
Calculate circumference
Display the area and circumference values

Although this example is quite straight forward, it is helpful to refine some of the steps in the
initial algorithm above. Step 1 (getting data) and Step 4 (display outputs) are basic steps; hence
do not require further refinement. Steps 2 and 3 however can be refined to add some detail to
show explicitly the formula (or detail steps) to be used.

Step 2 refinement:
2.1 Area is PI radius radius (Area= r2).
Step 3 refinement:
3.1 Assign the product of two times PI and radius to circumference.

Page 3 of 8
Prepared By Aiman Bin Ismail May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

Hence, our completed algorithm after refinement is as follows:


1. Get circle radius value,
2. Calculate area,
2.1 Area is PI radius radius (Area= r2).
3. Calculate circumference,
3.1 Circumference is 2 PI radius (circumference= 2r).
4. Display the area and circumference values.

Step 4: Implementation
Note: Dont worry about this yet
/*
* Calculates and displays the area and circumference of a circle
*/

#include <stdio.h>
#define PI 3.14159

int
main()
{
double radius, /* input radius of circle*/
area, /* output radius of circle*/
circum; /* output radius of circle*/

/*Ask user to enter the radius of circle*/


printf("\nEnter radius of circle: ");
/*Storing the user input into variable radius*/
scanf("%lf",&radius);

/*Calculate Area and Circumference*/


area = PI * radius * radius;
circum = 2 * PI * radius;

/*Display Area and Circumference*/


printf("\nArea of circle is: %f",area);
printf("\nCircumference of circle is: %f",circum);

return(0);
}

Page 4 of 8
Prepared By Aiman Bin Ismail May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

Output:

2.4) IN LAB ACTIVITIES

Activity A: The Boss Circuit Problem


You are required by your employer to write a program to find the voltage (V) of the circuit
shown in Figure 2.1 if the load (RL) and current (I) are varied.
Follow the problem solving steps discussed earlier to solve the problem.

Figure 2.1 The Boss Circuit

Step 1: Problem Requirements

Page 5 of 8
Prepared By Aiman Bin Ismail May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

Step 2: Analysis

Data requirements
Problem Constant:

Problem Input:

Problem Outputs:

Relevant Formulas:

Step 3: Design

Page 6 of 8
Prepared By Aiman Bin Ismail May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

Activity B: Total Equivalent Resistance


Using the problem solving method, design a solution to find the equivalent resistance (Req) of
the circuit shown in Figure 2.2.

Figure 2.2 Equivalent Resistance Circuit

Page 7 of 8
Prepared By Aiman Bin Ismail May 2015
Collage of Engineering (COE) EEEB114: Programming For Engineers

2.5) STATE YOUR LEARNING CURVE

Page 8 of 8
Prepared By Aiman Bin Ismail May 2015