Questions
using recursion no loops allowed(for,while..ect) not allowed #4: Write a recursive function ‘bool palindrome(string s)’ that...

using recursion
no loops allowed(for,while..ect) not allowed

#4: Write a recursive function ‘bool palindrome(string s)’ that returns true if s is a palindrome and false if not.


#5: Write a recursive function 'void reverse(string &word)' that reverses the given input string.

string name = "damian";
reverse(name);
cout << name << endl;  //should display "naimad".

#6: Write a function 'string binary(int n)' that returns a string of 1's and 0's which is the binary representation of n.

cout << binary(43) << endl; // 101011

#7: Write a function 'int numTwos(int n)' which returns the number of 2's in the base-4 expansion of n.

cout << numTwos(2170) << endl; // 3

c++

In: Computer Science

Java Programming (8th Edition) Joyce Farrell p.530, Chapter 10 Problem 1E with user input with scanner...

Java Programming (8th Edition) Joyce Farrell p.530, Chapter 10 Problem 1E with user input with scanner and the following results:

Enter name of horse: ABC
Enter color of horse: Red
Enter year: 2000
Enter name of horse: DEF
Enter color of horse: Blue
Enter year: 2010
Enter number of races: 6
ABC is red and born in 2000.
DEF is blue and born in 2010.
DEF completed 6 races..

In: Computer Science

This week’s journal articles focus on empowering leadership and effective collaboration in geographically dispersed teams, please...

This week’s journal articles focus on empowering leadership and effective collaboration in geographically dispersed teams, please answer the following questions:

How do geographically dispersed teams collaborate effectively?

Please find at least three tools on the market that teams can use to collaborate on a geographically dispersed team. Please note the pros and cons of each tool.

In: Computer Science

Suppose you need to transfer some data ensuring integrity and authentication and confidentiality of data. Explain...

Suppose you need to transfer some data ensuring integrity and authentication and confidentiality of data. Explain the steps.

Please don't provide handwritten solution for this question.

In: Computer Science

You are working as a Security Engineer in ABX Company Pvt. Ltd. Suddenly, intruder has got...

You are working as a Security Engineer in ABX Company Pvt. Ltd. Suddenly, intruder has got access to their database and used them to impersonate users to get some documents. Fortunately, attack was identified and the stopped by your team. Now, your manager asked you to find a secure way to store password securely and others could not able to reverse it or use it for login. What will be your solution? Would you use hashing? If you use hashing please explain the steps.

In: Computer Science

Please write in java: Write a recursive method toNumber that forms the integer sum of all...

Please write in java: Write a recursive method toNumber that forms the integer sum of all digit characters in a string. For example, the result of toNumber("3ac4") would be 7. Hint: If next is a digit character ('0' through '9'), Character.isDigit(next) is true and the numeric value of next is Character. digit(next, 10).

In: Computer Science

**********************************java********************************************************** Purpose: The purpose for this project is to reinforce the knowledge from Chapter 9 of...

**********************************java**********************************************************

Purpose: The purpose for this project is to reinforce the knowledge from Chapter 9 of the textbook. The students will learn how to write a user defined class.

Project Objectives:

Apply UML design on user defined class

Write overloaded constructors of a class

Write mutators (i.e. get methods) and accessors (i.e. set methods) of a class

Write overloaded methods

Write main method to test the user defined class

Class Diagram:

Student must implement the Temperature class according to the following class design.

Temperature

-­‐degree: double

-­‐scale: char

+Temperature()

+Temperature(degree: double)

+Temperature(scale: char)

+Temperature(degree: double, scale: char)

+getDegreeInCelsius(): double

+getDegreeInFahrenheit(): double

+setDegree(degree: double): void

+setDegree(scale: char): void

+setDegree(degree: double, scale: char): void

+equals(obj: Temperature): boolean

+isLessThan(obj: Temperature): boolean

+isGreaterThan(obj: Temperature): boolean

Method details

The name of a method explains it usage.

getDegreeInCelsius will return the temperature’s degree in its equivalent Celsius degree. If the temperature’s scale is ‘C’, then the return value is temperature’s degree. If the temperature’s scale is ‘F’, the return value is calculated by the following formula: C = (F-­‐32)*5/9. For example, if the temperature degree is 77 and scale is ‘F’, then the method will return 25since (77-­‐32)*5/9 = 25. For another example, if the temperature degree is 77 and scale is ‘C’, then the method will return 77.

getDegreeInFahrenheit will return the temperature’s degree in its equivalent Fahrenheit degree. If the temperature’s scale is ‘F’, then the return value is temperature’s degree. If the temperature’s scale is ‘C’, the return value is calculated by the following formula: F = 1.8C+32. For example, if the temperature degree is 25 and scale is ‘F’, then the method will return 25; For another example, if the temperature degree is 25 and scale is ‘C’, then the method will return 77 since 1.8*25+32 = 77.

void setDegree(double degree) will reset the temperature to given degree without change the scale of the temperature.

void setDegree(char scale) will reset the temperature to given scale without change the degree of the temperature.

void setDetree(double degree, char scale) will reset the temperature to given degree of given scale.

equals method returns true if this temperature is equal to parameter Temperature; false otherwise. You need to compare tow temperatures under same scale. For example, you either compare whether getDegreeInCelsius return same value for both temperatures, or whether getDegreeInFahrenheit return the same value for both temperatures.

isLessThan method return true if this temperature is less than parameter Temperature ; false otherwise. Again, you need to compare two temperatures under same scale.

isGreaterThan method returns true if this temperature is greater than parameter Temperature; false otherwise. Again, you need to compare two temperatures under same scale.

Main method requirements

The main method must create four Temperature objects by using all four constructors.

The main method must test all set and get methods by setting the attributes according to user’s input then displaying the temperature by printing out the result of get methods.

The main function must test equals, isLessThan, and isGreaterThan methods by compare two Temperature objects and print out the result.

Sample pseudo code for main function

Create a Temperature object by calling default constructor

Print out the temperature’s degree in Celsius

Print out the temperature’s degree in Fahrenheit

Ask user to enter the scale and degree of the temperature

Call set method(s) to set the temperature’s degree and scale

Print out the temperature’s degree in Celsius

Print out the temperature’s degree in Fahrenheit

Repeat step 1 to 7 for all other three constructorsto create three more temperatures

Test if temperature1 equals temperature2 and print out appropriate message

Test if temperature1 is less than temperature2 and print out appropriate message

Test if temperature1 is greater than temperature2 and print out appropriate message

Repeat step 9 to 11 for other pairs of temperatures

Note on main function and debugging

Fix one error a time.

If step 2 output is wrong, then either constructor is wrong or getDegreeInCelsiu function is wrong

If step 3 output is wrong, then either constructor is wrong or getDegreeInFahrenheit function is wrong

If step 6 output is wrong, then either set method(s) is wrong or getDegreeInCelsiu function is wrong

If step 7 output is wrong, then either set method(s) is wrong or getDegreeInFahrenheit function is wrong

If step 9 output is wrong, then the equals method has problem

If step 10 output is wrong, then the isLessThan method has problem

If step 11 output is wrong, then the isGreaterThan method has problem

*******************************MY CODE **********************************************

I tried to make this program but I had trouble with a few things, please complete the program and make sure it compiles. If possible, comment. Thank you

import java.util.Scanner;
public class Temperature
{
public static void main(String[] args) {
  
Temperature temp = new Temperature(0.0,C);
System.out.println("The first Temperature has been created using the default constructor which sets");   
System.out.println("the degree to a default value of " + this.degree + "and the scale to a default value of " + this.scale);
System.out.println("The first Temperature is " + getDegreeInCelsius + " C ");
System.out.println("The first Temperature is " + getDegreeInFahrenheit + " F ");

Scanner in = new Scanner(System.in);
System.out.print("set the degree (a number) and the scale (F or C) of the first Temperature.");
double degree = in.nextdouble();
System.out.print("First set the degree: " + this.degree);
//The first Temperature has been created using the default constructor which sets
//the degree to a deafault value of 0.0 and the scale to a default value of C.
//The first Temperature is 0.00 C.
//The first Temperature is 32.00 F.
//Set the degree (a number) and the scale (F or C) of the first Temperature.
//First set the degree:
  

}
  
Temperature();
Temperature(double degree){
this.degree = degree;   
}
Temperature(char scale){
this.scale = degree;   
}
Temperature(double degree, char scale){
this.degree = degree;
this.scale = degree;
}
  
  
private double degree;
private char scale;
  
public double getDegreeInCelsius(){
if(scale == 'C' || scale == 'c'){   
return degree;
}else {
return (degree - 32) * 5 / 9.0;
}
}
  
public double getDegreeInFahrenheit(){
if(scale == 'F' || scale == 'f'){
return degree;
}else {
return (1.8 * (degree) + 3.2);
}

}
  
public void setDegree(double degree) {
this.setDegree = degree;
}
  
public void setDegree(char scale) {
this.setDegree = scale;
}
  
public void setDegree(double degree, char scale) {
this.setDegree = degree;
this.setDegree = scale;
  
}

public boolean equals(){
if(this.getDegreeInCelsius() == obj.getDegreeInCelsius()){
return true;
  
}else if(this.getDegreeInFahrenheit() == obj.getDegreeInFahrenheit()){ {
return false;
}
}
  
public boolean isLessThan(Temperature temp){
if(this.getDegreeInCelsius() < temp.getDegreeInCelsius()){
return true;
}else if(this.getDegreeInFahrenheit() < temp.getDegreeInFahrenheit()){
return true;
}else{
return false;
}
}
  
public boolean isGreaterThan(Temperature temp){
if(this.getDegreeInCelsius() > temp.getDegreeInCelsius()){
return true;
}else if(this.getDegreeInFahrenheit() > temp.getDegreeInFahrenheit()){
return true;
}else{
return false;
}
  
}

In: Computer Science

Python question Define a function called hash_string_weighted_folding(string_to_hash, modulus) that takes two parameters: a string variable string_to_hash...

Python question

Define a function called hash_string_weighted_folding(string_to_hash, modulus) that takes two parameters: a string variable string_to_hash and an integer called modulus. The function returns an integer that is the hash value of string_to_hash.

This hash function processes the string in blocks of 4 characters (the final block may be shorter depending on the length of string_to_hash) and multiplies each character’s ASCII value by a weight. The weight depends on the position of the character in the block of 4 characters: the ASCII value of the character in the first position is multiplied by 256 to the power of zero (i.e., by 1); the character in the second position has its ASCII value multiplied by 256 to the power of 1 (i.e., by 256); the third character has its ASCII value multiplied by 256 to the power of 2; and the fourth character in each block has its ASCII value multiplied by 256 to the power of 3. All of the resulting weighted values are summed and the function returns the result of this sum modulus the parameter modulus.

Note: You can use the inbuilt Python ord() function to return the ASCII value of a string character.

For example:

Test Result
string_to_hash = "Kea"
print(hash_string_weighted_folding(string_to_hash, 5519))
2959
string_to_hash = "Piwaiwaka"
print(hash_string_weighted_folding(string_to_hash, 6089))
5997
string_to_hash = "Kaki"
print(hash_string_weighted_folding(string_to_hash, 3797))
2339

In: Computer Science

General Requirements: • You should create your programs with good programming style and form using proper...

General Requirements:

• You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand;

• You should create identifiers with sensible names;

• You should make comments to describe your code segments where they are necessary for readers to understand what your code intends to achieve.

• Logical structures and statements are properly used for specific purposes.


Objectives
This assignment requires you to write a program in Java that calculates the day of week and the week of month for a given date, as well as to print the calendar of the month where the given date exists. Please note, you are not allowed to use any date based classes predefined in Java JDK.
Background




For a given date, we can use the Gregorian calendar to find the corresponding the day of the week, and the week of the month. For example, May 25 2019 is a Saturday and locates in the fourth week of May 2019. In general, we can use the following formula (Zeller’s congruence) to calculate the day of a week for any given date after October 15 1582.



where
• h is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6 = Friday)

• q is the day of the month

• m is the month (3 = March, 4 = April, 5 = May, 6=June, 7=July, 8=August, 9=September, 10=October, 11=November, 12=December, 13=January, 14 = February)

• K is the year of the century (year mod 100).

• J is the zero-based century (year/100). For example, the zero-based centuries for 1995 and 2000 are 19 and 20 respectively.
For example, For 1 January 2000, the date would be treated as the 13th month of 1999, so the values would be: q=1, m=13, K=99, J=19, so the formula is
h = (1+[13*(13+1)/5]+99+[99/4]+[19/4]+5*19) mod 7 = (1+[182/5]+99+[99/4]+[19/4]+95) mod 7 = (1+[36.4]+99+[24.75]+[4.75]+95) mod 7 = (1+36+99+24+4+95) mod 7 = 0 = Saturday

However, for 1 March 2000, the date is treated as the 3rd month of 2000, so the values become q=1, m=3, K=00, J=20, so the formula is

h = (1+[13*(3+1)/5]+00+[00/4]+[20/4]+5*20] mod 7 = (1+[10.4]+0+0+5+100) mod 7 = (1+10+5+100) mod 7 = 4 = Wednesday






Tasks You will create one program called MyCalendar.java. You should first implement the MyCalendar and MyDate classes from the following UML class diagrams. You can add extra attributes and methods, but the attributes and methods shown in the UML diagrams can’t be modified.


  

MyCalendar - myDate: MyDate - day: Day + Main(String[] args) + MyCalendar(MyDate myDate) + dayOfWeek(): Day + weekOfMonth(): int + printCalendar(): void
• Day is an enumeration data type which contains the days of the week, i.e., Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, and Sunday. • MyCalendar(MyDate myDate)is the construction method of the class MyCalendar. • dayOfWeek() method will return the day of the week for myDate. • weekOfMonth() method will return the week of the month for myDate. • printCalendar() method will print the calendar of the month for myDate. • Main(String[] args) method will read a given date from the command line, the format of the given date is dd/mm/yyyy. You can assume the date input format is always correct, but the input date may be invalid. For example, 31/02/2017 is not a valid date. If the input date is not a valid date, the program will ask user to input another valid date through keyboard. This process will be repeated until a valid date is input by the user. The valid input date will be used to create the object (myDate) of class MyDate, then the object (myCalendar) of class MyCalendar. The dayOfWeek() method, weekOfMonth() method, and printCalendar() method of myCalendar object will be called to display the day of the week, the week of the month, and the calendar of the month for the input date by the user.


MyDate
- day: int - month: int - year: int + MyDate(int day, int month, int year) + getDay(): int + getMonth(): int + getYear(): int + isDateValid(): boolean
• MyDate(int day, int month, int year) is the constructor of the class MyDate. • getDay() method returns the day of myDate object. • getMonth() method returns the month of myDate object. • getYear() method returns the year of myDate object. • isDateValid() method returns a Boolean value, i.e., a true when the myDate object is valid, and a false otherwise (notes: January, March, May, July, August, October, December has 31 days. April, June, September, November has 30 days. February has 29 days in a leap year, and 28 days in a common year.).



  
Your program must have the exact same output as the following example. Example of the program output:
java MyCalendar 29/02/2019 29/02/2019 in not a valid date, please re-input a valid date: 25/05/2019 25/05/2019 is a Saturday and located in the fourth week of May 2019 The calendar of May 2019 is:
SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
(Note: Each column indicates a day and the column width are fixed to 3 characters. The distance between two adjacent columns is fixed to three characters as well.)

In: Computer Science

Write a C++ arithmetic calculator program that performs four arithmetic operations namely addition, subtraction, multiplication and...

  1. Write a C++ arithmetic calculator program that performs four arithmetic operations namely addition, subtraction, multiplication and division. This program prompts user to enter data in the following order: First data is the number, second data is an operator and the third data is the number. You are required to:
  1. Write a function for addition.
  2. Write a function for subtraction.
  3. Write a function for multiplication.
  4. Write a function for division.
  5. Write a main program which calls four functions based on the operator selected by user.

In: Computer Science

What is the latency experienced by a memory controller on a row buffer hit?

What is the latency experienced by a memory controller on a row buffer hit?

In: Computer Science

Explain in details Hadoop architecture. Give an example of Hadoop MapReduce example using real data

Explain in details Hadoop architecture. Give an example of Hadoop MapReduce example using real data

In: Computer Science

At Brenda’s Bakery, cantaloupes are sold as follows: 1-20 cantaloupes are $.75 each 21-50 cantaloupes are...

  1. At Brenda’s Bakery, cantaloupes are sold as follows:
  • 1-20 cantaloupes are $.75 each
  • 21-50 cantaloupes are $.70 each
  • 51-100 cantaloupes are $.65 each
  • 101 or more cantaloupes are $.60 each

For example:

  • If you buy 30 cantaloupes, you will pay $21.00 (30 cantaloupes at $.70 each).
  • If you buy 6 cantaloupes, you will pay $4.50 (6 cantaloupes at $.75 each).
  • If you buy 200 cantaloupes, you will pay $120.00 (20 cantaloupes at $.60 each).
  • If you buy 60 cantaloupes (see below), you will pay $39.00 (60 cantaloupes at $.65 each)

Please write a program where you input a number of cantaloupes and Python tells you the total cost.

In: Computer Science

Create a short program in Java which contains the below information: - Has one abstract and...

Create a short program in Java which contains the below information:

- Has one abstract and two regular classes

- Has two interfaces (the two regular classes have to implement at least one interface

- At least one regular class must implement both interfaces

- The two classes have to extend the abstract class

- The abstract class must have a method

- At least one interface must have a method

- At least two fields in each class, this includes the superclass

- All the fields are instantiated within the constructor

In: Computer Science

(c++) Create a program that is like deli. You can enter peoples names in, and they...

(c++) Create a program that is like deli. You can enter peoples names in, and they will be placed into a stl queue. You can also choose to "serve" someone, which will choose the next person in line. (It will say "now serving" and then the persons's name.). Last, you can choose to "quit", which will "serve" the remaining people in the queue, and then the program will end.

In: Computer Science