CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2004
    Posts
    244

    depreciation program... help please...

    hi, i need help please...

    i need to write a program to calculate the depreciation of equipment passed its useful life using two different methods...

    these are the actual requirements for the program:

    "Depreciation"

    Program requirements:

    1)

    write a c++ program to calculate depreciation using the straight-line and sum-of-digits methods.

    2)

    this program must use at least three functions

    3)

    depreciation is a decrease in value of some asset over time due to wear and decay. For exampl, suppose that a company purchases a computer system for $200,000 that will serve its needs for a five-year period. After that time, it can be sold for an estimated $50,000. The equipment will have a depreciated by $150,000 during the five-year period.

    4)

    the input to the program will be the initial cost, the residual value, and the number of years to depreciate, plua a code to indicate whether to use straight-line or sum-of-digits method.

    5)

    the output of the program will be a series of tables, one for each of the input lines. The program must use an end-of-file loop to get credit.

    6)

    The program must use file I/O

    ---------------------------------------------------------------------------

    INPUT


    200000.0 50000.0 5 S // S means straight-lie method
    200000.0 50000.0 5 D // D means sum-of-digits method
    15000.0 2500.0 10 S
    20000.0 2500.0 8 D

    ---------------------------------------------------------------------------

    OUTPUT

    for each depreciation table, write the initial cost and the residual value above the table with an appropriate message.
    The tables themselves should have column heading for each item. Under the columns, put the year, the depreciation for that year, the accumulated depreciation, and the carrying value. (The carrying value is the initial cost minus the accumulated depreciation.) The output must be formatted. Use a setprecision of 2 for the floating point numbers.

    ---------------------------------------------------------------------------

    SAMPLE OUTPUT FOR LINE 2 OF THE INPUT.

    (thisis supposed to look like a table but on the post, it doesnt...)

    Sum-of-Digits method

    Original cost= 200000.00 Residual Value= 50000.00

    Current year Current deprec Accum Depreciation Carry Value


    1 50000.00 50000.00 150000.00

    2 40000.00 ` 90000.00 110000.00

    3 30000.00 120000.00 80000.00

    4 20000.00 140000.00 60000.00

    5 10000.00 130000.00 50000.00

    ----------------------------------------------------------------------------



    and this is the code i have come up with so far...

    any help qill be greatly appreciated....

    thank you in advance...

    Code:
    
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    
    using namespace std;
    
    void inLine (float, float, float, float, float, int, int);
    void sumDigits (float, float, float, float, float, float, int, int);
    
    int main()
    
    {   //main starts
    
        ifstream inputfile;       //input file
        ofstream outputfile;      //output file, created by program
    
        float cost;               //original cost of equipment
        float junkValue;          //value at end of useful life
        float den;                //denominator
        float dep;                //depreciation
        float depsum;             //accumulative depreciation
        float carry;              //cost of equipment minus accumulative depreciation
        int years;                //useful life
        int counter;              //counts from one to useful life
        char method;              //identifies depreciation method
    
        inputfile.open("inputfile.txt");       //attempts to open input file
    
        if (!inputfile)                        //if it fails to open input file...
    
        {  //if starts
    
           cout << "Failure to open input file, please check and try again..." << endl;
           //system ("PAUSE");          // i am getting an error here, when i want the system to pause...
           return 1;
    
        }  //end of if
    
        outputfile.open("outputfile.txt");      //creates output file
    
        if (!outputfile)                        //if it fails to create file...
    
        {  //if starts 2
    
           cout << "Failure to create output file, please check and try again..." << endl;
           //system ("PAUSE");         //same error here , it gives me an error whe i try to make the system pause....
           return 1;
    
        }  //end of if2
    
        inputfile >> cost;
    
        while (inputfile)
    
        {     //while loop
    
        inputfile >> junkValue >> years >> method;
    
        if (method == 'S' || method == 's')
                   sumDigits(cost, junkValue, den, dep, depsum, carry, years, counter);
        else if (method == 'D' || method == 'd')
                   inLine(cost, junkValue, dep, depsum, carry, years, counter);
        else
                   cout << "Can not determine method to calculate depreciation, please check input file data..." << endl;
    
        //inputfile >> cost;
    
        }      //end of while loop
    
        //counter=0;
    
        for(counter=1, counter<= years, counter++)
    
        (
    
            outputfile << setw(5)  << counter;
            outputfile << setw(20) << dep;
            outputfile << setw(19) << depsum;
            outputfile << setw(8)  << carry;
    
        }
    
        inputfile >> cost;
    
        //system("PAUSE");
        return 1;
    
    }   //end of main...
    
    void sumDigits ( float cost, float junkValue, float den, float dep, float depsum, float carry, int years, int counter)
    
    {   //open void sumDigits
    
    
    
    
        den=(years*(years+1)/2);
        counter=0;
    
        for( counter=years; counter >= 1; counter--)
    
        {
    
              depsum=0;
              dep=((cost-junkValue)*(counter/den));
              depsum= depsum+dep;
    
        }
    
         carry = cost - depsum;
    
    }    //close void sumDigits...
    
    void inLine ( float cost, float junkValue, float dep, float depsum, float carry, int years, int counter)
    
    {    //open void inLine
    
         depsum=0;
         dep=((cost-junkValue)/years);
         depsum=depsum + dep;
         carry=cost - depsum;
    
    }

    i know i have many comments,but those comments are cleaned out before i hand it in, it is just form me to keep track of what i am doing, which seems not to be working .....

    thank you for the help guys (and ladies)
    Last edited by inbugable; March 15th, 2008 at 05:53 PM.

  2. #2
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: depreciation program... help please...

    [ Moved thread ]

  3. #3
    Join Date
    Sep 2004
    Posts
    244

    Re: depreciation program... help please...

    wow...noone??

  4. #4
    Join Date
    Jan 2004
    Location
    Düsseldorf, Germany
    Posts
    2,401

    Re: depreciation program... help please...

    Maybe you should let us know, what your problem is. Does your program compile? Does it run? Is it complete? What is stopping you from completing it?
    More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity. --W.A.Wulf

    Premature optimization is the root of all evil --Donald E. Knuth


    Please read Information on posting before posting, especially the info on using [code] tags.

  5. #5
    Join Date
    Feb 2002
    Posts
    4,640

    Re: depreciation program... help please...

    Quote Originally Posted by inbugable
    wow...noone??
    And the problem your having is?

    Viggy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured