Given an array myArray of numbers, write a function to square the alternate numbers of the myArray, starting from index 0 using the array method map.
Sample Input 1
[ 1, 2, 3, 4, 5 ]
Sample Output 1
[ 1, 2, 9, 4, 25 ]
Sample Input 2
[ 2, 4 ]
Sample Output 2
[ 4, 4 ]
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
function main() {
const myArray = JSON.parse(readLine());
/* Write your code here */
}
Given an array
Sample Input
[ 12, 2, 2, 4, 1 ]
Sample Output
616 -14 -14 112 -77
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
function main() {
const myArray = JSON.parse(readLine());
/* Write your code here */
}
Given an array nestedArray of arrays, write a JS program to multiply the values in the sub-array if at least one of its values is even else return zero.
Sample Input 1
[ [ 12, 1, 2, 4, 1 ], [ 18, 20, 30, 45 ], [ 49, 11, 13, 21 ] ]
Sample Output 1
[ 96, 486000, 0 ]
Sample Input 2
[ [ 0, 1 ], [ 1, 3, 4 ] ]
Sample Output 2
[ 0, 12 ]
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
function main() {
const nestedArray = JSON.parse(readLine());
/* Write your code here */
}
Create a program in Python to accept input from a student and then display if the student is eligible to graduate and if so if they will graduate cum laude, magna cum laude or summa cum laude.
Your program should prompt the student to enter his/her name and gpa. If the gpa is 4.0, then display a message stating that he/she has graduated summa cum laude. If the gpa is less than 4.0 but greater than or equal to 3.8, then display a message that they have graduated magna cum laude. If the gpa is not greater than or equal to 3.8 but greater than or equal to 3.5, then display a message that they have graduated cum laude. If the gpa is less than 3.5 but greater than 2.0, display a message that they have graduated. If the gpa is less than 2.0, display a message that they are not eligible to graduate but can take more courses to bring their gpa up to at least 2.0.
Create an abstract class named Book. Include a String field for the book’s
title and a double field for the book’s price. Within the class, include a
constructor that requires the book title, and add two get methods—one
that returns the title and one that returns the price. Include an abstract
method named setPrice(). Create two child classes of Book: Fiction and
NonFiction. Each must include a setPrice() method that sets the price for
all Fiction Books to $24.99 and for all NonFiction Books to $37.99. Write a
constructor for each subclass, and include a call to setPrice() within each.
Write an application demonstrating that you can create both a Fiction and
a NonFiction Book, and display their fields. Save the files as Book.java,
Fiction.java, NonFiction.java, and UseBook.java
Create a class named Horse that contains data fields for the name, color, and birth year. Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field that holds the number of races in which the horse has competed and additional methods to get and set the new field. Write an application that demonstrates using objects of each class. Save the files as Horse.java, RaceHorse.java, and DemoHorses.java.
Write a program to obtain the multiplication of a 4 x 4 matrix.
Polynomial addition and multiplication using linked lists.