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.
- 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)
- Constructors:
- Example Output:
Circle[radius=?, color=?]
- Attributes:
- 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)
- Constructor:
- Example Output:
firstName LastName
salary * 12
- Increased salary after raise
- Attributes:
- 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)
- Constructors:
- Example Output:
- Balance after credit
- Balance after debit
- Balance after transfer
- Attributes:
- 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)
- Constructor:
- Example Output:
- Time after advancing by 1 second
- Time after moving back by 1 second
- Attributes:
- Compile the C++ files using a C++ compiler (e.g.,
g++
). - Run the C++ programs Run the executable and provide the required input.
- Follow the instructions for user input and verify the outputs.
- Fork the repository.
- Create a new branch for your changes.
- Implement your solution to one of the assignments.
- Submit a pull request with a clear description of your changes.
To test the programs, follow these steps:
- Compile the program using a C++ compiler (e.g.,
g++
). - Run the executable and provide the required input.
- Verify that the output matches the expected results provided in the examples.
This project is licensed under the MIT License.