5 Replies - 682 Views - Last Post: 15 May 2011 - 11:29 PM Rate Topic: -----

#1 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Wanting to ignore File input based on data found

Posted 14 May 2011 - 08:39 AM

Basically i have started to write a program to simulate an ATM machine I have been provided with sample data to test with though i am meant to end input when X is found in the file. This has two classes associated I believe correctly though I will be using a Getter which contains the file input so i may remove an additional one i have at the moment

# include <iostream>
# include <fstream>

#include <account.h>
#include <customer.h>
# define maxlength 5
# define max_acc 10
 using namespace std;

class Account : public customer
{
    public:
        Account();
        virtual ~Account();
        int GetCustomer_ID() { return Customer_ID; }
        void SetCustomer_ID(int val) { Customer_ID = val; }
        int GetAccount_ID() { return Account_ID; }
        void SetAccount_ID(int val) { Account_ID = val; }
        char GetAccount_Type() { return Account_Type; }
        void SetAccount_Type(char val) { Account_Type = val; }
        double GetBalance() { return Balance; }
        void SetBalance(double val) { Balance = val; }
        double GetInterest_Rate() { return Interest_Rate; }
        void SetInterest_Rate(double val) { Interest_Rate = val; }
    protected:
    private:
        int Customer_ID;
        int Account_ID;
        char Account_Type;
        double Balance;
        double Interest_Rate;
} account Accounts [max_acc];

class Customer
{
    public:
        Customer ();
        ~Customer ();
        int GetCustomer_ID() { return Customer_ID; }
        void SetCustomer_ID(int val) { Customer_ID = val; }
        string GetCustomer_Name() { return Customer_Name; }
        void SetCustomer_Name(string val) { Customer_Name = val; }
        string GetAddress() { return Address; }
        void SetAddress(string val) { Address = val; }
    protected:
    private:
        int Customer_ID;
        string Customer_Name;
        string Address;
}Customer Customers [maxlength];




int main ()
{

ifstream myfile ("customers.dat");

    if (myfile.is_open())
  {
    while ( myfile.good() )
    {  for (int n = 0; n <length; n++)
    {
      myfile >> Customer[n].Customer_ID;cout<<flush;
      myfile >> Customer[n].Customer_Name;
      myfile >> Customer[n].Address;
      myfile >> Accounts[n].Account_Type
      myfile >> Accounts[n].Account_ID
      
           }

      myfile.close();}



Again as a later step i am meant to check if the accounts pin number is ! = 9999

i was thinking of using a switch statement on the account type


ie if account type = C && pin ! = 9999

as C is checking account Basically i would like to know how to end the input of the indivdual person at X as the file has more than one person and more than one X


Note the functions were auto generated using codeblocks so any errors there also i would like to fix should i remove the virtual functions?

Any Help is greatly appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: Wanting to ignore File input based on data found

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Wanting to ignore File input based on data found

Posted 14 May 2011 - 09:52 AM

There are times when it is hard to answer a question because the answer that comes to mind is: "Well you just do it." that is, there is no secret C function or C++ class that you can plug-in, its just a question of writing up the logic.

So what you want is to write a parser. Something that takes meaning from the text file and preforms rudimentary operations based upon what it finds. The operations would probably be -- either store the information in some kind of structure, or ignore it and look for more good information.

Can you give us an example of what your data file looks like?
Was This Post Helpful? 0
  • +
  • -

#3 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Re: Wanting to ignore File input based on data found

Posted 15 May 2011 - 12:45 AM

View PostNickDMax, on 15 May 2011 - 03:52 AM, said:

There are times when it is hard to answer a question because the answer that comes to mind is: "Well you just do it." that is, there is no secret C function or C++ class that you can plug-in, its just a question of writing up the logic.

So what you want is to write a parser. Something that takes meaning from the text file and preforms rudimentary operations based upon what it finds. The operations would probably be -- either store the information in some kind of structure, or ignore it and look for more good information.

Can you give us an example of what your data file looks like?



I Can give you an idea of what the data is like it has been suggested to use a list though i have not done so where i have the arrays.

the data is as attached

basically i am meant to take the data found in the attached file which contains both customer and account information and perform calculations on the data ie intrest ,deposit etc

depending on the account type ie K,C,S etc intrest rates may not apply or overdrafts may be avaliable I know the functions as writen are close to what i am looking for though as the data contains the variable at different points i agree stroing it somehow either arrays or lists would suffice.


though i am also thinking that as some customers contain more than 1 account i must link the customer number to it ie the first nuber in the data so maybe a temp varaible that passes the customer ID and uses it for all until X is found may work though i have limited expereince with functions/passers as i generally write in procedural code


So any help is greatly appricated and any changes are welcomed as long as it performs the desired tasks

Attached File(s)

  • Attached File  data.txt (277bytes)
    Number of downloads: 89

Was This Post Helpful? 0
  • +
  • -

#4 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Re: Wanting to ignore File input based on data found

Posted 15 May 2011 - 04:12 AM

Okay i will Write a bit of code here to show exactly what i am aiming to do



Classes As Above

except 

Account

should have int pin

inside a loop where pin = 9999 makes program return 0; and exit 


though i would like to have this as a cin value  that gets stored in an array 

and a cin of account number that searches the accounts array

ie where accontnum = accounts[n].account_Num or similar


where account_type = C interest Rate = 0.0
balance = 1000 (Default Value)
if trasnaction is depost balance += amount or balance = balance+amount 


where account type = 'K' intrest rate = 18.0

avaliable credit = 5000 default initial value - amount 

amount owing = amount 

pin = pin

where account type = 'S'

interest = 5%
balance = 0 initial

if deposit balance = balance+amount
if withdrawl balance = balance-amount with the ability to overdraw by $150 

though if balance <0 cout  Account overdrawn by amount 




I know how to write this part fairly easily excpet i don't know how to if it is using a linked list or how to overcome the differences in the above data as two customers have more than one account so I need something flexible which is why i belive a linked list may be the best option or a multi dimesional array such as


customer number -> account Number -> account info


then a for loop which would allow for returning all customer numbers or a cin for account numbers which would eturn the balance and enable the user to perform transactions


ie if a enter account number 0000001

which has initial balance of $1000

then i choose to do 'D' for deposit balance would update and the change would be shown in the output

if i chose W Withdrawl etc

else simulate pin = 9999

or cout message please enter pin = 9999

or have a press 0 to exit which sets pin to = 9999 as the exit clause.


How would i structure this using the above code as a basis though i think i need to remove some of the setters as they Are in the same datafile or how would i pull it into the different lists or arrays


Any He;lp is greatly appriciated Thanks
Was This Post Helpful? 0
  • +
  • -

#5 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Re: Wanting to ignore File input based on data found

Posted 15 May 2011 - 06:16 AM

Re-reading the specifications

A menu containing (Which i think i would like to enter account number or customer id then account number and pin which would then generate a textfile output of the account information after the transaction has run

1 Withdraw Cash 2 Deposit 3 Show balance 4 Quit

Your program should read the customer data and transaction file supplied and correctly apply the transactions to the customers and their accounts. Your program should produce a balance for all customers on screen first then apply the transactions, producing an on-screen display of the account and the transaction then produce an updated balance on screen for every customer. Customers should be updated in the customer file.

The program should then enter ATM mode and allow operations on accounts. After exiting the ATM mode the new transactions generated should be applied to the customer data file and the updated customer data stored. A final update balance for all customers should then be displayed on screen.


The suggestion is a linked list which stores the account types for each customer using an ATM Class which i suspect to contain the fucntions to update balance etc

Any help on this is much appreciated

This post has been edited by jaimesharp: 15 May 2011 - 06:19 AM

Was This Post Helpful? 0
  • +
  • -

#6 jaimesharp  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 105
  • Joined: 27-May 09

Re: Wanting to ignore File input based on data found

Posted 15 May 2011 - 11:29 PM

Basically i would like to know how to take the data and add it to a linked list
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1