ok this thread is in honor of bbomber72000. Ok I need help with a bank program. I'll give you details later about the program.
ok this thread is in honor of bbomber72000. Ok I need help with a bank program. I'll give you details later about the program.
Its actually an ATM program we are working on, but whatever.
<\randomness>
WTH? Do not use this forum for spam. Take it to PM or IM because you obviously aren't looking for any help in here.
I will reopen this, but if one more spam post is posted by either of you, the thread will get closed again.
Hello Pika Art by Dr Unne ~~~ godhatesfraggles
In order to get help, you need to post the program prompt, and say what part you are stuck on.
BTW, get a new prompt if you lost it.
Leave some shards under the belly
Lay some grease inside my hand
It's a sentimental jury
And the makings of a good plan
ok I need help on my next program.
The prompt goes like this:
Write a multi function program that will read the names of students and their respective scores for a quiz from a data file(NAME_QUIZ.DAT). Next, determine which person had the highest score as well as the lowest. Finally print that information to a data file.
We learned about sequential access files, stream operation modes and random access files in class. We also learned about ifstream.h, ofstream.h and infile. Where do I get started in the program?
This is NAME.QUIZ.DAT :
Allen Anderson
72
Bob Bennett
38
Carla Cobb
91
Dave Davis
76
Earl Eaton
92
Frank Floyd
89
Gavin George
77
Helen Hightower
98
Ingrid Ingersolls
90
Jack Johnson
65
Ken Kennedy
97
Louise Larkin
87
Maria Melendez
86
The End
0
You will need four local variables, the highest and lowest score, each initialized to 0 and the names of the student's with the highest and lowest scores. Then read through the file and compare the score to the highest existing score. If it's higher, store that student's name and score as the new highest. Do the same with the lowest. Then output the highest and lowest to the output file.
As far as how to develop it, be sure to do it on piece at a time as it's much easier to test and debug. I would reccomend writting the code to read in the file. Then write the code to find the highest score. Then the code for the lowest. Finally, write the code to generate the output.
I think I get what you are saying. This is what I have come up with after minutes of thinking. (I'm using Dev C++)
#include <conio.h>
#include <iostream>
#include <iomanip.h>
#include <fstream.h>
#include <dos.h>
int main()
{
int highest;
int lowest;
char namehighest;
char namelowest;
highest=0;
lowest=0;
outfile.open("NAME_QUIZ.DAT", ios::out);
}
You can test both min and max at the same time (while reading, in fact).Originally Posted by Flying Mullet
And then there is Death
I think he meant "test the code", not "test the data".Originally Posted by Endless
![]()
Ah, I seeThat said, you can write both min and max at the same time and test.
And then there is Death
OK this is what I got:
# include <conio>
# include <iostream>
# include <iomanip>
# include <dos>
using namespace std;
int main()
{
int score;
char user_name[25];
char user_score[3];
ifstream infile;
infile.open("NAME_QUIZ.DAT", ios::in);
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
if(infile)
{
infile.get(user_name,25);
infile.ignore(80,'\n');
infile.get(user_score, 3);
infile.ignore(80, '\n');
score = atoi(user_score);
cout << user_name<< endl;
cout <<user_score<<endl;
getch();
}
else
{
cout << "ERROR!\n";
}
infile.close();
return 0;
}
I need to know how to make it loop instead of those if statements, and I need it to print the highest and lowest scores.
It's been a while since I've written any C++ but I know you can loop in a manner similar to this:
Code:#include<conio> #include<iostream> #include<iomanip> #include<fstream> #include<dos> using namespace std; int main() { int score; char user_name[25]; char user_score[3]; ifstream infile; infile.open("NAME_QUIZ.DAT", ios::in); while(infile) { infile.get(user_name,25); infile.ignore(80,'\n'); infile.get(user_score, 3); infile.ignore(80, '\n'); score = atoi(user_score); cout << user_name << endl; cout << user_score << endl; getch(); } infile.close(); return 0; }
Ok this is the finished bank program that I attached to the post. It works and does the things I wanted it to:
1. Withdraw from checking acc
2. Withdraw from Savings acc
3. deposit to checkings acc
4. deposit to savings acc
5. see your balance in checkings
6. see your balance in savings
7. quit
I have a pin number that is installed and it is 7410.
Now, I have to make data files of at least 5 customers using sequential access files. I have to put a name, a pin, a checking balance, and a savings balance of the customer. Where do I start.?
//Header files.
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
//prints out the textfile.
using namespace std;
ofstream outfile ("AtmUpdate.txt");
int pinnumber = 7410;
double checkbalance = 314.19;
double savebalance = 708.03;
struct ATM
{
char name[41];
int pinnumber2;
int option;
double withdrawlcheckingamount;
double withdrawlsavingsamount;
double depositsavingsamount;
double depositcheckingamount;
double depositsbalance;
double deposit;
double withdrawl;
double endingbalance;
};
ATM record;
void ProgramDescription(); //
int Get_pinnumber(); //
int Get_pinnumber1(); //
int Get_pinnumber2(); //
int Get_option(); //
int withdrawlC(); //
int withdrawlS(); //
int depositC(); //
int depositS(); //
int calcwithc(); //
int calcwiths(); //
int calcdepc(); //
int calcdeps(); //
int main()
{
ATM record;
ProgramDescription();
Get_pinnumber();
Get_option();
outfile.open("BANK.DAT",ios::app);
getch();
return 0;
}
//Program Description.
void ProgramDescription()
{
cout << "This program simulates an ATM machine.\n\n";
cout << "Welcome to Banks-O-Million.\n\n";
cout << "Please hit any key to continue.\n\n";
getch();
}
//Gets PIN number.
int Get_pinnumber()
{
system ("cls");
cout << "Please enter your 4 digit PIN number.\n";
cin >> record.pinnumber2;
if (pinnumber == record.pinnumber2)
{
cout << "You may move on to the next screen. Hit any key to get there." << endl;
getch();
}
else
{
cout << "You have entered the wrong PIN number. You have 2 more attempt(s) left. Please hit any key to get to the next screen and try again." << endl;
getch();
Get_pinnumber1();
}
}
//if they get it wrong, it goes here.
int Get_pinnumber1()
{
cout << "Please enter your 4 digit PIN number.\n";
cin >> record.pinnumber2;
if (record.pinnumber2 == pinnumber)
{
cout << "You may move on to the next screen. Hit any key to get to the next screen." << endl;
getch();
}
else
{
cout << "You have entered the wrong PIN number. You have one more attempt(s) left. Please hit any key to get to the next screen, and try again." << endl;
getch();
Get_pinnumber2();
}
}
//If they get it wrong again, it goes here.
int Get_pinnumber2()
{
cout << "Please enter your 4 digit PIN number.\n";
cin >> record.pinnumber2;
if (record.pinnumber2 == pinnumber)
{
cout << "You have entered the correct PIN number. Please hit any key to get to the next screen." << endl;
}
else
{
cout << "You have entered the wrong PIN number 3 times incorrectly. This ATM is now eating up your card.\a\a\a\a\a\a\a." << endl;
return 0;
}
}
//Gets their option for what they want to do.
int Get_option()
{
system ("cls");
cout << "What would you like to do today: \n";
cout << "Enter an option:\n\n";
cout << "1-Withdraw from your Checking account\n\n";
cout << "2-Withdraw from Savings account.\n\n";
cout << "3-Deposit to Checking account.\n\n";
cout << "4-Deposit to Savings account.\n\n";
cout << "5-See your balance in your checking account.\n\n";
cout << "6-See your balance in your savings account.\n\n";
cout << "7-Quit.\n\n";
cout << "Option: ";
cin >> record.option;
system ("cls");
//prints out atm option chosen.
switch (record.option)
{
//withdrawal from checking option.
case 1:
withdrawlC();
break;
//withdrawl from savings option.
case 2:
withdrawlC();
break;
//Deposit to checking account
case 3:
depositC();
break;
//Deposit to savings account.
case 4:
depositS();
break;
//See checking balance.
case 5:
cout << "You currently have $" << checkbalance << " in your checking account.\n";
cout << "Hit any key to end the program";
return 0;
break;
//See savings balance.
case 6:
cout << "You currently have $" << savebalance << " in your savings account.\n";
cout << "Hit any key to end the program";
return 0;
break;
//Quit.
case 7:
cout << "Thank you for using this ATM. Please hit any key to exit.";
return 0;
//All other cases, invalid
default:
cout << "\n";
cout << record.option;
cout << " is invalid. Please try again.";
Get_option();
}
}
int withdrawlC()
{
cout << "\nHow much do you wish to withdraw? ";
cin >> record.withdrawlcheckingamount;
calcwithc();
return 0;
}
int calcwithc()
{
double checkbalance = 314.19;
double savebalance = 708.03;
record.endingbalance = checkbalance - record.withdrawlcheckingamount;
cout << "\nYour new balance is: $";
cout << record.endingbalance;
}
int withdrawlS()
{
cout << "\nHow much do you wish to withdraw? ";
cin >> record.withdrawlsavingsamount;
calcwiths();
return 0;
}
int calcwiths()
{
double savebalance = 708.03;
record.endingbalance = savebalance - record.withdrawlsavingsamount;
cout << "\nYour new balance is: $";
cout << record.endingbalance;
return 0;
}
int depositC()
{
cout << "\nHow much do you wish to deposit? ";
cin >> record.depositcheckingamount;
calcdepc();
}
int calcdepc()
{
double checkbalance = 314.19;
record.endingbalance = checkbalance + record.depositcheckingamount;
cout << "\nNew balance: $";
cout << record.endingbalance;
return 0;
}
int depositS()
{
cout << "\nHow much do you wish to deposit? ";
cin >> record.depositsavingsamount;
calcdeps();
}
int calcdeps()
{
double savebalance = 708.03;
record.endingbalance = savebalance + record.depositsavingsamount;
cout << "\nNew balance: $";
cout << record.endingbalance;
return 0;
}
Last edited by Mr. Hid-Man; 05-01-2006 at 04:36 PM.