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

Class Assignment 1

The document discusses different programming paradigms including imperative and declarative paradigms. Imperative paradigms include procedural, object-oriented, and parallel processing approaches. Declarative paradigms include logical, functional, and database programming. Examples are provided for each paradigm type.

Uploaded by

mehmoodbilal177
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Class Assignment 1

The document discusses different programming paradigms including imperative and declarative paradigms. Imperative paradigms include procedural, object-oriented, and parallel processing approaches. Declarative paradigms include logical, functional, and database programming. Examples are provided for each paradigm type.

Uploaded by

mehmoodbilal177
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

PROGRAMMING FUNDAMENTALS

Submitted by:
Bilal Mehmood

Reg #:
SP23-BDS-058

Submitted to:
SIR RIZWAN RASHID

Assignment:
Class Assignment # 1

pg. 1
Programming paradigms:

A programming paradigm is the classification, style or way of programming. It is an


approach to solve problems by using programming languages. Difficulty of paradigms depends
on the programming language we use.

Types:

There are basically two types of programming paradigms, which we use in solving any
problem, these are.

 Imperative programming paradigms


 Declarative programming paradigms

Imperative programming paradigms:

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

Procedural programming paradigm:

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.

Example: FORTRAN, c++ etc.

OOP programming paradigm:

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.

Example: Java, python etc.

Parallel processing approach:

Parallel processing is the processing of program instructions by divided into multiple


processors. A parallel processing system possesses many numbers of processor with the
objective of running a program in less time by dividing them.

pg. 2
Example: C++, NESL etc.

Declarative programming paradigm:

Declarative programming is a programming paradigm in which the programmer defines


what needs to be accomplished by the program without defining how it needs to be implemented.
In other words, the approach focuses on what needs to be achieved instead of instructing how to
achieve. Declarative programming paradigm is also divided into 3 categories.

Logical programming paradigm:

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.

Example: Prolog etc.

Functional programming paradigm:

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.

Example: Perl, JavaScript etc.

Database programming paradigm:

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,

Example: SQL, AWK etc.

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

Now the correct code and output is as,

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

You might also like