Class Assignment 1
Class Assignment 1
Submitted by:
Bilal Mehmood
Reg #:
SP23-BDS-058
Submitted to:
SIR RIZWAN RASHID
Assignment:
Class Assignment # 1
pg. 1
Programming paradigms:
Types:
There are basically two types of programming paradigms, which we use in solving any
problem, these are.
Imperative programming consists of sets of detailed instructions that are given to the
computer to execute in a given order. It's called "imperative" because as programmers we dictate
exactly what the computer has to do, in a very specific way. Imperative programming focuses on
describing how a program operates, step by step. The imperative programming is further divided
into three main types, which are
This paradigm emphasizes on procedure in terms of under lying machine model. It has the
ability to reuse the code and it was boon at that time when it was in use because of its
reusability. There is no difference in between procedural and imperative approach.
The program communication. The smallest and basic entity is object and all kind of
computation is performed on the objects only. More emphasis is on data rather procedure. It
can handle almost all kind of real life problems which are today in scenario.
pg. 2
Example: C++, NESL etc.
In logical paradigm we have a knowledge base which we know before and along with the
question and knowledge base which is given to machine, it produces result. It use the concepts
of AI, Machine learning and perception models.
The functional programming paradigms have its roots in mathematics and it is language
independent. The key principle of this paradigm is the execution of series of mathematical
functions. The central model for the abstraction is the functions which are meant for some
specific computation and not the data structure.
This programming methodology is based on data and its movement. Program statements
are defined by data rather than hard-coding a series of steps. There are several programming
languages that are developed mostly for database application. It is applied to streams of
structured data, for filtering,
pg. 3
a. Write JAVA statements that can produce Syntax Errors. Give three different examples
and write the names of errors.
This code contain 3 types of syntax errors as, did not use ( ; ) in 1 statement, similarly did not
tell the data type of num2 while declaring variable num2, similarly did not use (.) in output
statement. All of these are syntax errors.
b. Write JAVA statements that can produce Logical Errors. Give three different examples
and briefly explain the reason (1-2 lines).
Logical errors are those errors which occur after getting output means that your desired output is
wrong just like in above code in which wrong formulas of perimeter and area are used which
leads to logical error.
pg. 4
c. Write JAVA statements that can produce Run Time Errors. Give three different
examples and briefly explain the reason (1-2 lines).
Runtime errors occur during the execution of program mot during the compilation of program. In
the above code a string type data is added to integer type which leads to runtime error and
similarly, num2 is divided by 0 which is also a runtime error and also during printing format ,the
format is set for 2 out puts but only one variable is given which is also a runtime error.
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.
pg. 5
Error Correction
Variable declarations int count = 1; int PRIME;
int sum; double x; int newNum;
Wrong expression Sum = sum+count
Assignment operator x = 25.67;
Undeclared Variable In print statement use PRIME.
Type conversion Sum = (double)count+(double)PRIME
Output:
pg. 6
Comments (single line) The code written after ( // ) is single line comment
Comments (Multi line) The code written between ( /* */ ) is multiline comment
Special symbols ; , // , ( ) , {}
Reserve words Int , Class , public
Identifier(predefined) String , println , System
Identifier(defined by user) Num2 , num3 ,result
Standard output stream object System.out.println(“product of numbers: “ + result);
Standard output stream object Scanner input = new Scanner(System.in);
pg. 7
Question – 4: 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).
pg. 8
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)
Statements a b c d
c. a = (b++) + 3 * ++d; 15 7 UND 3
c = 2 * d + (++b) + a; 15 8 29 3
b = 2 * (++c) - (a++); 16 45 30 UND
d = d++ + d + b++ + b; UND 46 UND 98
Statements a b c sum
sum = a + b + (int) c; 3 5 14 22
c /= a; 3 UND 4.7 UND
b += (int) c - a; 3 6 4.7 UND
a *= 2 * b + (int) c; 48 6 4.7 UND
Suppose a, b, and sum is int variables and c is a double variable. What value is
assigned to each variable after each statement executes? Suppose a = 3, b = 5,
and c = 14.1
pg. 9
Question – 5:
pg. 10
Question – 6:
pg. 11