EX NO 7 : OOPS LAB - FUNCTION OVERLOADING

 

EX NO 7 – Function overloading


Set 1. Smart Calculator with Mode-Based Operations ( ROLL NUM - 56 TO 61)

Function: calculate()

Overloads:

  • calculate(int a, int b, char op)
    • Perform operation based on op
      • '+' → addition
      • '-' → subtraction
      • '*' → multiplication
      • '/' → division (handle divide-by-zero)
  • calculate(double a, double b)
    • Always perform division and return precise result
  • calculate(int a)
    • Return square of number

Set  2. Student Evaluation System ( ROLL NUM - 6 TO 10)

Function: evaluate()

Overloads:

  • evaluate(int marks)
    • Assign grade:
      • ≥90 → A
      • ≥75 → B
      • ≥50 → C
      • <50 → Fail
  • evaluate(int marks, int attendance)
    • If attendance > 85%, add 5 bonus marks
    • Then compute grade
  • evaluate(string grade)
    • Print remark:
      • A → Excellent
      • B → Good
      • C → Average
      • Fail → Needs Improvement

Set  3. Password Validation System 🔐  ( ROLL NUM - 11 TO 15)

Function: validate()

Overloads:

  • validate(string password)
    • Check:
      • Length ≥ 6
      • Contains at least one digit
  • validate(string password, int minLength)
    • Check if password length ≥ minLength
  • validate(string password, bool checkSpecial)
    • If true, check for special characters (@,#,$,%,&)

Set  4. Online Shopping Discount System 🛒 ( ROLL NUM - 16 TO 20)

Function: calculateBill()

Overloads:

  • calculateBill(double amount)
    • No discount → return same amount
  • calculateBill(double amount, int discountPercent)
    • Apply:
      final = amount - (amount * discountPercent / 100)
  • calculateBill(double amount, string couponCode)
    • Example logic:
      • "SAVE10" → 10% discount
      • "FLAT500" → subtract 500
      • Invalid → no discount

Set   5. Attendance Tracking System  ( ROLL NUM - 21 TO 25)

Function: markAttendance()

Overloads:

  • markAttendance(int studentID)
    • Mark as Present
  • markAttendance(int studentID, string status)
    • Accept "Present" or "Absent"
    • Store/display accordingly
  • markAttendance(string name)
    • Mark attendance using student name instead of ID

Set  6. Time Conversion Utility ⏱️  ( ROLL NUM - 26 TO 30)

Function: convertTime()

Overloads:

  • convertTime(int seconds)
    • Convert into:
      • minutes = seconds / 60
      • remaining seconds
  • convertTime(int minutes, int seconds)
    • Convert into total seconds
  • convertTime(int hours, int minutes, int seconds)
    • Convert into:
      • total seconds
      • OR total minutes (your choice for variation)

Set  7. Medical Diagnosis Assistant 🏥 ( ROLL NUM - 31 TO 40)

Function: diagnose()

Overloads:

  • diagnose(float temperature)
    • 37.5°C → Fever
    • Else → Normal
  • diagnose(float temperature, int pulseRate)
    • Fever + pulse > 100 → “Consult Doctor”
    • Else → Mild condition
  • diagnose(string symptom)
    • Example:
      • "cough" → Cold
      • "headache" → Stress
      • "stomach pain" → Digestive issue

Set  8. Matrix Operations System ( ROLL NUM - 41 TO 50)

Function: operate()

Overloads:

  • operate(matrix A, matrix B)
    • Perform matrix addition
  • operate(matrix A, int scalar)
    • Multiply each element by scalar
  • operate(matrix A)
    • Return transpose of matrix

👉 Students must implement loops properly here (good practice!)


Set  9. File Logger System 📁  ( ROLL NUM - 51 TO 55)

Function: log()

Overloads:

  • log(string message)
    • Print message with default tag [INFO]
  • log(string message, string level)
    • Print: [LEVEL]: message
  • log(string message, string level, string time)
    • Print: [TIME] [LEVEL]: message

Set  10. Geometry Distance Analyzer   ( ROLL NUM - 1 TO 10)

Function: distance()

Overloads:



Comments