Turbo Pascal Help

I am a student taking a class in Turbo Pascal (the 5th Ed. book).
I'm terrible at programming and missed the last class. I haven't
been able to find anyone that could help me understand the last work
we were given . I was hoping someone might be able
to explain this to me. I won't receive a grade in this until I complete
all my work and I don't seem to be able to get past this.

self-check pg. 439 #1: (on arrays) Turbo Pascal
The following sequence of statements changes the contents of array X.
Describe what each statement does to the array, and show the final
contents of array X after all statements execute.

X = array
I = index range

I :=3;
X[I] := X[I] + 10.0;
X[I - 1] := X[2 * 1 - 1];
X[I + 1] := X[2 * 1] + X[2 * I + 1);
for I :=3 downto 1 do
X[I + 1] := X[I]

I would appreciate any help I can get with this.
Serina

Comments

  • : I am a student taking a class in Turbo Pascal (the 5th Ed. book).
    : I'm terrible at programming and missed the last class. I haven't
    : been able to find anyone that could help me understand the last work
    : we were given . I was hoping someone might be able
    : to explain this to me. I won't receive a grade in this until I complete
    : all my work and I don't seem to be able to get past this.
    :
    : self-check pg. 439 #1: (on arrays) Turbo Pascal
    : The following sequence of statements changes the contents of array X.
    : Describe what each statement does to the array, and show the final
    : contents of array X after all statements execute.
    :
    : X = array
    : I = index range
    :
    : I :=3;
    : X[I] := X[I] + 10.0;
    : X[I - 1] := X[2 * 1 - 1];
    : X[I + 1] := X[2 * 1] + X[2 * I + 1);
    : for I :=3 downto 1 do
    : X[I + 1] := X[I]
    :
    : I would appreciate any help I can get with this.
    : Serina

    Hey Serina,

    First off, you need to understand what an array is. Think of it like a row of boxes on graph paper. In this case, we'll use 10 boxes in a row and number them from 1..10 You can change put tick marks in any one box, but it will only effect the one.

    For the example above:
    I :=3;

    so just change all the 'I' to '3'. The second line then becomes:
    X[3] := X[3] + 10.0;

    So box #3 gets 10.0 ticks added to it.

    X[3 - 1] := X[2 * 1 - 1];

    So box #2 (3-1) will get the same number of ticks that are in box #1 (2*1-1). So if Box[1] (Box #1) has 6 tick marks, then you would make it so box[2] has 6 tick marks as well.

    Hope this helps a bit. Monday mornings are not a good time to catch me...

    Phat Nat

  • : : I am a student taking a class in Turbo Pascal (the 5th Ed. book).
    : : I'm terrible at programming and missed the last class. I haven't
    : : been able to find anyone that could help me understand the last work
    : : we were given . I was hoping someone might be able
    : : to explain this to me. I won't receive a grade in this until I complete
    : : all my work and I don't seem to be able to get past this.
    : :
    : : self-check pg. 439 #1: (on arrays) Turbo Pascal
    : : The following sequence of statements changes the contents of array X.
    : : Describe what each statement does to the array, and show the final
    : : contents of array X after all statements execute.
    : :
    : : X = array
    : : I = index range
    : :
    : : I :=3;
    : : X[I] := X[I] + 10.0;
    : : X[I - 1] := X[2 * 1 - 1];
    : : X[I + 1] := X[2 * 1] + X[2 * I + 1);
    : : for I :=3 downto 1 do
    : : X[I + 1] := X[I]
    : :
    : : I would appreciate any help I can get with this.
    : : Serina
    :
    :
    : Thanx Nat,
    I appreciate your time. I think I understand it better.
    Is this right?
    1. I :=3; {index = 3}

    2. X[3] := X[3] +10; {stores value of 10 in index 3}

    3. X[3 - 1] := X[2 * 3 - 1]; {stores same value in index [2] as in index[5]}

    4. X[3 + 1] := X[2 * 3] + X[2 * 3 + 1]; {index 4 = sum of index 6 and index 7}

    5. for I := 5 to 7 do {initilizes I to 5}

    6. X[I] := X[I + 1]; {adds 1 to I}
    {index 5 := 5 + 1}
    {index 6 := 6 + 1}
    {index 7 := 7 +1}

    7. for I := 3 down to 1 do {initializes I to 3}

    8. X[3 + 1] := X[3] {adds 1 to I}
    {X[2 + 1] := X[2]}
    {X[1 + 1] := X[1]}

    Does this look ok or am I still way off?
    Thanx,
    Serina


  • : : : I am a student taking a class in Turbo Pascal (the 5th Ed. book).
    : : : I'm terrible at programming and missed the last class. I haven't
    : : : been able to find anyone that could help me understand the last work
    : : : we were given . I was hoping someone might be able
    : : : to explain this to me. I won't receive a grade in this until I complete
    : : : all my work and I don't seem to be able to get past this.
    : : :
    : : : self-check pg. 439 #1: (on arrays) Turbo Pascal
    : : : The following sequence of statements changes the contents of array X.
    : : : Describe what each statement does to the array, and show the final
    : : : contents of array X after all statements execute.
    : : :
    : : : X = array
    : : : I = index range
    : : :
    : : : I :=3;
    : : : X[I] := X[I] + 10.0;
    : : : X[I - 1] := X[2 * 1 - 1];
    : : : X[I + 1] := X[2 * 1] + X[2 * I + 1);
    : : : for I :=3 downto 1 do
    : : : X[I + 1] := X[I]
    : : :
    : : : I would appreciate any help I can get with this.
    : : : Serina
    : :
    : :
    : : Thanx Nat,
    : I appreciate your time. I think I understand it better.
    : Is this right?
    : 1. I :=3; {index = 3}
    :
    : 2. X[3] := X[3] +10; {stores value of 10 in index 3}
    :
    : 3. X[3 - 1] := X[2 * 3 - 1]; {stores same value in index [2] as in index[5]}
    :
    : 4. X[3 + 1] := X[2 * 3] + X[2 * 3 + 1]; {index 4 = sum of index 6 and index 7}
    :
    : 5. for I := 5 to 7 do {initilizes I to 5}
    :
    : 6. X[I] := X[I + 1]; {adds 1 to I}
    : {index 5 := 5 + 1}
    : {index 6 := 6 + 1}
    : {index 7 := 7 +1}
    :
    : 7. for I := 3 down to 1 do {initializes I to 3}
    :
    : 8. X[3 + 1] := X[3] {adds 1 to I}
    : {X[2 + 1] := X[2]}
    : {X[1 + 1] := X[1]}
    :
    : Does this look ok or am I still way off?
    : Thanx,
    : Serina
    :
    A number of your explanations is still a little off. These are 2 and 5 thru 8. 5 & 6 are actually 2 parts of the same statement:
    [code]
    for I := 5 to 7 do
    X[I] := X[I + 1]; { <== statement ends here }
    [/code]
    Just remember that Pascal uses a semicolon as statement separator. The for-do loop does a little more than initializing I to 5. It also checks if I <= 7 and increments I with each step. The same goes for 7 & 8.
  • : Thanx Nat,
    : I appreciate your time. I think I understand it better.
    : Is this right?
    : 1. I :=3; {index = 3}
    :
    : 2. X[3] := X[3] +10; {stores value of 10 in index 3}
    :
    : 3. X[3 - 1] := X[2 * 3 - 1]; {stores same value in index [2] as in index[5]}
    :
    : 4. X[3 + 1] := X[2 * 3] + X[2 * 3 + 1]; {index 4 = sum of index 6 and index 7}
    :
    : 5. for I := 5 to 7 do {initilizes I to 5}
    :
    : 6. X[I] := X[I + 1]; {adds 1 to I}
    : {index 5 := 5 + 1}
    : {index 6 := 6 + 1}
    : {index 7 := 7 +1}
    :
    : 7. for I := 3 down to 1 do {initializes I to 3}
    :
    : 8. X[3 + 1] := X[3] {adds 1 to I}
    : {X[2 + 1] := X[2]}
    : {X[1 + 1] := X[1]}
    :
    : Does this look ok or am I still way off?
    : Thanx,
    : Serina

    Pretty close. There are just a few that are a little off:

    X = array
    I = index range

    1. I :=3;
    1. I :=3; {index = 3}

    2. X[I] := X[I] + 10.0;
    [b]2. X[3] := X[3] +10; {stores value of 10 in index 3}[/b]
    [italic]This actually adds 10 to the existing value. If X[3] was set to 5, then this would make it 15[/italic]

    3. X[I-1] := X[2*I-1];
    3. X[3-1] := X[2*3-1]; {stores same value in index [2] as in index[5]}

    4. X[3+1] := X[2*3] + X[2*3+1]; {index 4 = sum of index 6 and index 7}

    5. for I := 5 to 7 do {initilizes I to 5}
    [b]this is a loop; usually used with BEGIN and END. This will set I=5, then add one until I=7. Example:[/b]
    [code]
    For I := 5 to 7 Do
    Begin
    WriteLn(I);
    End;
    [/code]
    [b]If you ran this, You would see:[/b]
    [code]5
    6
    7[/code]

    6. X[I] := X[I + 1]; {adds 1 to I}
    {index 5 := 5 + 1}
    {index 6 := 6 + 1}
    {index 7 := 7 + 1}
    [b]
    {index 5 := index 6 (5 + 1)}
    {index 6 := index 7 (6 + 1)}
    {index 7 := index 8 (7 + 1)}
    [/b]

    7. for I :=3 downto 1 do
    X[I + 1] := X[I]

    7. For I := 3 down to 1 do {initializes I to 3}
    X[3 + 1] := X[3] {adds 1 to I}
    {X[2 + 1] := X[2]}
    {X[1 + 1] := X[1]}
    [b]For I := 3 down to 1 do {initializes I to 3}
    X[3 + 1] := X[3] {index 4 (3+1) = index[3]}
    {X[2 + 1] := X[2]}
    {X[1 + 1] := X[1]}
    [/b][italic]When DOWNTO is used in place of TO, I counts down, instead of up[/italic]

    Hope this clears up any problems. If you need more help, just leave a message.

    Phat Nat

  • : A number of your explanations is still a little off. These are 2 and 5 thru 8. 5 & 6 are actually 2 parts of the same statement:
    : [code]
    : for I := 5 to 7 do
    : X[I] := X[I + 1]; { <== statement ends here }
    : [/code]
    : Just remember that Pascal uses a semicolon as statement separator. The for-do loop does a little more than initializing I to 5. It also checks if I <= 7 and increments I with each step. The same goes for 7 & 8.


    :Thanks zibadian,
    That helped, I'm working on it.
    Serina

  • [b][red]This message was edited by sweet_serina at 2003-6-24 20:5:16[/red][/b][hr]
    :
    : Thanx Phat Nat,

    This is making more sense to me. This is what I have now:


    : X = array
    I = index range

    1. I :=3; {index = 3}
    :
    : 2. X[3] := X[3] +10; {adds value of 10 in index 3}
    :
    : 3. X[3 - 1] := X[2 * 3 - 1]; { same value in index [2] as in
    index[5]}
    :
    : 4. X[3 + 1] := X[2 * 3] + X[2 * 3 + 1];
    {index 4 = sum of index 6 and index 7}
    :
    : 5. for I := 5 to 7 do {initilizes I to 5}
    : X[I] := X[I + 1]; {checks if I is <=7 and adds 1 to I}
    : {loop}
    {index 5 := index 6 (5 + 1)}
    : {index 6 := index 7 (6 + 1)}
    : {index 7 := index 8 (7 + 1)}
    :
    : 6. for I := 3 down to 1 do {initializes I to 3}
    : X[3 + 1] := X[3] {checks if I is <= 1 and adds 1 to I}
    {loop}
    : {index [4]= index [3]}
    X[2 + 1] := X[2]
    {index [3] = index [2]}
    X[1 + 1] := X[1]
    {index [2] = index [1]}

    Am I closer? I'm supposed to show the final contents of array X after all statements execute. I just figured out that I am supposed to substitute code from one program with this code and then tell what it does. My mind doesn't even want to mess with this anymore. I have one program to finish writing and this assignment here to finish and I will earn an ass. degree in computer science, and that is what I feel like, an ass. I have until the 7th to finish but I am beginning to wonder. I think if I get a good nights sleep I'll do better tomorrow. Thanx for looking at this for me and all your help.
    Serina


  • : 6. for I := 3 down to 1 do {initializes I to 3}
    : X[3 + 1] := X[3] {checks if I is <= 1 and adds 1 to I}
    : {loop}
    : {index [4]= index [3]}
    : X[2 + 1] := X[2]
    : {index [3] = index [2]}
    : X[1 + 1] := X[1]
    : {index [2] = index [1]}
    :
    : Am I closer? I'm supposed to show the final contents of array X after all statements execute. I just figured out that I am supposed to substitute code from one program with this code and then tell what it does. My mind doesn't even want to mess with this anymore. I have one program to finish writing and this assignment here to finish and I will earn an ass. degree in computer science, and that is what I feel like, an ass. I have until the 7th to finish but I am beginning to wonder. I think if I get a good nights sleep I'll do better tomorrow. Thanx for looking at this for me and all your help.
    : Serina


    Looks good other than the part above. You got the numbers right, but the check is :
    6. for I := 3 down to 1 do {initializes I to 3}
    X[3 + 1] := X[3] {checks if [b]I is >= 1[/b] and adds 1 to I}

    because it starts at 3 and goes down until 1

    Phat Nat
  • Thanx Phat Nat,
    Now I am supposed to use numbers from another program and say what it does and what the final outcome is.
    (value of X[I] from other program)
    X[1]= 16
    X[2]= 12
    X[3]=6
    X[4]=8
    X[5]=2.5
    X[6]=12
    X[7]=14
    X[8]=-54.5
    =======================================
    I :=3;
    X[I] := X[I] + 10;
    X[I - 1] := X[2*I-1];
    X[I+1] := X[2*I] + X[2*I+1];
    for I := 5 to 7 do
    X[I] := X[I + 1];
    for I := 3 down to 1 do
    X[I + 1] := X[I]
    =========================================
    Is this right?

    I = index range
    X = array

    I := 3; {I = 3}
    X[I] := X[I] + 10; { X[3] stores 6(from other program) + 10 = 16}
    X[I - 1] := X[2*I-1]; {X[2] = X[5], X[5] = 2.5 }
    X[I+1] := X[2*I] + X[2*I+1]; {X[4] = X[6] + X[7], X[4] = X[4]=26}
    for I := 5 to 7 do {initializes I to 5 and checks if I>= 7
    X[I] := X[I + 1];and increments with each loop}
    {X[5]:= X[6], X[5] and X[6] = 12}
    {X[6] := X[7], X[6]= 14}
    {X[7] := X[8], X[7]= -54.5}

    for I := 3 down to 1 do {initializes I to 3}
    X[I + 1] := X[I]
    {X[4] := X[3], X[4]= 16}
    {X[3] := X[2], X[3]= 2.5}
    {X[2] ;= X[1], X[2]= 16}

    show final contents of array X:
    X[1] = 16
    X[2] = 16
    X[3] = 2.5
    X[4] = 16
    X[5] = 12
    X[6] = 14
    X[7] = -54.5
    X[8] = -54.5

    I think I still did it wrong. I would appreciate it if you can check this for me.
    Thanx, Serina


  • : Thanx Phat Nat,
    : Now I am supposed to use numbers from another program and say what it does and what the final outcome is.
    : (value of X[I] from other program)
    : X[1]= 16
    : X[2]= 12
    : X[3]=6
    : X[4]=8
    : X[5]=2.5
    : X[6]=12
    : X[7]=14
    : X[8]=-54.5
    : =======================================
    : I :=3;
    : X[I] := X[I] + 10;
    : X[I - 1] := X[2*I-1];
    : X[I+1] := X[2*I] + X[2*I+1];
    : for I := 5 to 7 do
    : X[I] := X[I + 1];
    : for I := 3 down to 1 do
    : X[I + 1] := X[I]
    : =========================================
    : Is this right?
    :
    : I = index range
    : X = array
    :
    : I := 3; {I = 3}
    : X[I] := X[I] + 10; { X[3] stores 6(from other program) + 10 = 16}
    : X[I - 1] := X[2*I-1]; {X[2] = X[5], X[5] = 2.5 }
    : X[I+1] := X[2*I] + X[2*I+1]; {X[4] = X[6] + X[7], X[4] = X[4]=26}
    : for I := 5 to 7 do {initializes I to 5 and checks if I>= 7
    : X[I] := X[I + 1];and increments with each loop}
    : {X[5]:= X[6], X[5] and X[6] = 12}
    : {X[6] := X[7], X[6]= 14}
    : {X[7] := X[8], X[7]= -54.5}
    :
    : for I := 3 down to 1 do {initializes I to 3}
    : X[I + 1] := X[I]
    : {X[4] := X[3], X[4]= 16}
    : {X[3] := X[2], X[3]= 2.5}
    : {X[2] ;= X[1], X[2]= 16}
    :
    : show final contents of array X:
    : X[1] = 16
    : X[2] = 16
    : X[3] = 2.5
    : X[4] = 16
    : X[5] = 12
    : X[6] = 14
    : X[7] = -54.5
    : X[8] = -54.5
    :
    : I think I still did it wrong. I would appreciate it if you can check this for me.
    : Thanx, Serina

    Looks right, but I'm in a rush so I may have counted wrong too. But you have the idea. I'll check it again later and make another post if it is wrong.
    Phat Nat



  • : Phat Nat,
    I wanted to thank you for all your help. I finished my work and turned it in on time. I couldn't have done it without understanding this last assignment. I hope alot of good things come your way. Thanks again.
    Sweet Serina
    :
    :
    :

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories