CS 508

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

CS 508

Assignment No 1
BC200407853
Question No. 1: Marks: 5
Compare the following code snippets in C and Ada. How do the operators and data types differ between the two
languages?

C Code Snippet:

Ada Code Snippet:


Solution:
C and Ada, while both being complied languages, have some key differences in operators and data types:
Operators:
Overloaded Operators:
C has some overloaded operators like + (addition and string concatenation), while Ada
generally uses separate operators for different functionalities.
Bitwise Operators:
C provides a comprehensive set of bitwise operators(&&,|,^,etc.) for manipulating bits
within a data type, which are less common in Ada.
Short-circuit Evaluation:
C performs short-circuit evaluation for logical operators(&&,||) where the evaluation
stops after the first operand determines the result. Ada requires explicit evaluation of both operands.

Data Types:
Implicit Type Conversion:
C allows implicit type conversion between compatible data types, which can
sometimes lead to unexpected behavior. Ada is stricter, requiring explicit casting when
converting between data types.
Enumeration Types:
Both languages support enumerated data types but C’s syntax is simpler.
Record Types:
Ada offers a stronger record type system with features like named fields and
access types for safe manipulation. C’s record-like structures are less structured.
Pointer Arithmetic:
C allows pointer arithmetic, which can be powerful but also error-prone. Ada
avoids pointer arithmetic for safer memory management.

Question No. 2: Marks 5

You are required to fill out the following table correctly by writing the name of appropriate language in front
of each row.

Note: Please don’t create a new table; use the following table only.

Statement Appropriate
Language
The programming language was designed primarily for hardware description. VHDL(VHSIC
Hardware Description
Language)
The programming language known for its powerful operators for string pattern Perl
matching but suffered from poor readability and maintainability.
The first programming language introduced the concept of a class, which served as Stimuli
the basis for data abstraction.

The programming language was primarily designed for teaching structured Pascal
programming and gained popularity for its simplicity and size.

The programming language designed for systems programming at Bell Labs, which C
evolved from B and was influenced by ALGOL 68.

Question No. 3: Marks: 5

Suppose you as a programming student going to learn how to use the “if statement” in 2 different
programming languages like C and Ada.

Let’s first consider the following C “if statement”.

if (some condition)
//
Now consider the “if statement” in Ada programming language.

if (some condition) then


-- do this
end if
-- now do this
Now by keeping an eye on the above codes, answer the following question:
How does the "if statement" differ between C and Ada? Justify your answer with valid
reason.
Answer:
When we compare the syntax, structure, and block format of the “if statement” in C and
Ada.
Syntax:
C : In C, the “if statement” is terminated by a semicolon after the condition.
Ada : In Ada, the “if statement” is terminated by the keywords end if followed by a semicolon.
Structure:
C : In C, there is no explicit indication of the end of the “if statement”. It consists of a single line
or a block of code executed if the condition is true.
Ada : In Ada, the “if statement” is enclosed between the if and end if keywords, providing clear
demarcation of the statement’s beginning and end.
Block:
Ada: In Ada, the body of the “if statement” is structured as a block with a clear beginning and
end. This promotes readability and maintainability by clearly delineating the scope of the conditional
code.

You might also like