Examine the C++, Python, and Java codes that do swap two values, which one you think is the best, which one you think is the worse – Note: identify the language evaluation criteria you used, but no need to justify.
C++ PROGRAM
//include required library file
#include <iostream>
//use nmaespace
using namespace std;
//main function defintion
int main()
{
//declare and initialize the required variables
int a = 10, b=20, temp;
//print the values before swapping
std::cout << "a = " <<a <<", b = "<<b
<< std::endl;
//code to swap
temp = a;
a=b;
b=temp;
//print the values after swapping
std::cout << "a = " <<a <<", b = "<<b
<< std::endl;
return 0;
}
JAVA PROGRAM
//Main class definition
public class Main
{
////main function defintion
public static void main(String[] args) {
//declare and initialize the required variables
int a = 10, b=20, temp;
//print the values before swapping
System.out.println("a = " + a + ",
b = " + b);
//code to swap
temp = a;
a=b;
b=temp;
//print the values after
swapping
System.out.println("a = " + a + ",
b = " + b);
}
}
PYTHON PROGRAM
#declare and initialize two variables with values
a = 10
b = 20
#print the values
print('a = ',a , ", b = ",b)
# create a temporary variable and use it to swap the values
temp = a
a = b
b = temp
#print the values after swapping
print('a = ',a, ", b = ",b)
EXPLANATION
-> Python is the best
-> C++ is the worst
(Simplicity is the criteria used for comparison)
Examine the C++, Python, and Java codes that do swap two values, which one you think...
USE JAVA, PYTHON OR C TO WRITE AN ALGORITHM FOR THIS EXERCISE: . Chocolate bar puzzle Given an n × m chocolate bar, you need to break it into nm 1 × 1 pieces. You can break a bar only in a straight line, and only one bar can be broken at a time. Design an algorithm that solves the problem with the minimum number of bar breaks. What is this minimum number? Justify your answer by using the properties...
To swap two elements of a python list, I need: Select one: a. a new element at the beginning of the list b. a new element at the end of the list Question text To swap the content of two nodes from a doubly-linked-list, I need: Select one: a. a reference to previous only. b. a reference to previous and a reference to next. c. a temporary Doubly-Linked-List node. d. a temporary variable to contain an object. Question text To...
In a sensible language ( any of C#/Java/Python) write a program which correctly calculates add, subtract, multiply and divide using our ‘minifloat’ binary format using an algorithm you code yourself. Some details: Your program only needs to work on two ‘numbers’ at a time, read those in from a text file – failure to read those values from a text file will result in a grade of 0. For each ‘number’ store the sign, exponent and mantissa separately. You can hard code your...
What is the difference between a partnership and a corporation, and which one do you think is best for a small business?
PLEASE DO THIS IN PYTHON!!! Question 6 (Can you graduate? – 30 pts): Write a complete program that asks the user for their GPA (Grade Point Average) and reads that number in. If the user’s GPA is between 2.0 and 3.9, print “You can graduate.” If the GPA is 4.0 print “You’re my hero!” Otherwise, it should print “Raise your GPA!” Please indicate which language you are using to answer the question (Pseudocode, C#, Java or Python).
C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists of any primitive type you want. (Array of size 2020) (This could be based on MSDN libraries or the lab) – you do not need to instantiate any of the linked lists to contain any actual values. Paste your code for that here (this should only be one line) Based on your code or the lab from 4 or your doubly linked list from...
Discuss, define, compare, and contrast the four major tests of insanity. Which one do you think is best?
2. Examine Metro’s Statement of financial position and identify which accounts you think will require adjusting entries at the year end. Explain why this would be required. 3. A customer purchases $150 of goods at a Metro store using a $100 gift card with the remaining amount in cash. Prepare the journal entry for this transaction. 4. Looking at Note 4 explain why it is necessary for Metro to make judgements and estimates. Using fixed assets as an example, explain...
Write a complete Java program which has two methods, one to enter values for an array and another one to sort it using Bubble Sort method. Draw DIAGRAMS for memory allocation, AR and ARI for the program.
a. what ethical company did you think of? why? which one of the perspectives do they fall under? b. what unethical company did you think of? why? which one of the perspectives do they fall under? c. what perspectives do you think are most relevant in society today? why? repond to a. b. and c. parts of the question. the image is there to help you answer part of the question Perspectives Utilitarianism Categorical imperative Rawl's Justice as fairness Aristotelian...