[SOLVED] CPT121-Task 1.1.3 Variables, Types and Casting

24.99 $

Programming resource
Digital learning resource
Category:
✓ Practical programming resource
✓ Suitable for guided study and reference
✓ Tutor guidance available when needed

Description

Rate this product
  1. Give appropriate declarations (type and name) for variables used to store the following values:
    1. An employee’s taxable salary e) The average rainfall for the past month
    2. The month number within a year f) A letter to hold an answer (‘y’ or ‘n’)
    3. An employee identification number g) The constant string “Hello”
    4. The capacity of a tank in cubic inches h) The conversion rate from $AUS to $US

 

 

  1. Assuming that the types of the variables x, y, and z  are int, float  and double  respectively, which of the following statement(s) are likely to result in error ?

 

  1.                   a) x = y;              b) x = z;               c) y = x;
  2.                   d) y = z;              e) z = x;                f) z = y;

 

  1. The following code segment prints an incorrect result (instead of the expected result of sqr = 10000000000 ).

int num1 = 100000; int sqr = num1 * num1;

System.out.println(“sqr = ” + sqr);

 

Describe the problem / error that has occurred and suggest a solution or work-around to the problem which will allow the correct result to be stored and printed.

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.