Skip to content

This repository contains solutions to Assignment 6, which focuses on object-oriented programming concepts in C++. The assignment includes tasks related to classes, methods, and object manipulation.

Notifications You must be signed in to change notification settings

MMTalal/CPP-Programming-Assignment-6-Solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Programming Assignment 6 Solutions

Overview

This repository contains solutions to Assignment 6, which focuses on object-oriented programming concepts in C++. The assignment includes tasks related to classes, methods, and object manipulation.

Assignments

1. Circle Class

  • Description: Implement a Circle class with the following attributes and methods:
    • Attributes:
      • radius: double (default value: 1.0)
      • color: String (default value: "red")
    • Methods:
      • Constructors:
        • Circle()
        • Circle(radius: double)
        • Circle(radius: double, color: String)
      • Getters and Setters:
        • getRadius(): double
        • getColor(): String
        • setRadius(radius: double): void
        • setColor(color: String): void
      • Additional Methods:
        • getArea(): double (returns the area of the circle)
    • Example Output:
      • Circle[radius=?, color=?]

2. Employee Class

  • Description: Implement an Employee class with the following attributes and methods:
    • Attributes:
      • id: int
      • firstName: String
      • lastName: String
      • salary: int
    • Methods:
      • Constructor:
        • Employee(id: int, firstName: String, lastName: String, salary: int)
      • Getters:
        • getID(): int
        • getFirstName(): String
        • getLastName(): String
        • getName(): String (returns full name)
        • getSalary(): int
        • getAnnualSalary(): int (returns salary * 12)
      • Setter:
        • setSalary(salary: int): void
      • Additional Method:
        • raiseSalary(percent: int): int (increases salary by the given percent and returns the new salary)
    • Example Output:
      • firstName LastName
      • salary * 12
      • Increased salary after raise

3. Account Class

  • Description: Implement an Account class with the following attributes and methods:
    • Attributes:
      • id: String
      • name: String
      • balance: int (default value: 0)
    • Methods:
      • Constructors:
        • Account(id: String, name: String)
        • Account(id: String, name: String, balance: int)
      • Getters:
        • getID(): String
        • getName(): String
        • getBalance(): int
      • Additional Methods:
        • credit(amount: int): int (adds amount to balance and returns the new balance)
        • debit(amount: int): int (subtracts amount from balance if amount <= balance, otherwise prints "Amount exceeded balance" and returns balance)
        • transferTo(another: Account, amount: int): int (transfers amount to another account if amount <= balance, otherwise prints "Amount exceeded balance" and returns balance)
    • Example Output:
      • Balance after credit
      • Balance after debit
      • Balance after transfer

4. Time Class

  • Description: Implement a Time class with the following attributes and methods:
    • Attributes:
      • hour: int (range: [0, 23])
      • minute: int (range: [0, 59])
      • second: int (range: [0, 59])
    • Methods:
      • Constructor:
        • Time(hour: int, minute: int, second: int)
      • Getters and Setters:
        • getHour(): int
        • getMinute(): int
        • getSecond(): int
        • setHour(hour: int): void
        • setMinute(minute: int): void
        • setSecond(second: int): void
        • setTime(hour: int, minute: int, second: int): void
      • Additional Methods:
        • nextSecond(): Time (advances time by 1 second and returns the instance)
        • previousSecond(): Time (moves time back by 1 second and returns the instance)
    • Example Output:
      • Time after advancing by 1 second
      • Time after moving back by 1 second

How to Run the Programs

  1. Compile the C++ files using a C++ compiler (e.g., g++).
  2. Run the C++ programs Run the executable and provide the required input.
  3. Follow the instructions for user input and verify the outputs.

How to Contribute

  1. Fork the repository.
  2. Create a new branch for your changes.
  3. Implement your solution to one of the assignments.
  4. Submit a pull request with a clear description of your changes.

Testing

To test the programs, follow these steps:

  1. Compile the program using a C++ compiler (e.g., g++).
  2. Run the executable and provide the required input.
  3. Verify that the output matches the expected results provided in the examples.

License

This project is licensed under the MIT License.

About

This repository contains solutions to Assignment 6, which focuses on object-oriented programming concepts in C++. The assignment includes tasks related to classes, methods, and object manipulation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages