Lab2v1 ICTT 133
Lab2v1 ICTT 133
Lab2v1 ICTT 133
2. (String) Write a program that reads in a string input consisting of 2 words with
a blank in between. The program displays each of the word in reverse.
Example:
Enter string: java python
Output: avaj nohtyp
Assume input is valid.
3. (if…else) Write a program that reads in 2 integer values. Display one of the
following messages:
- “The 2 numbers are the same”
- “The 2 numbers are not the same”
4. (String, if…else) Write a program that reads a string and checks whether it is
a palindrome. It displays either the message palindrome or the message not a
palindrome. A palindrome is a word that spells the same backwards, e.g., the
word solos is a palindrome.
5. (if…else) A telco charges the following for usage of data in a foreign country:
Data Rate
Up to 2GB $5 flat
Above 2GB $5 + $1 for every 100MB or part
thereof
Run 1:
Amount of data used (GB): 1.5
Charge is $5.00
Run 2:
Amount of data used (GB): 2.54
Charge is $11.00
6. (if…elif…else) Write a program that determines whether two integers are even
or odd. Display one of the following messages:
- “The 2 numbers are even”
- “The 2 numbers are odd”
- “One number is even and the other is odd”
Write a program that inputs a NRIC number and displays whether a NRIC is
valid. Display “Valid NRIC” or, if it is invalid, one of the following error
messages:
- Length must be exactly 9
- The first letter must be S, T, F or G
- Must consist of 7 digits
- Reference letter must be A to Z or a to z
Example,
Run 1
Enter NRIC: S1234567A
Valid NRIC
Run 2
Enter NRIC: X123456789B
Length must be exactly 9
Run 3
Enter NRIC: S12345XXB
Must consist of 7 digits
Data Rate
Up to 2GB $5 flat
Above 2GB $5 + $1 for every 100MB or part
thereof
Above 4GB $25 flat
The program also validates that input must be greater than 0. Otherwise,
display “Invalid input!”.
Run 1
Enter arithmetic expression: 23.6 + 33.2
Result: 56.8
Assume that the numeric values are valid, but the the operator may be
invalid.
10. Write a triangle checker program that reads in the 3 sides of a triangle. The
program checks whether the 3 values can form a triangle. A triangle will not
be possible if the sum of any two is less than or equal to the third. If the
values can form a triangle, print the type of triangle according to the table
below.
11. A computer store allows customers to buy laptops and pay by instalments.
The payment plan is based on the purchase amount as given in the following
table:
Amount Payment
Less than 1000 No instalment. Pay full amount.
At least 1000 Either pay in 6 monthly instalments with an addition
of 5% of the amount, or pay in 12 monthly
instalments with an addition of 10% of the amount
Write a program that reads in the amount of the laptop. If the amount is at
least 1000, prompt the user to select 0, 6 or 12 months, and displays the
instalment plan. Examples of different input are as follows:
Run 1
Enter amount: 800
Please pay $800.00. No instalment plan.
Run 2
Enter amount: 1200
Pay in 0, 6 or 12 month instalment: 0
Please pay $1200.00. No instalment plan.
Run 3
Enter amount: 2400
Pay in 0, 6 or 12 month instalment: 6
6 month instalment plan of $420.00 per month