ECH 3854 – Homework Set #1

Florida State University
Jose Mariano da Silva Neto























ECH 3854 – Homework Set #1
FAMU-FSU College of Engineering
Fall 2014 Due Date: 09/03/14

1. You are developing a program for a credit card authorization machine so that it can accept credit
cards and obtain approval for transactions. It can read cards issued by major credit card
companies. You are currently interested in contacting the appropriate credit card company and
providing the card number read. Applying the first two steps of the problem solving
methodology covered in class, design all the operations that you think are reasonable for such a
problem.

SOLUTION:

For this problem, it was required to use the methodology covered in class. It is necessary to
follow some steps:

1
st
Step – Problem Statement and Input/Output Analysis

a) Problem statement: To create a program that can be used to obtain approval for
transactions in a credit card machine.
b) Input/Output Analysis:

The input is the credit_card_authorization and it includes:

i) credit_card_company
ii) number_of_card
iii) expiration_date
iv) CVS_number

The output includes:

i) answer_for_the_authorization

2
nd
Step – Decomposition

i) Enter with the following data:

First: Credit_card_company:
It is valid?
If yes, proceed to the next step;
Otherwise, print the message: This card is not valid.
End the program

Second: number_of_card
It is valid?
If yes, proceed to the next step;
Otherwise, print the message: The number of this card is not valid.
End the program

Third: expiration_date
It is valid?
If yes, proceed to the next step;
Otherwise, print the message: This card does not have a valid date.
End the program

Fourth: CVS_number
It is valid?
If yes, proceed to the next step;
Otherwise, print the message: This card does not have a valid CVS number.
End the program

ii) Available balance

The available balance is equal or higher than the purchase amount?
If yes, print the answer: answer_for_the_authorization: Accept with success
Otherwise, print the answer: answer_for_the_authorization: Sorry, you do not have
an available balance for this transaction.


2. Given a quadratic equation of the form:

You are required to design and write a program to solve for the roots of any quadratic equation
of the form given above, regardless of type. Following the top-down design approach outlined in
class, (a) State the problem (b) Define the inputs and outputs (c) design and then decompose the
problem into subtasks (d) refine the subtasks into smaller more detailed pieces
SOLUTION:
1
st
Step – Problem Statement and Input/Output Analysis

a) Problem statement: To find the roots of any quadratic equation of the form:

b) Define the inputs and outputs

The input is the credit_card_authorization and it includes:

i) a_value
ii) b_value
iii) c_value

The outputs include:

i) x1_root1
ii) x2_root2
c) Design and then decompose the problem into subtasks

i) Enter with the following data:

 a_value
 b_value
 c_value

ii) To calculate the delta_value
iii) If delta_value is valid, to calculate the roots for the quadratic equation
iv) To print the x1_root1 and x2_root2


d) Refine the subtasks into smaller more detailed pieces


i) To write the equation in the form:

ii) In the program, enter with the a, b and c values:
 a_value
 b_value
 c_value
iii) To calculate the delta_value:

delta_value = b*b-4*a*c

if delta_value is equal to 0, this equation has a solution and it is unique,
x1=x2
if delta_value is greater than 0, this equation has solution and it has two
roots, x1_ root1 and x2_root2
otherwise, this equation does not have a real solution.

iv) To calculate x1_ root1 and x2_root2:

x1_root1=(-b+sqrt(delta_value))/(2*a);
x2_root2 = (-b-sqrt(delta_value))/(2*a);

v) To print the results:

 x1_ root1
 x2_root2