Questions on Subroutine & Functions for BASIC

1.  If Rs. 5000 is invested at 6% how much will have been accumulated after 10 years. If calculated annually, F can be determined as: F = P(1+I)^t  if quarterly: F = P(1+I/4)^4t, Write a program to solve the above problem with subroutine.

2.  Write a program using three subroutines and UDF to calculate critical constants given by:

    C1= (A+B+C)     C2=(A2+B2+C2)    C3=(A*B*C)                                  Using Six sets of data.

3.  Write a program to either calculate X, Y or Z depending on user’s choice (Use ON-GOSUB).

    X = 5A2             Y = (5AB)1/10      Z = (AB)2

        B2                   A+B     Accept the values of A and B.

4.  Fifty members of Nature’s Club are to be served a notice by the secretary for attending the meeting, mentioned the venue, date and time. Using a subroutine Write a program.

5.  WAP using a subroutine to compute charges for sending parcels when the charges are as follows: for the 1Kg. Rs. 15.00, for additional weight for every 500gm or fraction there of Rs. 8.00.

6.  Write a program to calculate either the value of L, K or M depending on user’s choice. (Use ON-GOTO statement)

    L = (A2 + B2)/C2    A = sum of 1st 10 multiples of 3.

    K = (AB + C)2       B = Sum of 1st 10 even numbers.

    M = A/B + C2        C = Sum of 1st 10 odd numbers.

7.  The population of a country at the end of a year can be found out by multiplying the population P at the beginning of the year by (1+x/100), where x is the growth rate of the population. Taking as inputs the population P at the beginning of the year 1999 and the growth rate X, Write a program using a subroutine to find the population at the beginning of each year from 2000 to 2008.

8.  Write a basic program that reads the employee’s name, his grade and his basic pay. His wages are then calculated according to his grade. If grade A, then he receive H.A of 15% and pays income tax 20%. If grade B, then he receive H.A of 10% and pays income tax 16%. If grade C, then he receive H.A of 5% and pays income tax 12%. The employee salaries consist of (Basic Pay + House Allowance-Income Tax). Using ON-GOSUB statement write a basic program which will print out the following information about the employee:

            Name     Grade    Basic   H.A    I.T   Total Salary

9.  If 12 + 22 + 32 + 42 + 52 + 62 + ....... + N2. Then using a subroutine, write a program to compute the sum of the square of the first N natural numbers. Where N is to be taken as input.

10. If the population of a country increased by 2% every year, then calculate the population after N year using subroutine. Where initial population of the country and N year to be accepted.

11. A circular is to be issued by the secretary to seventy-five members of a nature Club. The circular should state that on the Sunday, 6th April from 7 AM, a walk carrying banner like “WE LOVE ANIMALS” or “TREES ARE OUR FRIEND” will be organised. All members must make their own banner and assembled outside the clubroom. Using a subroutine write a BASIC program.

12. To find the sum of the given series using function 1X3 + 3X5 + 5X7 + ................ + 17X19.

13. Write a program in BASIC using the user-defined function to calculate and print the value of Y, corresponding to each the following value of X. Where X = 1, 2, 3, 4, 5, ........10. A and B are taken as input. Y = BÖ((1+X2)/A2)

14. At time ‘t’ after start, the distance ‘s’ traveled by a body moving with initial velocity ‘u’ and acceleration ‘a’ is given by the formula: S=ut+1/2 at2  Using a user defined function write a program to compute S.

15. The solution of two linear equations: ax+by=c  & px+qy=r is given by as

    X =  Cq - br             Y =  ar - cp

         aq - bp                  aq - bp

    Write a program in BASIC using user-define function to find the solution of any pair of simultaneous equation by the given value of a, b, c, p, q and r. The program should print “No solution” if aq-bp=0.


Questions for C++

1. At time ‘t’ after start, the distance ‘s’ traveled by a body moving with initial velocity ‘u’ and acceleration ‘a’ is given by the formula: S=ut+1/2 at2  Using a user defined function write a program to compute S.

2. If Rs. 5000 is invested at 6% how much will have been accumulated after 10 years. Then calculate F, F can be determined as F = P(1+I)^t. Write a program to solve the above problem using function.

3.  Write a program using three Functions calculate the critical constants given by:

    C1= (A+B+C)    C2=(A2+B2+C2)           C3=Ö(A*B*C)

                        3   Using Six sets of constant data.

4.  Write a program to either calculate X, Y or Z depending on user’s choice (Use switch case).

    X = 5A2     Y = (5AB)1/10    Z = (AB)2

        B2                          A+B     Accept the values of A and B.

5. WAP using a function to compute charges for sending parcels when the charges are as follows: for the 1Kg. Rs. 15.00, for additional weight for every 500gm or fraction there of Rs. 8.00.

6.  WAP using three functions to calculate either the value of L, K or M on user’s choice. (Use switch case)

    L = (A2 + B2)/C2         A = sum of 1st 10 multiples of 3.

    K = (AB + C)2            B = Sum of 1st 10 even numbers.

    M = A/B + C2             C = Sum of 1st 10 odd numbers.

7. WAP a program that reads the employee’s name, his grade and his basic pay. His wages are then calculated according to his grade. If grade A, then he receive H.A of 15% and pays income tax 20%. If grade B, then he receive H.A of 10% and pays income tax 16%. If grade C, then he receive H.A of 5% and pays income tax 12%. The employee salaries consist of (Basic Pay + House Allowance-Income Tax). Using a single function (with switch case) write program which will print out the following information about the employee:

          Name    Grade     Basic     H.A    IT   Total Salary

8. WAP to check whether a given number is Armstrong or not using a function name check. Function should return a value 1 if number is Armstrong otherwise it return 0 if not.

9.  WAP using a function prime to check whether a given number is Prime or not. Function should return a value 1 if number is Armstrong otherwise it return 0 if not.

10. Write a menu driven program (using switch case) to find the areas of rectangle, sphere or triangle. While finding the area of the triangle care must be taken to check whether a triangle must be formed with the set of data inputted. Use separate function for each of the given shapes.

11. Write a program to print in the manner given below. Use one function for printing alphabets and another function to print the number.

                a a a a a 1

                b b b b 1 2

                c c c 1 2 3

                d d 1 2 3 4

                e 1 2 3 4 5

12. Raising a no ‘n’ to power ‘p’ is the same as multiplying ‘n’ by itself ‘p’ times. Write a function name power with two arguments a double value for ‘n’ and an int value for ‘p’ and return the result as double. Use default argument, as 2 for ‘p’ so that if the argument is omitted the number will be squared. WAP that gets a value from user to test the power function.

13. Write a Function to sort an array of integers using insertion sort. The function should have 2 parameters array name and number of elements in array.

14. A, B, C are arrays of integer of size M, N, (M+N). The numbers in the array A appears in ascending order, while number in B appears in descending order. Write a function to produce 3rd array ‘C’ by merging array ‘A’ and ‘B’ in ascending order. Use A, B, C as an argument in a function.

15. Suppose an array ‘AR’ containing integers in ascending order. Write a function to search an integer from AR with help of binary searching. Receiving an integer ‘0’ to show the absence of it and integer ‘1’ to show presence. The function should have three parameters AR, number to be searched, no of elements.