19/06/2024

Weekly 1 Assignments

1. Branching

Input a year N (0 < N < 2999), output ‘Leap year’ if year N is a leap year, output ‘Not leap year’ if year N is not a leap year;  Note that year N is a leap year if N is divisible by 4 AND N is not divisible by 100; However year N is always a leap year if N is divisible by 400; 

2. Looping

Input an integer N and an integer M (0 < N, M < 20), output a N by M parallelogram.  Example, N = 5, M = 4, output is

 
   *****
  *****
 *****
*****

 

Extension 1: 

Output both the original parallelogram and its mirror image.


Extension 2: 

Use ‘*’ and ‘+’ for alternating rows.

3. String operation

Input a string Name, a string Action, an integer Time.  Compose a sentence saying some is going to something at some time.  Example: Name = “George”, Action = “Sleep”, Time = 22, Output: George is going to Sleep at 22 o’clock.
 

Extension 1: 

Name can contain multiple words separated by ‘and’, in that case you’ll need to use ‘are’ instead of ‘is’.


Extension 2: 

Time can be in the past.  In that case you’ll need to use ‘was going to’ instead of ‘is going to’.  Not they may need to be adapted to plural forms as well.

No comments: