0% found this document useful (0 votes)
39 views6 pages

C++ Program List

The document contains C++ code for a Depreciation class that calculates asset depreciation using both Straight-Line and Diminishing Balance methods. It includes methods for user input and displays the depreciation and book value for each year. The code demonstrates different implementations of the depreciation calculations, including variations in control structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views6 pages

C++ Program List

The document contains C++ code for a Depreciation class that calculates asset depreciation using both Straight-Line and Diminishing Balance methods. It includes methods for user input and displays the depreciation and book value for each year. The code demonstrates different implementations of the depreciation calculations, including variations in control structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

#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;
}

You might also like