Area and Circumference of a Circle
Given radius
radius of a circle, write a JS constructor function with the methods getArea and getCircumference to calculate the area and circumference of the circle.
Note
The value of π = 3.14
Quick Tip
Use the formulae to calculate,
Sample Input 1
7
Sample Output 1
153.86
43.96
Sample Input 2
25
Sample Output 2
1962.5
157
Hotel Bill
A Hotel is offering discounts to its customers.
Given charge per day
dayCharge based on category and numbers of days customer stayed days as inputs, write a JS arrow function to return the total bill with the discount.
Quick Tip
Apply discounts on the following basis,
Sample Input 1
200
3
Sample Output 1
570
getting 600 but actual output is 570.
Sample Input 2
180
1
Sample Output 2
180
Unite Family
Given three objects
Sample Input
{'surname' : 'Jones', 'city': 'Los Angeles'}
{'dish': 'puddings'}
{'pet': 'Peter'}
Sample Output
Mr and Mrs Jones went to a picnic in Los Angeles with a boy and a pet Peter. Mrs Jones made a special dish "puddings"
Sample output-2
Expected: Mr and Mrs Williams went to a picnic in Columbia with a boy and a pet Rocky. Mrs Williams made a special dish "cakes"
your output: Mr and Mrs Jones went to a picnic in Los Angeles with a boy and a pet Peter. Mrs Jones made a special dish "puddings"a. An algorithm is a procedure for solving a problem in terms of the actions to execute and the order in which these actions execute. Write an algorithm for the implementation of the sentinel control in Question A Sub Question.
B. For larger datasets, a linear search may be inadequate or perhaps inefficient. What other search method can be employed to return the maximum number from a set of elements in an array. Explain your answer. [5 marks]
I. Identify and correct the errors in each of the following sets of code: [6 marks] i.
while ( c <= 5 ) {
product *= c; ++c;
ii. if ( gender == 1 )
System.out.println( "Woman" );
else;
System.out.println( "Man" );
iii. What is wrong with the following while statement?
while ( z >= 0 )
sum += z;
D. Explain two (2) programming situations that will require the use of overloaded methods [5 marks]
Write a java program that reads three (3) int variables and performs the below operations:
i. Prints out their product
ii. Prints out the maximum of the numbers Do not use any inbuilt Java Methods to return the maximum. Extra marks will be awarded for clarity of code and comments. [8 marks]
B. Algorithms perform differently on different data sets and as such we may be interested in either their Best-case, Worst-case or Average-case scenarios. Explain why the Worst-case for an insertion sort is with reverse-sorted data. [6 marks]
C. Identify and correct the errors in each of the following sets of code: [6 marks]
i. while ( c <= 5 )
{
product *= c; ++c;
ii. if ( gender == 1 )
System.out.println( "Woman" );
else;
System.out.println( "Man" );
iii. What is wrong with the following while statement?
while ( z >= 0 )
sum += z;
D. Explain two (2) programming situations that will require the use of overloaded methods [5 marks]
After the Python code below has run, what happens if 'the_file' does not already exist?
try:
fin = open('the_file', 'r')
except:
fin = open('the_file', 'w')
fin.close()
Final Value with Appreciation
Given principal amount
principal as an input, time period in years time and appreciation percentage apprPercentage as optional inputs, write a JS function to return the final value finalValue with the given appreciation percentage and time period. The default values for time and apprPercentage are 2 and 5 respectively.
Quick Tip
The formula to calculate the final value with appreciation is,
finalValue = principal * (1 + time * appreciation / 100)
Sample Input 1
1000
2
3
Sample Output 1
1060
Sample Input 2
3000
Sample Output 2
3300.0000000000005
Write a program to get an integer from the user (to enter the number of students) and store it in the num variable. Then, allocate the memory dynamically for the float array using new operator. Next enter data(student register number) into the array using pointer notation. Arrange register number from lower to highest. After this you no longer need the array, so deallocate the array memory using the delete operator.
A).Consider a problem to find the student who had the highest GPA for the 2020/2021 academic year.
i. Explain your choice of either a search or a sorting algorithm to solve this problem. [7.5 marks]
ii. Write the algorithm for your implementation. [7.5 marks]
B). Consider the analogy of a pile of books on a table. Using a diagram, explain the basic operations involved in adding a book to the pile and removing a book from the pile. [5 marks]
C). Use the code below to answer the questions that follow: [5 marks]
public class CS204 { public static int linearSearch(int[] data, int target) {
for (int i = 0; i < data; i++) {
if (target == data[i]){
return i;
}
}
return -1;
}
public void main(String[] args) {
int[] data = {3, 14, 7, 22, 45, 12, 19, 42, 6}; System.out.println("Search for 7: " + linearSearch(7));
}
}
i). Why is method linearSearch declared static? Identify and resolve the errors in the code.
ii) identify nd resolve the errors in the code.