Which function is most likely to have procedural cohesion?

main()
findSquareRoot()
getSaleSubtractDiscountAddTax()
openFiles()

The correct answer is: C. getSaleSubtractDiscountAddTax()

Procedural cohesion is a measure of how well the different parts of a function work together to achieve a single, well-defined purpose. A function with high procedural cohesion has a single, well-defined task that it performs. A function with low procedural cohesion has multiple tasks that it performs, or it performs a task in a way that is not well-defined.

The function getSaleSubtractDiscountAddTax() is most likely to have procedural cohesion because it has a single, well-defined task: to calculate the total sale price of an item after applying a discount and tax. The other functions do not have a single, well-defined task. The function main() is the entry point for a program, and it typically performs multiple tasks, such as initializing variables, reading input, and displaying output. The function findSquareRoot() calculates the square root of a number. The function openFiles() opens one or more files.

Here is a more detailed explanation of each option:

  • Option A: main() is the entry point for a program, and it typically performs multiple tasks, such as initializing variables, reading input, and displaying output. Therefore, it is not likely to have high procedural cohesion.
  • Option B: findSquareRoot() calculates the square root of a number. Therefore, it is not likely to have high procedural cohesion.
  • Option C: getSaleSubtractDiscountAddTax() calculates the total sale price of an item after applying a discount and tax. Therefore, it is likely to have high procedural cohesion.
  • Option D: openFiles() opens one or more files. Therefore, it is not likely to have high procedural cohesion.
Exit mobile version