C++ coding Class-based Problem #2

Hi Expert,

Here is problem #2 I'm trying to separate a big problem into numerous smaller problems so I can distribute more points.

Here is my overall Code. (not 100% complete)

#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>

using namespace std; 
  
class SavingsAccount
{
      private:
         int accNumber;
         float balance;
         float interestRate;  
         
      public:
         void setUpAccount( int, float, float );
         void addDeposit(float);
         void subWithdraw (float);
         void addInterest();
         float getBalance();
         bool matchAccount (int);
}; 

class Customer
{
      private:
         string name;
         string address;
         SavingsAccount saveAcnt;
         
      public:
         void createCust(string, string, int);
         bool seachAccounts (int);
         void applyTrans (char, float);
         void accessAccount (char);
};

class Transaction
{
      private: int accountNumber;
      private: float amount;
      private: char transType;
            
      public: void readRecord (ifstream);
      public: int findAccount (Customer[], int);
      public: void process (Customer[]);
          
};




                                float SavingsAccount:: getBalance()
                                    {
                                          return balance;
                                    }
                                                                      
                                                               void setUpaccount(int accountNumber, float amount, float transType)
                                                               {
                                                               ofstream myfile;
                                                               ofstream out("example.txt");
                                                               myfile.open ("example.txt", ios::in | ios::out);
                                                               cout<<"Enter account Number:  "<< endl;
                                                               cin >>accountNumber;
                                                                                                          
                                                               cout<<"Enter Starting Balance:  "<< endl;
                                                               cin >>amount;
                                                                                                          
                                                               cout<<"Enter Interest Rate:  "<< endl;
                                                               cin >>transType;
                                                               }
                                                                                                          
                                                                                                          
     
                                                                                  void adddeposit(float balance, float deposit)
                                                                                  {                                                                                 
                                                                                  cout <<"Enter an amount to deposit: "<< endl; 
                                                                                  cin >> deposit;
                                                                                  balance = balance+ deposit;
                                                                                  } 
     
                                                                                    void subWithdraw(float withdraw, float balance)
                                                                                    {
                                                                                    cout << "Enter an amount to withdraw $" << endl;
                                                                                    cin >> withdraw;
                                                                                    balance = balance - withdraw;
                                                                                    }     
                                                                                                                                                                        
                                                                                    void addinterest(float interestRate)
                                                                                    {
                                                                                    interestRate = 5.0;
                                                                                    }   
                                                                                                                                                                                    
                                                                                                               bool matchAccount(int a, int accNumber)
                                                                                                               {
                                                                                                               cout << "enter an account number";
                                                                                                               cin >> a;
                                                                                                               if (a==accNumber)
                                                                                                                  {
                                                                                                               cout<<"This account Number already exsists"<<endl; 
                                                                                                                 
                                                                                                                   }
                                                                                                               }
                                                                                                                                                                                     
                                                                                                                                                                                                  
                                                                                                                                                                                        
     

int main()
{
  setUpaccount(int accountNumber, float amount, float transType);
  system("pause");                                                       
  return 0;
}

Open in new window


Here is the code I am working on in this problem.

void setUpaccount(int accountNumber, float amount, float transType)
 {
 ofstream myfile;
 ofstream out("example.txt");
 myfile.open ("example.txt", ios::in | ios::out);
 cout<<"Enter account Number:  "<< endl;
 cin >>accountNumber;
                                                                                                          
 cout<<"Enter Starting Balance:  "<< endl;
 cin >>amount;
                                                                                                          
 cout<<"Enter Interest Rate:  "<< endl;
 cin >>transType;
    }

Open in new window


 
bool matchAccount(int a, int accNumber)
 {
 cout << "enter an account number";
  cin >> a;
            if (a==accNumber)
                {
                  cout<<"This account Number already exsists"<<endl; 
                 }
 }

Open in new window


What I'm trying to do is make the setUpaccount function write to a file without deleting the previous content of said file, when I input myfile instead of cin I get a whole heap of errors about myfile not working etc even though I have the fstream library in my code. (although I think my logic on how this works is wrong.)

Another thing I'm trying to do is make my boolean function check said file for duplicate accNumbers when the user types in whatever accNumber when setting up a new account. Depending on the results either allowing the user to input that account number or displaying an alert in the form of a cout and ending the creation of that account.

Thanks in Advance,

Rick.

Ricky NguyenITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

brendanmeyerCommented:
can you post some errors?
0
Ricky NguyenITAuthor Commented:
Hey again brendanmeyer :),

Currently the bool function doesn't produce any errors but I know that it doesn't perform its task properly for example I'm pretty sure a cout statement alone won't prevent the accNumber from being placed into the notepad file I'm also wondering what sort of coding I would have to apply for the bool function to check the notepad in the first place.

As for my writing to file problem with the setUpaccount function currently I am running with.

  
void setUpaccount(int accountNumber, float amount, float transType)
 {
 ofstream myfile;
 ofstream out("example.txt");
 myfile.open ("example.txt", ios::in | ios::out);
 cout<<"Enter account Number:  "<< endl;
 cin >>accountNumber;
 myfile <<accountNumber;
                                                              
                                                                                                          
 cout<<"Enter Starting Balance:  "<< endl;
 cin >>amount;
  myfile <<amount;
                                                                                                          
   cout<<"Enter Interest Rate:  "<< endl;
   cin >>transType;
   myfile <<transType;
                                                              
}

Open in new window


For the code above I'm getting an expected primary-expression before "type" when I call the function.

int main()
{
  setUpaccount(int accountNumber, float amount, float transType);
  system("pause");                                                       
  return 0;
}

Open in new window


Hope this helps clarify my question.


0
brendanmeyerCommented:
for
 
int main()
{
  setUpaccount(int accountNumber, float amount, float transType);
  system("pause");                                                       
  return 0;
}

Open in new window


you cant declare the variables in the function call
you need to declare them beforehand
int main()
{
  int accountNumber;
  float amount, transType;
  setUpaccount(accountNumber, amount, transType);
  system("pause");                                                       
  return 0;
}

Open in new window


does the code compile?
do you get warnings or errors?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ricky NguyenITAuthor Commented:

SWEET! :)

The code compiles now without a hitch and is put into the file that was specified although the numbers are compressed and don't have spacing at the moment, but how do I get my Boolean function to check the contents of a notepad file that already exists that contains the same data (accNumber, etc, etc) and then tell the user whether or not the accNumber they have entered in is valid.

If it helps the program in its complete form is meant to:

(class)Transactions ----(debit from or credit to) ---> (Class)Account -----Which belongs to---> (class)Customer

Those transactions are held in a notepad where they can be traced and displayed on screen by searching for an accNumber, hence why it is vital to not have duplicates.

0
Ricky NguyenITAuthor Commented:
Just figured out that I probably need to implement my array so that I can search that array for the data before the boolean takes effect. I will post this problem in another Question later :)

Thanks for the help.

More questions to come :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.