1) Convert the following Java code by using a function in C++, Python. public class lab9{ public static void main(String []args) { System.out.println(" System.out.println(" System.out.println(" System.out.println(" The output is public static int cale (int arg1, int arg2, char arg3) { int total=0; if (arg3 =='+') } total = arg1 + arg2; if (arg3==¹*¹) total = arg1 * arg2; if (arg3 == '-') total = arglarg2; if (arg3 == '/') 10+ 20 = " + calc(10,20,'+')); 10 * 20 = " + calc( 10, 20, '*')); 10 - 20 = " + calc( 10, 20, '-')); 10/20 = " + calc( 10, 20, '/')); total = arg1/ arg2; return total; } 10+ 20 10 * 20 10 - 30 200 20 = -10 10/200 } 2) Write your codes again in C++, Python by using total as a global variable. Don't return total from the function and the output will be the same.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
icon
Related questions
Question

 

 

1) Convert the following Java code by using a function in C++, Python.
public class lab9{
public static void main(String [] args) {
System.out.println("
System.out.println("
System.out.println("
10 + 20 = " + calc(10,20,'+'));
10 * 20 = " + calc( 10, 20, '*'));
10 - 20 = " + calc( 10, 20, '-'));
System.out.println(" 10/20 = " + calc( 10, 20, '/'));
}
The output is
public static int calc (int arg1, int arg2, char arg3) {
int total=0;
if (arg3 == '+')
total = arg1 + arg2;
= ¹*¹)
=
if (arg3=
total arg1 * arg2;
if (arg3 == '-')
total = arglarg2;
if (arg3 == '/')
total = arg1 / arg2;
return total; }
10 + 20 = 30
10 20 = 200
10
20 = -10
10 / 20 =
2) Write your codes again in C++, Python by using total as a global variable. Don't return
total from the function and the output will be the same.
Transcribed Image Text:1) Convert the following Java code by using a function in C++, Python. public class lab9{ public static void main(String [] args) { System.out.println(" System.out.println(" System.out.println(" 10 + 20 = " + calc(10,20,'+')); 10 * 20 = " + calc( 10, 20, '*')); 10 - 20 = " + calc( 10, 20, '-')); System.out.println(" 10/20 = " + calc( 10, 20, '/')); } The output is public static int calc (int arg1, int arg2, char arg3) { int total=0; if (arg3 == '+') total = arg1 + arg2; = ¹*¹) = if (arg3= total arg1 * arg2; if (arg3 == '-') total = arglarg2; if (arg3 == '/') total = arg1 / arg2; return total; } 10 + 20 = 30 10 20 = 200 10 20 = -10 10 / 20 = 2) Write your codes again in C++, Python by using total as a global variable. Don't return total from the function and the output will be the same.
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT