VUID
VUID
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:
Booleans: C uses _Bool or bool (with a library) and Ada uses Boolean.
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:
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 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.
if (some condition)
//
Now consider the “if statement” in Ada programming language.
Answer:
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
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.