#include <iostream>
using namespace std;
class Depreciation
{
float cost, salvage, rate;
int years;
public:
void input();
void straightLine();
void diminishingBalance();
};
// Function to get input from user
void Depreciation::input() {
cout << "Enter asset cost: ";
cin >> cost;
cout << "Enter salvage value: ";
cin >> salvage;
cout << "Enter useful life (years): ";
cin >> years;
cout << "Enter depreciation rate (% for DBM): ";
cin >> rate;
}
// Straight-Line Depreciation
void Depreciation::straightLine() {
float dep = (cost - salvage) / years;
float value = cost;
cout << "\nStraight Line Method:\n";
cout << "Year\tDepreciation\tBook Value\n";
for (int i = 1; i <= years; i++) {
value -= dep;
cout << i << "\t" << dep << "\t\t" << value << endl;
}
}
// Diminishing Balance Depreciation
void Depreciation::diminishingBalance()
{
float value = cost;
cout << "\nDiminishing Balance Method:\n";
cout << "Year\tDepreciation\tBook Value\n";
for (int i = 1; i <= years; i++)
{
float dep = value * rate / 100;
value -= dep;
cout << i << "\t" << dep << "\t\t" << value << endl;
if (value < salvage)
break;
}
}
int main() {
Depreciation d;
[Link]();
[Link]();
[Link]();
return 0;
}
#include <iostream>
using namespace std;
class Depreciation {
float cost, salvage, rate;
int years;
public:
void getInput();
void straightLine();
void diminishingBalance();
};
// Get user input
void Depreciation::getInput() {
cout << "Enter cost of asset: ";
cin >> cost;
cout << "Enter salvage value: ";
cin >> salvage;
cout << "Enter useful life (in years): ";
cin >> years;
cout << "Enter depreciation rate (for DBM) in %: ";
cin >> rate;
}
// Straight-Line Method using while loop
void Depreciation::straightLine() {
float dep = (cost - salvage) / years;
float value = cost;
int year = 1;
cout << "\nStraight-Line Method:\n";
cout << "Year\tDepreciation\tBook Value\n";
while (year <= years) {
value -= dep;
cout << year << "\t" << dep << "\t\t" << (value < salvage ? salvage : value) << endl;
year++;
}
}
// Diminishing Balance Method using while loop
void Depreciation::diminishingBalance() {
float value = cost;
int year = 1;
cout << "\nDiminishing Balance Method:\n";
cout << "Year\tDepreciation\tBook Value\n";
while (year <= years && value > salvage) {
float dep = value * rate / 100;
value -= dep;
if (value < salvage) value = salvage;
cout << year << "\t" << dep << "\t\t" << value << endl;
year++;
}
}
int main() {
Depreciation obj;
[Link]();
[Link]();
[Link]();
return 0;
}
#include <iostream>
using namespace std;
class Depreciation
{
float cost, salvage, rate;
int years;
public:
void getInput();
void straightLine();
void diminishingBalance();
};
// Input function
void Depreciation::getInput()
{
cout << "Enter cost of the asset: ";
cin >> cost;
cout << "Enter salvage value: ";
cin >> salvage;
cout << "Enter useful life (max 3 years for this demo): ";
cin >> years;
cout << "Enter depreciation rate (for DBM) in %: ";
cin >> rate;
}
// Straight-Line Method without control structures
void Depreciation::straightLine()
{
float depreciation = (cost - salvage) / years;
float value = cost;
cout << "\nStraight Line Method:\n";
cout << "Year\tDepreciation\tBook Value\n";
value -= depreciation;
cout << "1\t" << depreciation << "\t\t" << value << endl;
value -= depreciation;
cout << "2\t" << depreciation << "\t\t" << value << endl;
value -= depreciation;
cout << "3\t" << depreciation << "\t\t" << value << endl;
}
// Diminishing Balance Method without control structures
void Depreciation::diminishingBalance()
{
float value = cost;
cout << "\nDiminishing Balance Method:\n";
cout << "Year\tDepreciation\tBook Value\n";
float dep1 = value * rate / 100;
value -= dep1;
cout << "1\t" << dep1 << "\t\t" << value << endl;
float dep2 = value * rate / 100;
value -= dep2;
cout << "2\t" << dep2 << "\t\t" << value << endl;
float dep3 = value * rate / 100;
value -= dep3;
cout << "3\t" << dep3 << "\t\t" << value << endl;
}
int main()
{
Depreciation d;
[Link]();
[Link]();
[Link]();
return 0;
}