Computer science Hw

profilelaram14
chapter2__2.cs_.docx

Assignment 1: Data Types and Expressions

Name: __________________________________________ Date ____________________________________________

1. Define following terms:

a. Variables

b. Literals

c. Object

d. Keyword

e. Byte

2. What is following type of statement called?

f. result +=15

Is it same as result = result + 15?

3. Suppose x, y, and z are int variables and x = 2, y = 6, and z = 10, keeping the original values in each equation what will be in the memory locations of each of the variables x, y, and z following execution:

x

y

z

z = ++y % 2

(for example)

2

7

1

x = y + 14 – z / 7

x = y * z/ 2 – x * z

x %= - -z – y * 2

y = (z – y) * 2 = - -y

4. Suppose x, y, and z are type double and x = 2.5, y = 6.9, and z = 10.1 keeping the original values in each equation what will be in the memory locations of each of the variables following execution:

x

y

z

z *= y++ % 7

x = (int) y + (14 – z / 7)

x= z / 3 * - -y

z /=(int) y / x

z = x + y / 4

5. Correct the syntax error and show the values using print statement.

namespace ConsoleApplication1

{

class Program

{

static void Main(string[ ] args)

{

int num1 = 10

num2 = 25;

double = 45.5;

float val1 = 33.6;

string word1 = "C# is a programming language;

char letter = a';

val2 = 100M;

/* print statement should go below this line */

Console.Read();

}

}

}

Your output should be like the output below.

6. Write a program that will give the areas of tennis and badminton courts in square feet. The dimensions of tennis court are 36 feet wide and 78 feet long and that of badminton court is 20 feet wide and 44 feet long.

(Hint: Formula for area = width * length)

COSC 1436 Page 1