Input from a file using statistical calculations

This is a discussion on Input from a file using statistical calculations within the C++ Programming forums, part of the General Programming Boards category; In my computer class we have an assignment where we are supposed to read from a file the account number, ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    8

    Input from a file using statistical calculations

    In my computer class we have an assignment where we are supposed to read from a file the account number, annual interest rate for the account, starting balance, the number of months that the account has been open
    the statistics are as follow
    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00

    WithD Deposit WithD
    0.00 100.00 75.00

    *One deposit and one Deposit WithD
    withdrawal for each month* 200.00 50.00

    there are 5 lines just like this one above and i am supposed to figure out the total deposits, total withdrawls, Total interest gained, show the final balance and the account number for each individual line and output them all to a file. If anyone can help me with this i would greatly appreciate it Thanks, Mike

  2. #2
    Registered User
    Join Date
    Oct 2003
    Posts
    8

    Input from a file using statistical calculations

    In my computer class we have an assignment where we are supposed to read from a file the account number, annual interest rate for the account, starting balance, the number of months that the account has been open
    the statistics are as follow
    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00

    WithD Deposit WithD
    0.00 100.00 75.00

    Deposit WithD
    200.00 50.00

    There is one deposit and one withdrawal for each month

    there are 5 lines just like this one above and i am supposed to figure out the total deposits, total withdrawls, Total interest gained, show the final balance and the account number for each individual line and output them all to a file. If anyone can help me with this i would greatly appreciate it Thanks, Mike

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    one way is to use an ifstream and the >> operator (assuming there is a space between each piece of data in the file as in your post) to read the material into appropriate variables. Read in the administrative data straight up and use a loop to control how many times you read in deposits and withdrawals, adjusting the balance after reading in each tranaction.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    8
    Unfortunately i'm not sure to do what you are saying... is there anyway you could take the time to demonstrate what you are talking about... if so i would greatly appreciate it.

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    any code?

    first you need to learn file I/O...

    clarify you data file... which one is it?

    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00
    3456 0.03 1256.89 4 0.00 56.00 100.00
    3456 0.03 1256.89 4 0.00 56.00 100.00

    or

    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00
    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00
    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00

    or

    3456 0.03 1256.89 4 0.00 56.00 100.00
    3456 0.03 1256.89 4 0.00 56.00 100.00
    3456 0.03 1256.89 4 0.00 56.00 100.00

    //edit: didn't realize you double posted... I copied this into the other post (http://cboard.cprogramming.com/showt...362#post317362)
    Last edited by major_small; 10-09-2003 at 12:33 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    any code?

    first you need to learn file I/O...

    clarify you data file... which one is it?

    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00
    3456 0.03 1256.89 4 0.00 56.00 100.00
    3456 0.03 1256.89 4 0.00 56.00 100.00

    or

    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00
    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00
    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00

    or

    3456 0.03 1256.89 4 0.00 56.00 100.00
    3456 0.03 1256.89 4 0.00 56.00 100.00
    3456 0.03 1256.89 4 0.00 56.00 100.00
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Registered User
    Join Date
    Oct 2003
    Posts
    8
    3578 0.03 904.67 3 0.00 50.00 0.00 0.00 75.00 0.00


    the first number is the account number
    the second number is the interest rate
    the third number is the balance
    the fourth number is how many months the account has been open
    the fifth, seventh, and ninth are deposits
    the sixth, eight and tenth numbers are withdrawals


    i have five lines similar to the line at the top of this page, some have a few more deposites but also alternate... these other lines also have acct #'s, interest rates, etc.

    thanks

  8. #8
    Registered User
    Join Date
    Oct 2003
    Posts
    8
    3578 0.03 904.67 3 0.00 50.00 0.00 0.00 75.00 0.00


    the first number is the account number
    the second number is the interest rate
    the third number is the balance
    the fourth number is how many months the account has been open
    the fifth, seventh, and ninth are deposits
    the sixth, eight and tenth numbers are withdrawals


    i have five lines similar to the line at the top of this page, some have a few more deposites but also alternate... these other lines also have acct #'s, interest rates, etc.

    thanks

  9. #9
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    i would put a letter in front of each, for example:

    a3578 i0.03 b904.67 t3 d0.00 w50.00 d0.00 w0.00 d75.00 w0.00

    then read through and when you encounter:
    a - put in account box
    i - put in interest box
    b - put in balance box
    t - put in time(months) box
    d - add to deposits box
    w - add to withdrawel box

    it would end up something like this (in a loop):
    Code:
    ...
    infile>>headerchar;
    
    if(headerchar=='a')
       infile>>account;
    else if(headerchar=='i')
       infile>>interest;
    ...
    Last edited by major_small; 10-09-2003 at 12:47 PM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  10. #10
    Registered User
    Join Date
    Oct 2003
    Posts
    8
    is there any way to incorporate this into a while loop maybe using a .eof as well in order to calculate equations... i am not familiar with the headerchar statement

  11. #11
    Registered User
    Join Date
    Oct 2003
    Posts
    8
    oh sorry i just got an email from my professor stating that i am NOT allowed to change the file that i am gathering input from which means that i can't add letters

  12. #12
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Originally posted by cuttlefishkarl
    3578 0.03 904.67 3 0.00 50.00 0.00 0.00 75.00 0.00


    the first number is the account number
    the second number is the interest rate
    the third number is the balance
    the fourth number is how many months the account has been open
    the fifth, seventh, and ninth are deposits
    the sixth, eight and tenth numbers are withdrawals
    If every line always has 10 numbers with above description it's easy to read those numbers
    Code:
    while inFile
       read account
       read interest
       read balance
       read open
       read deposit1
       read deposit2
       read deposit3
       read withdrawal1
       read withdrawal2
       read withdrawal3
    
       calculate total deposit etc
       print to file
    However, if number of deposits/withdrawals varies one line to another, it's impossible to read it without modification on the input file

  13. #13
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699

    Re: Input from a file using statistical calculations

    Originally posted by cuttlefishkarl
    In my computer class we have an assignment where we are supposed to read from a file the account number, annual interest rate for the account, starting balance, the number of months that the account has been open
    the statistics are as follow
    ACCT# Int R Balance Months Deposit WithD Deposit
    3456 0.03 1256.89 4 0.00 56.00 100.00

    WithD Deposit WithD
    0.00 100.00 75.00

    *One deposit and one Deposit WithD
    withdrawal for each month* 200.00 50.00

    there are 5 lines just like this one above and i am supposed to figure out the total deposits, total withdrawls, Total interest gained, show the final balance and the account number for each individual line and output them all to a file. If anyone can help me with this i would greatly appreciate it Thanks, Mike

    This is homework. Write a program that *attempts* to solve the problem. If something breaks, and you can't fix it - ask for help. But try to do your own work please.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  14. #14
    Registered User
    Join Date
    Oct 2003
    Posts
    8
    This is NOT homework. It is for a test grade and is not simply graded based on whether i attempted the assignment... thank you but no thank you... if you cant help i understand...

  15. #15
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    use english first:

    like alphoide does. Except a little more detail:

    while input stream is valid
    start while
    read account
    read interest
    read balance
    read how long open which equals how many deposits/wd will follow
    for loop using however many months(see above) as terminator
    start for loop
    read in a deposit
    increment balance with deposit
    read in a withdrawal
    decrease balance by withdrawal
    calculate monthly interest on balance
    add monthly interest to balance
    stop for loop
    stop while

    Now try to write something in code, if you haven't already. Everything you need is probably in your note/book/tutorial.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 01:20 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21