CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Dec 2010
    Posts
    4

    VBC++ help with putting stuff into a file

    Code:
    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <cstdlib>
    #include <ctime>
    #include <fstream>
    using std::ifstream;
    using std::ofstream;
    using namespace std;
    const int MAXACCOUNTS = 50;
    const int MAXANYTHING=100;
    ifstream myfile;
    ofstream myfile2;
    
    struct BankAccount{
     char Name[MAXANYTHING];
     char Address[MAXANYTHING];
     float Balance;
     int AccountNumber;
    };
    
    void menu(){
     cout<<"Welcome To The Bank Menu:"<<endl;
     cout<<"1. Open new account"<<endl;
     cout<<"2. Deposit amount"<<endl;
     cout<<"3. Withdraw amount"<<endl;
     cout<<"4. Display an account"<<endl;
     cout<<"5. Modify an account"<<endl;
     cout<<"6. Close an account"<<endl;
     cout<<"7. Exit"<<endl<<endl<<endl;
     cout<<"Please Select An Option:"<<endl;
    }
    
    void enter(BankAccount Account[], int & numberItems){
     const int LENGTH=20;
     
     int random_integer;
    
     if(numberItems==MAXACCOUNTS){
      cout<<"Can't add a new account. Array is full"<<endl;}
     BankAccount anAccount;
     cout<<endl<<"Please enter your name:"<<endl;
     cin>>anAccount.Name;
     cout<<endl<<"Please enter your address:"<<endl;
     cin>>anAccount.Address;
     cout<<endl<<"Please enter your initial deposit amount:"<<endl;
     cin>>anAccount.Balance;
    
     srand((unsigned)time(0));
     random_integer = rand();
     anAccount.AccountNumber = random_integer;
     cout<<"Your Account Number Is:"<< random_integer<<endl;
    
     Account[numberItems]=anAccount;
     numberItems++;
     }
    
    void display(BankAccount Account[],int & numberItems){
     int AccNum;
     
    
      if(numberItems==0)
       cout<<"There are no accounts in the bank.";
      else
       cout<<"Please enter the bank account number";
       cin>>AccNum;
       for(int k=0;k<=numberItems;k++){
        if(AccNum==Account[k].AccountNumber){
         cout<<"Account Name:"<<Account[k].Name<<endl;
         cout<<"Account Address:"<<Account[k].Address<<endl;
         cout<<"Account Balance:"<<Account[k].Balance<<endl;
        }
       }
    }
    
    
    
    //int MenuChoice, NextFreeAccount=0;
    //int AccountNumber [MAXACCOUNTS];
    //char Name[MAXACCOUNTS];
    //char Address [MAXACCOUNTS];
    //double deposit=0,withdraw=0;
    //int random_integer=0;
    
    
    
    
    
    
    
    void main(){
     int numberElements=10;
     BankAccount Accountss[MAXACCOUNTS];
     int selection;
     do{
      menu();
      cin>>selection;
      switch(selection){
       case 1:
        enter(Accountss,numberElements);
        break;
       case 2:
        display(Accountss,numberElements);
        break;
       case 3:
        //modify(Accountss,numberElements);
        break;
       case 4:
        //deleteItem(Accountss,numberElements);
        break;
      }
    
      myfile.open("File1.txt",ios::app);
      myfile2.open("File2.txt");
      if(myfile.fail()){
    	  cout<<"file1 could not be opened"<<endl;
      }
      else {
    	  cout<<"File1 was opened."<<endl;
      }
      if(myfile2.fail()){
    	  cout<<"File2 could not be opened"<<endl;
      }
      else{
    	  cout<<"file2 was opened"<<endl;
      }
    
     }while(selection!=5);
     cout<<"Thank you for using this program\n";
     system("pause");
    }
    thats our code..


    im just confused.. ssee i want to find out how to put the structure into the file.. so that it saves the users info. any help would be awesome.

    If you could leave your msn messenger address that would be awesome to help us.
    Last edited by cilu; December 7th, 2010 at 05:35 AM. Reason: code tags

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: VBC++ help with putting stuff into a file

    1. Please, use Code tags. Otherwise your code is absolutely unreadable. See Announcement: Before you post....
    2. Please, Please, provide more info about what you are trying to achieve and what your problem is.
    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: VBC++ help with putting stuff into a file

    You can use the write() and read() methods.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: VBC++ help with putting stuff into a file

    What do you have against white space?

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: VBC++ help with putting stuff into a file

    Quote Originally Posted by GCDEF View Post
    What do you have against white space?
    I guess OP just *saves* spaces...
    The question is, however: what for?
    Victor Nijegorodov

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    Re: VBC++ help with putting stuff into a file

    Quote Originally Posted by VictorN View Post
    I guess OP just *saves* spaces...
    The question is, however: what for?
    I do this habitually too. For me, it goes back to the days of writing programs on punch cards. I'm an old dog and I don't like to learn new tricks.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: VBC++ help with putting stuff into a file

    Quote Originally Posted by hoxsiew View Post
    I do this habitually too. For me, it goes back to the days of writing programs on punch cards. I'm an old dog and I don't like to learn new tricks.
    I used punched cards during at least my first three or four years (since 1976) in programming. But I never tried to "save" cards, nor card spaces! I always tried to create something more or less readable (because it was I who had to read/update the code punched on the cards!)
    Victor Nijegorodov

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: VBC++ help with putting stuff into a file

    Quote Originally Posted by hoxsiew View Post
    I do this habitually too. For me, it goes back to the days of writing programs on punch cards. I'm an old dog and I don't like to learn new tricks.
    readabilityisimportantcodejustlikeenglishismucheasiertoreadandunderstandifyouusewhitespaceappropriately

  9. #9
    Join Date
    Dec 2010
    Posts
    4

    Re: VBC++ help with putting stuff into a file

    ok what i need to do is basically im writing a program for a bank. We ask the user if they want a new account ect, as you can see in the menu. If they select 1 it asks for some info, and that info needs to be saved to a file for opening if they want to display the account, or make mods to account such as change name, put a deposit, or make a withdrawl.

    Thanks

    Randy Rashid

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: VBC++ help with putting stuff into a file

    You are 'writing a program for a bank", a kind of interactive program... And this "program" has no GUI at all?
    Victor Nijegorodov

  11. #11
    Join Date
    Dec 2010
    Posts
    4

    Re: VBC++ help with putting stuff into a file

    gui?

  12. #12
    Join Date
    Dec 2010
    Posts
    4

    Re: VBC++ help with putting stuff into a file

    no no no ... its not a real bank. Im in first year university, intro to programming course..

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