Programming & Computer Science Answers

C++ 9913
Python 5288
Java | JSP | JSF 3611
C 1680
C# 1362
Computer Networks 989
Algorithms 652
Databases | SQL | Oracle | MS Access 641
HTML/JavaScript Web Application 588
Other 537
Visual Basic 358
Assembler 209
Software Engineering 202
AJAX | JavaScript | HTML | PHP 166
MatLAB 150
MatLAB | Mathematica | MathCAD | Maple 124
Action Script | Flash | Flex | ColdFusion 112
UNIX/Linux Programming 89
Web Development 73
Excel 36
ASP | ASP.NET 23
Delphi | Pascal 21
Perl 16
Prolog 9
Functional Programming 9
MathCAD 5
Wolfram Mathematica 4
WPF 4
Ruby | Ruby on Rails 3
NodeJS Web Application 2

Questions answered by Experts: 26 876

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

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,

  • Area of circle = π * radius * radius
  • Circumference of circle = 2 * π * radius

Input

  • The input will be a single line containing a number radius

Output

  • The first line of output should contain the area of the circle
  • The second line of output should contain the circumference of the circle

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

  • The formula for bill is,
  • bill = dayCharge * days
  • The formula to calculate the discounted bill,
  • bill - (bill * discount) / 100

Apply discounts on the following basis,

  • 5%, if the customer stays more than 2 days
  • 15%, if the customer stays more than 5 days

Input

  • The first line of input contains a number dayCharge
  • The second line of input contains a number days

Output

  • The output should be a single line containing the total bill with the discount

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

father, mother, and child, write a JS program to concatenate all the objects into the family object using the spread operator.Input

  • The first line of input contains an object father
  • The second line of input contains an object mother
  • The third line of input contains an object child

Output

  • The output should be a single line string with the appropriate statement as shown in sample outputs

Constraints

  • Keys of the objects should be given in quotes

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)

Input

  • The first line of input contains a number principal
  • The second line (optional) of input contains a number time
  • The third line (optional) of input contains a number apprPercentage

Output

  • The output should be a single line containing the finalValue

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.


LATEST TUTORIALS
APPROVED BY CLIENTS