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
Circleclass 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(): doublegetColor(): StringsetRadius(radius: double): voidsetColor(color: String): void
- Additional Methods:
getArea(): double(returns the area of the circle)
- Constructors:
- Example Output:
Circle[radius=?, color=?]
- Attributes:
- Description: Implement an
Employeeclass with the following attributes and methods:- Attributes:
id: intfirstName: StringlastName: Stringsalary: int
- Methods:
- Constructor:
Employee(id: int, firstName: String, lastName: String, salary: int)
- Getters:
getID(): intgetFirstName(): StringgetLastName(): StringgetName(): String(returns full name)getSalary(): intgetAnnualSalary(): 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 LastNamesalary * 12- Increased salary after raise
- Attributes:
- Description: Implement an
Accountclass with the following attributes and methods:- Attributes:
id: Stringname: Stringbalance: int(default value: 0)
- Methods:
- Constructors:
Account(id: String, name: String)Account(id: String, name: String, balance: int)
- Getters:
getID(): StringgetName(): StringgetBalance(): 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
Timeclass 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(): intgetMinute(): intgetSecond(): intsetHour(hour: int): voidsetMinute(minute: int): voidsetSecond(second: int): voidsetTime(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.