You are on page 1of 2

Exercise 2

Translating a Sequential Flowchart to C++ Code

Introduction:
The flowchart is a plan of your program but it must be formalized into C++ instructions. C++ is
not only the most widely used programming language but also gives you a good foundation to current
programming methods. So, practicing proper coding principles must be observed accordingly for this
would facilitate reading, writing and maintaining your code. For instance in the industry, the
maintenance cost is higher compared to the initial cost of software development [1]. These practices
includes but not limited to meaningful comments, clear and concise description to identifiers, and proper
code formatting. The three step principle below will greatly improve the structure of your program [2]
One statement per line
One line for the opening brace and one line for the closing brace
All statements under a brace must be indented
The sine law formula is an equation involving the lengths and the sides of an oblique triangle. The
equation are as follows:

= =
sin sin sin
Where a, b, c are sides and A, B, C angles opposite to the side. Refer to the figure below.

Figure 1: An oblique triangle with labels of sides and angles

The sine law is applicable if two side and an opposite angle is given and any two angles and one
opposite side is given [3].

Objectives: Implement a source code out of the flowchart for the given sine law related problem
Apply the disciplined formatting of a program for ease of code readability

Materials: Pen and paper

Procedure:
1. Create a flowchart to solve the rest of the unknown if sides a, and b, and angle B are the
given of your triangle. Note that the sum of A, B, C is 180 degrees.
2. The flowchart must include inputting of side a, b, and angle B then and the outputs are
the rest of the unknown. Since there is only one flowchart symbol for input and output,
place an appropriate label when using this symbol.
3. Systematically break down the derived equation so that one symbol of process,
input/output or preparation is equivalent to one statement of C++ code. Note: the in
<cmath> library the function sin(radians_argument)assumes radians as argument
while asin(argument) returns result in radians. So, to convert it to degrees multiply the
result by 57.2956, or divide the degrees by 57.2956 to convert it to radians.
4. When writing your code, observe the proper formatting rules.
References

[1] R. C. Martin, Clean Code, Boston, MA: Pearson Education, Inc., 2009 .

[2] D. Malik, C++ Programming: From Problem Analysis to Program Design, Course Technology, Cengage
Learning, 2011.

[3] R. Larson and R. Hostetler, Trigonometry, 7th ed., Houghton Mifflin Company, 2007.

You might also like