66. Hardware Timer Default Constructor

Create a class HardwareTimer that represents a simple MCU hardware timer.
The default constructor must initialize all internal values to safe, reset-like defaults.

Your class must include:

  • Private members
    • int frequency
    • bool enabled
    • int prescaler
  • Constructor behavior
    • The default constructor must set:
      • frequency = 0
      • enabled = false
      • prescaler = 1
    • These values represent a safe reset state:
    • Timer disabled
    • Prescaler at minimum valid value
    • No active frequency
  • Public methods
    • void configure(int freq, int pre)
      • Sets frequency = freq
      • Sets prescaler = pre
      • Enables the timer
    • void stop()
      • Disables the timer
    • void print()
      • Prints the timer state in the format:
      • F=<frequency> P=<prescaler> EN=<0 or 1>

In main()

  1. Create a HardwareTimer object using the default constructor
  2. Read integers f and p
  3. Call configure(f, p)
  4. Read integer flag x
    • If x == 0, call stop()
  5. Print the final timer state using print()

 

Example 1

Input:

1000 8
1 

Output:

F=1000 P=8 EN=1 

 

Example 2 

Input:

500 4
0

Output:

F=500 P=4 EN=0 

 

Constraints

  • The default constructor must be correctly implemented
  • All internal values must match the required defaults
  • Output formatting must match exactly

 

 

 

Loading...

Input

1000 8 1

Expected Output

F=1000 P=8 EN=1