CSE221 LabAssignment01 solved

$30.00

Original Work ?

Download Details:

  • Name: Assignment-01-txnl1o.zip
  • Type: zip
  • Size: 1.43 MB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (5 votes)

[1] File I/O: [10 marks]
Parity: A number has even parity if it’s an even number, and odd parity if it’s an odd
number.
Palindrome: A palindrome is a sequence of characters which reads the same
backward as forward, such as “madam”, “racecar” or “bob”.
Given pairs of a number and a string, check the parity of the number and whether the
string is a palindrome or not. In case of float/ decimal, indicate that it cannot have parity.
In a text file, some pairs will be given in separate lines. Read the words from a text
(input.txt) file, do the above mentioned operations, and save the outputs in another text
(output.txt) file using File I/O operations. Finally, in a text file named “records.txt”, write
the percentage of odd, even and no parity, and percentage of palindromes and
non-palindromes. Ideally you should store the inputs from the text file into a data
structure (e.g. array, list etc. ). You can either:
● pass the array as an argument to the isPalindrome function and return the
output array, OR,
● you can check the words one by one using a loop and return true/false
Sample input (inside input.txt file): [Download input text file from here]
1 madam
2 apple
3.6 racecar
89 parrot
45.2 discord
Sample output (inside output.txt file):
1 has odd parity and madam is a palindrome
2 has even parity and apple is not a palindrome
3.6 cannot have parity and racecar is a palindrome
89 has odd parity and parrot is not a palindrome
45.2 cannot have parity and discord is not a palindrome
Sample output (inside record.txt file):
Percentage of odd parity: 40%
Percentage of even parity: 20%
Percentage of no parity: 40%
Percentage of palindrome: 40%
Percentage of non-palindrome: 60%
Pseudocode for isPalindrome function:
Word <- input IF word=null/empty THEN Return not palindrome N<- length of word For i