The More I Help Others To Succeed, The More I Succeed

CS508 Assignment Solution # 2nd Fall 2021

Assignments 82
CS508 Assignment Solution # 2nd Fall 2021

CS508 Assignment Solution # 2nd Fall 2021

CS508 Assignment Solution # 2nd Fall 2021

Please read the following instructions carefully before solving & submitting assignment:

Uploading Instructions:

  • You can use a simple Notepad or any other text editor (like Sublime Text, Atom, VS Code etc.) for coding.
  • For compilation purpose, any online compiler can be consulted, like https://tio.run/#snobol4
  • Make sure to write your own VU Student ID at top.
  • After completion, copy all the code; it must be a simple text, which should not contain any format or style.
  • Paste it in text view at Student Inline Solution interface and click on save button.
  • You can update your solution any time but before the deadline.
  • Unlike assignment # 1, you do not need to upload any file at VU-LMS; provide the solution of assignment directly at VU-LMS.
  • After submit, make sure the submitted code is properly visible and in readable form.
  • No assignment will be accepted through email.

Rules for Marking:

It should be clear that your assignment will not get any credit if:

  • The assignment is submitted after due date.
  • The assignment is not submitted in proper format (i.e., simple text, without any format/style).
  • The assignment is fully or partially copied from other student or ditto copy from handouts or Internet; strict disciplinary action will be taken in this case.
  • The submission contains Student Id other than yours; Zero Marks will be awarded.
  • The submitted code is not readable; during evaluation, submitted code will be checked using simple text editor. If code is not readable due to wrong format or style then ZERO marks will be awarded and no excuse will be accepted in this regard.

Lectures Covered: This assignment covers lectures # 9 to 15.

GOOD LUCK

Problem Statement:

You are required to write a program in SNOBOL4 which will take input from user, store in an array and then print elements of the array in reverse order; the last element should be displayed first, followed by second last element and so on.  

  • At start, write your own VU Student ID using SNOBOL comments.
  • Take a string as input from user.
  • Check input’s length using SNOBOL4 built-in functions as given below; less than 1 or more than 50 characters is an invalid length.
  • Define an array of size 50 and initialize with hyphen “-“.
  • Design a pattern, which should contain alphanumeric characters only (i.e., A to Z, a to z and 0 to 9).
  • Create a loop using ‘Go to field’, which will match characters of input with pattern:
    • If any character is matched then store it in array.
    • Also store that character in a separate variable using concatenation feature.
    • If not matched, then ignore it.
    • Move to the next character.
  • Now create two more loops using ‘Go to field’:
    • First loop will take all elements (except hyphen “-“) from array in original order and store them in a separate variable using concatenation feature.
    • Second loop will also take all elements (except hyphen “-“) from array, but in reverse order, and store them in a separate variable using concatenation feature.
  • At end, simply print all the characters stored in three different variables on console with appropriate message.

For example, if input string is

A quick brown fox jumps over the lazy dog.

Then your program must print on console,

Valid Characters: Aquickbrownfoxjumpsoverthelazydog

Original Order: A, q, u, i, c, k, b, r, o, w, n, f, o, x, j, u, m, p, s, o, v, e, r, t, h, e, l, a, z, y, d, o, g,

Reverse Order: g, o, d, y, z, a, l, e, h, t, r, e, v, o, s, p, m, u, j, x, o, f, n, w, o, r, b, k, c, i, u, q, A,

However, in case, if input length is smaller than 1 or greater than 50 then following message should be displayed.

Invalid: input should contain 1 to 50 characters.

Note:

It is required to make sure that the program should consider both small and capital alphabets (i.e., a to z & A to Z) and numbers (i.e., 0 to 9) as valid characters. Spaces and punctuation marks (! . , ; : ? etc.) must be ignored. For example, the output of program for following string should be;

Input:

“Help!” she cried. “I can’t swim!”

Output:

Valid Characters: HelpshecriedIcantswim

Original Order: H, e, l, p, s, h, e, c, r, i, e, d, I, c, a, n, t, s, w, i, m,

Reverse Order: m, i, w, s, t, n, a, c, I, d, e, i, r, c, e, h, s, p, l, e, H,

Compiler:

For compilation purpose, you can consult any online compiler, like

Valid Characters:

TypeCharacters
Numbers0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Small Alphabetsa, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
Capital AlphabetsA, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z

SNOBOL4 Built-in Functions:

FunctionDescription
SIZE(S)Return the number of characters in string S.
GT(X, Y)        Integer X is greater than integer Y.
GE(X, Y)Integer X is greater than or equal to integer Y.
LT(X, Y)        Integer X is less than integer Y.
LE(X, Y)        Integer X is less than or equal to integer Y.

Sample Output:

CS508 Assignment Solution # 2nd Fall 2021

CS508 Assignment Solution # 2nd Fall 2021

*(BCXXXXXXXXX)
STRING = INPUT

MSG = STRING 
COUNT = SIZE(MSG)   
CHAR_ARRAY = DUPL('-',50 - SIZE(50))
VALID_ARRAY = ''
ORIGNAL_ORDER = ''
REVERSE_ORDER = ''  

 PATTERN = ('0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' | 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z') $ A
 HYPHEN = ('-') $ H

LT(COUNT,1) :S(E2) F(E1)

E1 GT(COUNT,50) :S(E2) F(P1)
E2 MSG = ‘Invalid characters’ :(S3)

P1 STRING PATTERN = :S(P2) F(P3)
P2 CHAR_ARRAY = CHAR_ARRAY ” A :(P1)

P3 CHAR_ARRAY HYPHEN = :S(P3)F(P4)
P4 CHAR_ARRAY PATTERN = :S(V1)F(P5)
V1 VALID_ARRAY = VALID_ARRAY ” A :(O1)
O1 ORIGNAL_ORDER = ORIGNAL_ORDER A ‘, ‘ :(R1)
R1 REVERSE_ORDER = REVERSE_ORDER ‘ ,’ A :(P4)

P5 REVERSE_ORDER = REVERSE(REVERSE_ORDER) :(M1)

M1 MSG = ‘Valid Characters : ‘ VALID_ARRAY ” :(S1)
S1 OUTPUT = MSG

MSG = 'Orignal Order : ' ORIGNAL_ORDER '' :(S2)

S2 OUTPUT = MSG

MSG = 'Reverse Order : ' REVERSE_ORDER '' :(S3)

S3 OUTPUT = MSG

END

CS508 Assignment Solution # 2nd Fall 2021
CS508 Assignment Solution # 2nd Fall 2021

For More Assignment Details

CS508 Assignment Solution # 2nd Fall 2021#CS508 Assignment Solution # 2nd Fall 2021#CS508 Assignment Solution # 2nd Fall 2021#CS508 Assignment Solution # 2nd Fall 2021

#CS508 Assignment Solution # 2nd Fall 2021#CS508 Assignment Solution # 2nd Fall 2021#CS508 Assignment Solution # 2nd Fall 2021#CS508 Assignment Solution # 2nd Fall 2021

Leave a Reply

Your email address will not be published.

Be silent and let your success shout