0% found this document useful (0 votes)
4 views

Assignment 2

Uploaded by

ekhlasbilal4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Assignment 2

Uploaded by

ekhlasbilal4
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Al-Azhar University – Gaza Course Code: ITCS4302

Faculty of Engineering & IT Course Name: CPL


Department of IT & CSE 2nd Semester – 2023/2024

Assignment (2)
St. Name: (Total Marks: 10) St. Reg.#:

Q1: Explain why Java and Ada treat mixed-mode expressions differently, and
analyze the implications of this difference using the following examples:

• Java: int x = 10; double y = 2.5; double z = x + y;


• Ada: X : Integer := 10; Y : Float := 2.5; Z : Float := X + Y;

What would happen in Python, and why does its approach differ?

Q2: Given the Python code:

x=0

if x > 0 and (10 / x) > 2:

print("Valid")

else:

print("Invalid")

Why does this code not result in a runtime error? Modify the code to avoid relying
on short-circuit evaluation for safety.
Q3: In Python, implement a class Vector that supports addition (+) and scalar
multiplication (*). Write an overloaded operator for each operation and demonstrate
its usage with examples.

Q4: Consider the Java code:

int x = 0;

if (x > 0 && (10 / x) > 2) {

System.out.println("Valid");

} else {

System.out.println("Invalid");

Explain the behavior of this code. How would removing short-circuit evaluation (&
instead of &&) change the outcome?

Q5: Evaluate the following Python expression step-by-step based on operator


precedence:

result = 10 - 2 ** 3 / 4 + 5

How would changing the exponentiation operator (**) to left-associative affect the
result?

You might also like