Algorithm Development set 1 Exercises
1(a) Develop an algorithm on paper that prints your name on one line, your street address on a second line, and your suburb, state and postcode on the third line.
Screen Scenario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Munir Lodin 9 Huxley Crescent Endearvour Hills, VIC 3802 |
PSEUDO CODE
Clear Screen
Display “Munir Lodin”
Display 1 new line
Display “9 Huxley Crescent”
Display 1 new line
Display “Endeavour Hills Vic 3802”
Display 1 new line
PERL CODE
#!c:\perl\bin\perl
#Developed by Munir Lodin on 18/02/08
#adset_1.pl
system(“cls”);
print(“Munir Lodin”);
print(“\n”);
print(“9 Huxley Crescent”);
print(“\n”);
print(“Endeavour Hills, Vic 3802”);
print(“\n”);
2(a) Develop an algorithm on paper to display the following verse in the exact
Format shown below:
Computers, computers everywhere
As far as I can see
I really really like these things
Oh why don’t they like me?
Screen Scenario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Computers, computers everywhere As far as I can see I really really like these things Oh why don’t they like me?
|
PSEUDO CODE
Clear screen
Display “Computers, computers everywhere”
Display 1 new line
Display 3 spaces
Display “as far as I can see”
Display 1 new line
Display I really really like these things
Display I new line
Display 3 spaces
Display “oh why don’t they like me?
Display 1 new line
PERL CODE
#!c:\perl\bin\perl
#adset1_2.pl
system("cls");
print("Computers, computers everywhere");
print("\n");
print(" ");
print("as far as i can see");
print("\n");
print("I really really like there things");
print("\n");
print(" ");
print("oh why don't they like me?");
print("\n");
3(a) Develop an algorithm on a paper to display the following in the exact format shown:
Part no. Price
T1267 $6.34
T1300 $8.92
T2401 $65.40
T4482 $36.99
Screen Scenario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Part no. Price T1267 $6.34 |
PSEUDO Code
Clear screen
Display 1 new line
Display “part no.”
Display 5 spaces
Display “price”
Display 2 new lines
Display “T1267”
Display 8 spaces
Display “$6.34”
Display 1 new line
Display “T1300”
Display 8 spaces
Display “$8.92”
Display 1 new line
Display “T2401”
Display 8 spaces
Display “$65.40”
Display 1 new line
display “T4482”
Display 8 spaces
Display “$36.99”
Display 1 new line
Perl Code
#!c:\perl\bin\perl
#Developed by Munir Lodin on 18/02/08
#adset1_3.pl
system("cls");
print("\n");
print("Part No.");
print(" ");
print("Price");
print("\n\n");
print("T1267");
print(" ");
print("\$6.34");
print("\n");
print("T1300");
print(" ");
print("\$8.92");
print("\n");
print("T2401");
print(" ");
print("\$65.40");
print("\n");
print("T4482");
print(" ");
print("\$36.99");
print("\n");
(b) Translate your algorithm from 3(a) into a perl program called adset1_3.pl. Ensure it executes successfully and generates the correct output
4. Predict the output of each of the following perl programs on paper screens, then key the programs in and execute each to check your answers:
(a)
#!c:\perl\bin\perl
#adset1_4a.pl
#
system(“cls”);
print(“Hello there\n”);
print(“finished.”);
Screen Scenario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Hello there Finished. |
(b)
#!c:\perl\bin\perl
#adset1_4b.pl
#
system(“cls”);
print(“Hello there\n”);
print(“\n”);
print(“Finished.”);
Screen Scenario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Hello there Finished. |
(c)
#!c:\perl\bin\perl
#adset1_4c.pl
#
system(“cls”);
print(“\nHello there”);
print(“Finished.”);
Screen Scenario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Hello thereFinished. |
(d)
#!c:\perl\bin\perl
#adset1_4d.pl
#
system(“cls”);
print(“Hello there\n\n”);
print(“Finished.”);
Screen Scenario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Hello there Finished. |
(e)
#!c:\perl\bin\perl
#adset1_4e.pl
system(“cls”);
print( “Hello there” );
print( “Finished.” );
Screen Scenario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Hello there Finished. |
5. Develop an algorithm on paper that meets the following requirements:
Display the words Hello and there on the screen, but with three spaces preceding the H in the word Hello. There should also be three spaces between hello and there.
Leave three blanks lines, then display the word Finished with three spaces preceding the F.
Screen Scenario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Hello there
Finished. |
PSEUDO Code
Clear screen
Display 3 spaces
Display “Hello”
Display 3 spaces
Display “there”
Display 3 new lines
Display 3 spaces
Display “Finished.”
Perl code
#!c:\perl\bin\perl
# Developed by Munir Lodin on 18/02/08
# adset1_5.pl
system("cls");
print(" Hello");
print(" there");
print("\n\n\n");
print(" Finished.");