0% found this document useful (0 votes)
17 views6 pages

VUID

Uploaded by

rubinapsr
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)
17 views6 pages

VUID

Uploaded by

rubinapsr
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/ 6

CS508 – Modern Programming Languages

Total Marks: 15
Assignment No. 01
Due Date: 29-April-
Semester: Spring 2024 2024
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:

Answer:

In the provided snippets, we have:

Integers: In C, an integer is represented as int, while in Ada, it can be represented as Integer.


Both support unsigned integers with unsigned int in C and Positive in Ada.

Floats: In C, a floating-point number is represented as float, while in Ada, it can be represented


as Float. Both support doubles with double in C and Long_Float in Ada.

Booleans: C uses _Bool or bool (with a library) and Ada uses Boolean.

Characters: C uses char, while Ada uses Character.

Arrays: Both support arrays, but Ada has more built-in array handling features, such as bounds
checking and the ability to declare multi-dimensional arrays without using pointers.

Strings: C uses null-terminated character arrays (char[] or char*), while Ada uses the String
type, which is a manageable array type with a fixed length.

Pointers: C supports pointers, which are not directly available in Ada. Ada uses access types for
similar functionality, but with more safety features.
Here is the table for clearly understand:

Category C Type Ada Type


Integers int Integer
Unsigned unsigned int Positive
Floats float Float
Doubles double Long_Float
Booleans _Bool or bool Boolean
Characters char Character
Arrays type[] or type* type
Strings char[] or char* String
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.

Appropriate
Statement
Language

The programming language was designed primarily for hardware description. APL

The programming language known for its powerful operators for string pattern
SNOBOL
matching but suffered from poor readability and maintainability.

The first programming language introduced the concept of a class, which served as
Simula 67
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 - 1972
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:

Differences between "if statement" in C and Ada

The "if statement" in C and Ada programming languages differ in the following ways:

Syntax

C: The "if statement" in C uses curly braces {} to enclose the code block that should be executed
if the condition is true.

Ada: The "if statement" in Ada uses the then keyword to indicate the start of the code block, and
the end if keywords to indicate the end of the code block.

Termination

C: In C, the "if statement" is terminated by the closing curly brace }.

Ada: In Ada, the "if statement" is terminated by the end if keywords.

Readability

C: The C "if statement" syntax can be more concise, but may be less readable, especially for
complex conditions or nested "if statements".
Ada: The Ada "if statement" syntax is more verbose, but can be more readable and easier to
understand, especially for complex conditions or nested "if statements".

Flexibility

C: The C "if statement" allows for more flexibility in terms of the code block that is executed, as
it can include multiple lines of code or even other control structures like loops.

Ada: The Ada "if statement" is more structured, with the then and end if keywords clearly
delineating the code block that should be executed.

Indentation

C: In C, the code block within the "if statement" is typically indented to improve readability, but
this is not required by the language syntax.

Ada: In Ada, the code block within the "if statement" is typically indented to improve
readability, and this is considered a best practice in the language.

You might also like