Lab 9 – 2017

Slides: [ EST ] [ ENG ]

Task 1 (2p)

Create a program, which will create and populate 2d array with values.

  1. Ask for number of rows
  2. Ask for number of columns
  3. Create array and initialize with 0’s  (0.25p)
  4. Use switch to select method (0.5p)
  5. Populate array with values
    1. Using input (scanf or other prefered function) (0.5p)
    2. Using random number generator (rand) (0.5p)

Display the array (0.25p)

Task 2 (1p)

Calculate day of the week

  • One of the tasks is to determine the day of the week when given the date.
  • The task in class is to create a program for the following task:
    • User inserts the date as three numbers – day of month, month, year;
    • The program calculates the number of day;
    • Outputs the name of date(Monday, tuesday, etc..).
      • Hint, use the switch statement.

The “mod” operator is used to get the remainder of the number so that is in range 0-6. Refer to google or previous lab slides for info.

Calculating day of week [ Link ]

Task 3 (2p)

Gregorian calendar verifier

Write a program, which takes into consideration the Gregorius calendar rules and returns if the program is an actual date or not.

  • A year is leap year if it is divisible by 4
  • For the Gregorian calendar, years that are multiple by 100, are leap years only then if they are also dividable by 400
      • 1600 and 2000 are leap years;
      • 1700 and 1800 are not.
  • User inserts the date a number formatted as “DDMMYYYY”.
    • Hint: you can use mathematics to extract different parts of the date(day, month, year) because it is a number.
  • Return text, which indicates whether the date is valid or not.