Hiranandani Trust School Internal Assessment
Hiranandani Trust School Internal Assessment
The Class ChoiceOverload uses character-based user decisions to dynamically alter calculations, such as deciding between computing squares or cubes, products or sums, and assessing string equality. This character-based choice allows the same method name to serve multiple purposes, enhancing user interaction and decision-making flexibility. It fosters flexibility in program design by allowing user-driven logic paths that handle a variety of computations flexibly without necessitating multiple distinct method calls or classes, thereby encapsulating multiple operations within streamlined control structures.
When calculating the area using method overloading, it's crucial to define methods that reflect the specific geometric characteristics and formulae for each shape. For triangles, the Heron's formula is implemented requiring three side lengths. For trapezoids, one method uses base lengths and height with appropriate coefficients, while for quadrilaterals like rhombuses or kites, the method uses diagonals for calculation. By overloading based on parameter signature—distinguishing each shape's parameters—the program effectively manages diverse geometric calculations under a unified method name streamlining function invocation based on context.
The electricity bill calculation method categorizes unit consumption into three tiers: (1) For 0 to 100 units, the charge is calculated at ₹1.25 per unit; (2) For units between 101 and 200, in addition to the first 100 units charged at ₹1.25 per unit, the additional units are charged at ₹1.50 per unit; (3) For units above 200, the additional units beyond 200 are charged at ₹1.80 per unit. This tiered pricing model helps determine the total bill based on the units consumed and provides a progressive charge on electricity usage.
The Pronic number program verifies if a number is Pronic by checking if the number can be expressed as the product of two consecutive integers. This is done by iterating through integers from 1 up to the number itself, and for each integer i, it calculates the product i * (i + 1) and checks if it matches the given number. The logic involves consecutive integers because a Pronic number is defined as the product of two consecutive integers, which means it fits the definition only if such a pair is found for the input number.
Function overloading allows the program to define multiple versions of the 'volume' method, each differing in parameter types and quantities to calculate volumes of a cube, sphere, and cuboid. For a cube, the function takes one float for the side. For a sphere, it takes a float for radius and height erroneously but is intended for proper radius and computes differently. For a cuboid, it takes three floats for length, breadth, and height. This method is beneficial in coding because it allows the concise organization of functions under one common name that distinguishes based on input parameters, encourages code reuse, and enhances readability and maintainability.
The pattern display program begins by printing the entire word, then repetitively reduces the number of characters displayed by one from the end in each subsequent line. By iterating backward through the word's length and using a nested loop to print characters up to the remaining length, the program constructs a pyramid-like pattern. This successive decrement ensures a descending character row alignment, which creates a symmetric stepwise visual effect. This mechanism efficiently visualizes strings in diminishing layers, emphasizing patterns through character manipulation.
The Transpose class reads a 4x4 matrix and processes it by iterating through its elements, swapping the row and column indices. It effectively creates a new matrix where the original matrix's rows become the new matrix's columns. This rearrangement is significant in linear algebra for operations such as transforming coordinate systems, solving systems of equations, and simplifying matrix expressions in theoretical and applied mathematics. The transposing operation enhances understanding and manipulation of data arrangement within matrices.
The logic for calculating bus fare operates on a tiered pricing strategy, which charges a base fare of ₹80 for distances up to 5 km. For distances greater than 5 km but not exceeding 15 km, an additional charge of ₹10 per km applies to the distance between 5 and 15 km. For distances over 15 km, a further fee of ₹8 per km is added for each kilometer beyond 15. This tiered strategy exemplifies effective pricing that increases with distance, mimicking utility-based and consumption-based strategies, helping manage capacity and revenue based on usage intensity and service level demand.
The Successor Product program computes a product by iterating through the digits of an input number and identifying the even digits. For each even digit, the program computes the successor (the next integer) and multiplies it to an accumulating product variable. If there are no even digits in the number, the program outputs 'No even digits.' The use of the successor ensures that each even digit contributes a factor that is one greater than it would have been.
The program identifies Happy Numbers by repetitively transforming a number through a process of summing the squares of its digits until the result is a single-digit number. This iterative process tests if the resulting number equals 1, which classifies the original number as a Happy Number. If the process results in any other number, it is deemed not a Happy Number. This classification depends on digit manipulation because it breaks down the number to its digit constituents to evaluate over repeated iterations.