Docsity

Ada95 Code: Creating Char and Int Queues, Modifying Circular Queue Enqueue, Proving Sum of, Exercises of Aeronautical Engineering

Toggle sidebar
bg1
________________________________
2
Part b. Can you create two instances of the package i.e. a character queues and integer
queues yes or no)
No
Part c.
(i) If yes in part b, Define the Ada95 instantiation for a character queue and an
This gets six points even if Parts a, b were wrong.
Character Queue
package Queue_Char is new Queue(
Size => 5,
Item => Character);
Integer Queue
package Queue_Int is new Queue(
Size => 5,
Item => Integer);
(ii) If no
4. type Table (Positive range <>) of Integer;
Has to be changed to:
4. type Table (Positive range <>) of Item;
________________________________
3
Part d.
Modify the Enqueue procedure for a circular queue. Include exception handlers to
handle overflow.
procedure Enqueue (
Element : in Item ) is
begin
if Tail+1 = Head then
raise Overflow;
end if;
Space(Tail) := Element;
Tail:= Tail+ 1;-- moves tail to the next location
if then -- make the tail
-- point to first location
1;
;
exception
when Overflow =>
Put_Line("Circular Queue is full");
end Enqueue;
Name:
from the code shown above. (Answer with one word: (3 points)
(6 points)
integer queue.
in part b, Which line(s) in the specification or body do you have to change?
List the line number and modification to be made.
is array
is array
Name:
(16 points)
Hint: How do you check if the queue is full or empty?
Tail = Size
Tail :=
end if
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Ada95 Code: Creating Char and Int Queues, Modifying Circular Queue Enqueue, Proving Sum of and more Exercises Aeronautical Engineering in PDF only on Docsity!

________________________________

Part b

. Can you create two instances of the package i.e. a

character queues

and

integer

queues

yes

(^) or

no

)

Part c No

(i)

If

yes

in part b, Define the Ada95 instantiation for a character queue and an

package Character Queue This gets six points even if Parts a, b were wrong.

Queue_Char

is new

Queue(

Item => Character);Size => 5,

package Integer Queue

Queue_Int

is new

Queue(

Item => Integer);Size => 5,

(ii)

If

no

type

Table

(Positive

range

<>)

of

Integer;

Has to be changed to:

type

Table

(Positive

range

<>)

of

Item;

________________________________

Part d

Modify the Enqueue procedure for a

circular

queue. Include exception handlers to

procedurehandle overflow.

Enqueue (

Element : in

Item )

is

begin

if Tail+1 = Head

then

raise Overflow;

ifTail:= Tail+ 1;-- moves tail to the next locationSpace(Tail) := Element;end if;

then -- make the tail

-- point to first location

exception

when Overflow =>

Put_Line("Circular Queue is full");

end Enqueue;

Name:

from the code shown above. (Answer with one word:

(6 points) (3 points)

integer queue.

in part b, Which line(s) in the specification or body do you have to change?

List the line number and modification to be made.

is array is array

Name:

(16 points)

Hint: How do you check if the queue is full or empty?

Tail := Tail = Size

end if

docsity.co

Name: ________________________________

Name: ________________________________

Problem 2 – Induction Proof

(5 points)

Problem 3 – Variant record

(10 points)

Prove using induction that the sum of the first

n positive integers is

(^) n(n+1)/*

Fighters and BombersDefine a variant record to holds aircraft information for two different types of aircraft:

1 + 2 + 3 + .. + n = n*(n+1)/

Both kinds of Aircraft have three common fields:

ID

is of type

integer

Call_Sign

is a

string

of maximum 20 characters

Aircraft_Type

is an

enumerated

type with values ‘fighter’ and ‘bomber’

In addition to the three common fields, Fighter Aircraft have fields:

Base Case

Aircraft_Mach

is a

record

(^) with fields

Top_Mach

of type

float

When n = 1,

Cruise_Mach

of type

float

Max_Range

is of type

integer

n*(n+1)/

In addition to the three common fields, Bomber Aircraft have fields:

Crew_Size

(^) of type

positive

Payload

of type

integer

Induction Hypothesis

: Let the theorem be true for j= n.

type Aircraft_Type

is(Fighter,Bomber);

type Fighter_Mach

is record

Inductive Step:

Cruise_Mach : Float;Top_Mach : Float;

When j = n+1, then

end record;

Sum

1 + 2 + 3 + .. + n + (n+1)

type Aircraft_Record(Kind: Aircraft_Type)

is

record

n*(n+1)/2 + (n+1)

[By Induction Hypothesis]

Type : Aircraft_Type; Call_Sign: String(ID : Integer;

((n

2 +n)+ (2n+2))/

[Arithmetic]

(n 2 +3n+2)/

[Arithmetic]

case

Kind is

when Fighter =>

(n+1)*(n+2)/

[Arithmetic]

Aircraft_Mach : Fighter_Mach; Max_Range : integer;

By theorem

Sum

(n+1)*(n+2)/

when Bomber=>

Crew_Size: Positive; Payload : integer;

Hence

end record

end case

For all n

1, the sum of the first

n positive integers is

n(n+1)/*

docsity.co

________________________________

Part a. What is a fully connected graph?

(3 points)

A fully connected graph withA fully connected graph is a graph in which every node is connected to every other node.

n nodes is denoted by

K

n .

nodes is

n*(n-1).

Base Case

n*(n-1)

Inductive Step: Induction Hypothesis

th

2*n.nodes of the fully connected graph, and hence has degree n. The n nodes of the Kn graph

n 2 +n

[

(n+1)*n

[

By theorem

n*(n+1)

∀ Hence n ≥

n (^) nodes=

n(n-1)*

________________________________

Part a

T

(P

R)

, given the following hypothesis 1 and 2:

(2 points)

R

S

S

¬(P

R)

[

T

¬(P

R)

[2,3 Transitivity of ->]

Part b

. Translate the following four sentences of English into the language of predicate

logic.

E(x)

represents x is even, and

O(x)

represents x is odd.

(8 points)

Even(2)2 is even

∃ Not every integer is even x ¬Even(x)

x ∃ y (Even(x) and ¬Even(y))

¬Even(x)If an integer is not even, then it is odd

Odd(x)

Name:

Problem 5 – Proof

(10 points)

Part b.

(7 Points)

When n = 1, the graph has one node and no edges, so the degree is zero.Prove that the sum of the degrees of all nodes in a fully connected graph of n

: Let the theorem be true for a graph with n nodes.

When the graph has n+1 nodes, the (n+1)

node has to be connected to the remaining n

have their degree increased by 1. Hence the total increase to the sum of the degrees is

n(n-1) + 2n

[By Induction Hypothesis] Arithmetic]Arithmetic]

Sum of all the degrees of the nodes of a fully connected graph with n+1 nodes is

1, the sum of the degrees of a fully connected graph with

Name:

Problem 6 – Logic

(10 points)

. Formally prove

2. T 1. P

3. ¬S

contrapositive of 1]

Some integers are even and some are odd

docsity.co

________________________________

Part a

. Convert the following POS (Product of Sum) expression into SOP

( Hint: Think about negation.

C

B

A

C

B

A

C

B

A

C

B

A

( Negating the expression above,

C

B

A

C

B

A

C

B

A

C

B

A

C

B

A

C

B

A

C

B

A

C

B

A

Part b

C

B

C

B

C

B

C

B

A A

C

B

C

A

Part c.

C

B

C

B

C

B

C

B

D

A

D

A

D

A

D

A

________________________________

and

next to each question.

Answer

a.

Java

b.

C

c.

Cobol

d.

Ada

which four?

d.c.b.a.

cyclomatic complexity

b. a.

lower

c.

itself/be executed.

C

C

A

Name:

Problem 7

(15 points)

(Sum of Product) form.

(5 points)

These are the 0’s, from the crib sheet, the 1’s can be found.

. Simplify the SOP expression derived above using K-Maps (5 points)

Simplified Expression is

What are the minterms that go into a four-variable K-Map (5 points)

Name:

Problem 8 – Multiple choice

(10 points)

Multiple Choice Questions. For each question, select the correct answer from the choices,

write the chosen letter in the box provided

  1. Heidi Perry explained four commonly used Software Life Cycles,programming languages in the world?which of the following languages is the other of the top 2 most usedstill is one of the two most commonly used programming languages, 1. Prof. Dewar mentioned during his guest lecture that “Visual Basic”

The Niagara, Incremental, Revolutionary, and Spiral modelsThe Waterfall, Incremental, Evolutionary, and Spiral modelsThe Niagara, Incremental, Evolutionary, and Spiral modelsThe Waterfall, Incremental, Acquisition, and Spiral models

  1. What is “

describes the asymptoticA theoretical measure used in complexity theory, thatall statements and conditions in a program at least onceNumber of independent paths needed to execute

bound of a function in terms

A measure of the number of times a recursive function will recursively callof another, usually simpler, function

docsity.co