Uploaded by amina tahir

CP CODING

advertisement
NAME: AMINA TAHIR
SECTION: T
REG NO.: L1S20BSSE0041
SERIAL NO.: 29
CP Coding
1. The common algorithm for calculating the roots of a quadratic equation by the quadratic formula
requires considering several special cases in your code. Write appropriate comments for this algorithm
so that the comments make it easy to see the different cases and how they are handled. Write
accompanying external documentation to explain this algorithm.
Algorithm: RootsQuadEquation(a, b, c)
Input: The values of coefficients a, b, c are entered by user.
Output: The roots of equation R1 and R2 are displayed.
Input the values of a, b and c;
d <- sqrt(b2-4ac)
The value of discriminant d is calculated by square root of b2-4ac. This value is used to calculate
both of the roots.
R1 <- (-b+b2-4ac)/2a;
R2 <- (-b-b2-4ac)/2a;
Display the value of R1 and R2.
Documentation: The documentation of algorithm includes only mentioning the workflow of the
algorithm to calculate the roots of quadratic equation. The values of coefficients a, b, c are
entered by user. The value of discriminant d is calculated by square root of b2-4ac. This value is
used to calculate both of the roots.
2. If one person has written a component but others have revised it, who is responsible if the
component fails? What are the legal and ethical implications of reusing someone else's
component?
If the component fails then only the developer is responsible to make that component or system
execute successfully.
Some ethical and legal implications of consumer reuse must satisfy the following points:
Does the function give the required data to user? or what level of modification is required in
developing the component? or was the component well documented? or is the record of
component’s previous test is available?
Some other conditions to be satisfied by the producer reuse are given as below:
Component should be general with all its parameter and conditions. Components should be
categorized according to the requirement. Interface of the component should be general.
Algorithms and data structures should be well documented. Error handling and communications
sections should be separate.
Download