Arithmetic Operations
Given a constructor function
ArithmeticOperations in the prefilled code and two numbers firstNumber and secondNumber as inputs, add the following methods to the constructor function using the prototype.MethodDescriptionratioOfNumbersIt Should return the ration of the numberssumOfCubesOfNumbersIt Should return the sum of cubes of the numbersproductOfSquaresOfNumbersIt Should return the product of squares of the numbers
The
secondNumber should not be equal to zero
Sample Input 1
8
4
Sample Output 1
2
576
1024
Sample Input 2
5
5
Sample Output 2
1
250
625
i want code in between write code here
"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 ArithmeticOperations(firstNumber, secondNumber) {
this.firstNumber = firstNumber;
this.secondNumber = secondNumber;
}
function main() {
const firstNumber = JSON.parse(readLine());
const secondNumber = JSON.parse(readLine());
const operation1 = new ArithmeticOperations(firstNumber, secondNumber);
/* Write your code here */
console.log(operation1.ratioOfNumbers());
console.log(operation1.sumOfCubesOfNumbers());
console.log(operation1.productOfSquaresOfNumbers());
}
"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 ArithmeticOperations(firstNumber, secondNumber) {
this.firstNumber = firstNumber;
this.secondNumber = secondNumber;
}
function main() {
const firstNumber = JSON.parse(readLine());
const secondNumber = JSON.parse(readLine());
const operation1 = new ArithmeticOperations(firstNumber, secondNumber);
/* Write your code here */
ArithmeticOperations.prototype.ratioOfNumbers = function() {
return this.firstNumber / this.secondNumber;
};
ArithmeticOperations.prototype.sumOfCubesOfNumbers = function() {
return this.firstNumber ** 3 + this.secondNumber ** 3;
};
ArithmeticOperations.prototype.productOfSquaresOfNumbers = function() {
return this.firstNumber ** 2 * this.secondNumber ** 2;
};
console.log(operation1.ratioOfNumbers());
console.log(operation1.sumOfCubesOfNumbers());
console.log(operation1.productOfSquaresOfNumbers());
}
Comments
Leave a comment