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.
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.
Chapter2: Using Data
Section: Chapter Questions
Problem 14RQ
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.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa74f7004-18d8-49c4-b3ac-81dd188e4a7b%2Fe28d3ae0-811d-4380-b1ca-e99a6eeabf76%2Fz9i4fs5_processed.jpeg&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
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.Recommended textbooks for you
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT