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

Assignment 1

Uploaded by

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

Assignment 1

Uploaded by

alina.raza2017
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

COMSATS University Islamabad

Department of Computer Science


Programming Fundamentals (CSC103)
Class Assignment – 1 (CLO-1)

Instructions

Submit assignment online within given time.

Answer to all questions should begin on new page.

Assignment document must contain a title page showing Assignment-1, your name and
registration number.

Assignment document must also contain JAVA source code (For JAVA Programming Questions)
along with output.

You must follow proper JAVA naming convention for identifiers and properly document your
source code

Plagiarism: Plagiarism is not allowed. If found plagiarized, zero marks will be awarded in the
assignment.
COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103)
Class Assignment – 1 (CLO-1)

Question – 1: This question focuses on the types of errors

a. Write JAVA statements that can produce Syntax Errors. Give three different examples
and write the names of errors
b. Write JAVA statements that can produce Logical Errors. Give three different examples
and briefly explain the reason (1-2 lines)
c. Write JAVA statements that can produce Run Time Errors. Give three different examples
and briefly explain the reason (1-2 lines)
d. The following program has syntax errors. Write clearly type of error and its correction
(in tabular form). After you have corrected the syntax errors, show the output of this
program.

public class Test{


public static void main(String[] arg){
count = 1;
sum = count + PRIME;
x := 25.67;
newNum = count * ONE + 2;
sum + count = sum;
x = x + sum * COUNT;
System.out.println(" count = " + count + ", sum = "
+ sum + ", PRIME = " + Prime);
}
}
COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103)
Class Assignment – 1 (CLO-1)

Question – 2: This question focuses on the basic elements of JAVA language (comments,
Special Symbols, Reserve Words and Identifiers)

Consider following JAVA Code


/*This program will calculate product of three numbers */
public class Product{
public static void main(String[] args){
int num1 = 10; // first number
int num2 = 20; // second number
int num3 = 1;// third number
int result; //product of numbers
result = num1 * num2 * num3;
System.out.println("Product of numbers: "+result);
}
}

You are required to identify following (Show your answer as tabular form)
- comments (Single Line, Multiline),
- Special symbols (three)
- Reserve words (three)
- Identifier (predefined and defined by user) (three each)
- Standard Input Stream Object
- Standard Output Stream Object
COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103)
Class Assignment – 1 (CLO-1)

Question – 3: This question focuses on the basic elements of JAVA language (Primitive Data
Types, Expressions and Assignments, Arithmetic Operators, Order of Precedence, Augmented
Assignment Operators, Type Conversion)

a. Write Java statements that accomplish the following.


o Declare int variables x and y.
o Initialize an int variable x to 10 and a char variable ch to ' B '.
o Update the value of an int variable x by adding 5 to it.
o Declare and initialize a double variable payRate to 12.50.
o Copy the value of an int variable firstNum into an int variable tempNum.
o Swap the contents of the int variables x and y. (Declare additional variables, if
necessary.)
o Suppose x and y are double variables. Output the contents of x , y , and the
expression x +12/ y – 18.
o Declare a char variable grade and set the value of grade to 'A'.
o Declare int variables to store four integers.
o Copy the value of a double variable z to the nearest integer into an int variable
x.
b. Suppose a, b and c are int variables and a = 5, b = 6, d = 2. What value is assigned to
each variable after each statement executes? If a variable is undefined at a particular
statement, report UND (undefined)
NOTE: Consider a = 5, b = 6, d = 2 for all of the following statements.
Statements a b c d
a = (b++) + 3 * ++d;
c = 2 * d + (++b) + a;
b = 2 * (++c) - (a++);
d = d++ + d + b++ + b;

c. Suppose a, b, and sum are int variables and c is a double variable. What value is
assigned to each variable after each statement executes?
NOTE: Consider a = 3 , b = 5 , and c = 14.1 for all of the following
statements.
Statements a b c sum
sum = a + b + ( int) c;
c /= a;
b += (int) c - a;
a *= 2 * b + (int) c;
COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103)
Class Assignment – 1 (CLO-1)
Question – 4:
COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103)
Class Assignment – 1 (CLO-1)

Question – 5:

Question – 6:

Question – 7:

NOTE: Solve the above problem without using loop.


COMSATS University Islamabad
Department of Computer Science
Programming Fundamentals (CSC103)
Class Assignment – 1 (CLO-1)
Question – 8:

Question – 9:

Question – 10:

You might also like