|
-
December 6th, 2010, 09:26 PM
#1
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
-
December 7th, 2010, 04:03 AM
#2
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
-
December 7th, 2010, 05:36 AM
#3
Re: VBC++ help with putting stuff into a file
You can use the write() and read() methods.
-
December 7th, 2010, 08:07 AM
#4
Re: VBC++ help with putting stuff into a file
What do you have against white space?
-
December 7th, 2010, 08:20 AM
#5
-
December 7th, 2010, 09:15 AM
#6
Re: VBC++ help with putting stuff into a file
 Originally Posted by VictorN
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.
-
December 7th, 2010, 09:23 AM
#7
Re: VBC++ help with putting stuff into a file
 Originally Posted by hoxsiew
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
-
December 7th, 2010, 09:31 AM
#8
Re: VBC++ help with putting stuff into a file
 Originally Posted by hoxsiew
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
-
December 7th, 2010, 03:03 PM
#9
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
-
December 7th, 2010, 03:08 PM
#10
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
-
December 7th, 2010, 03:19 PM
#11
Re: VBC++ help with putting stuff into a file
-
December 7th, 2010, 03:19 PM
#12
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|