上遇到错误undefined对“xxx”的引用,我和我的合作伙伴正在努力研究如何解决我们的代码中的错误。如果工程本科生和编程不完全是我们的专长,那么请把它放在我们身上。我继续在我的项目
对不起,如果我发送整个代码,但我很绝望,因为我们需要这个项目通过课程。谢谢。 这里是我的代码:
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <cctype>
#include <iomanip>
using namespace std;
struct baccount {
int pin;
char accholder[50];
int deposit;
void create_account();
void display_account() const;
void modify();
void depmoney(int);
void drawmoney(int);
void report() const;
int retpin() const;
int retdeposit() const;
};
void create_account()
{
struct baccount qeqe;
cout << "\nEnter Pin Number:";
cin >> qeqe.pin;
cout << "\n\nEnter your name : ";
cin.ignore();
cin.getline(qeqe.accholder, 50);
do {
cout << "\nEnter the initial amount to be stored in the account(Minimum P2000) : ";
cin >> qeqe.deposit;
} while (qeqe.deposit < 2000);
cout << "\n\n\nAccount Created..";
};
void display_account()
{
struct baccount qeqe;
cout << "\nPin Number: " << qeqe.pin;
cout << "\nAccount Holder Name : ";
cout << qeqe.accholder;
cout << "\nCurrent Balance : " << qeqe.deposit;
}
void depmoney(int x)
{
struct baccount qeqe;
qeqe.deposit += x;
}
void modify()
{
struct baccount qeqe;
cout << "\nPin Number : " << qeqe.pin;
cout << "\nModify Account Holder Name : ";
cin.ignore();
cin.getline(qeqe.accholder, 50);
cout << "\nModify Balance amount : ";
cin >> qeqe.deposit;
}
void drawmoney(int x)
{
struct baccount qeqe;
qeqe.deposit -= x;
}
void report()
{
struct baccount qeqe;
cout << qeqe.pin << setw(15) << " " << qeqe.accholder << setw(15) << " " << setw(8) << qeqe.deposit << endl;
}
int retpin()
{
struct baccount qeqe;
return qeqe.pin;
}
int retdeposit()
{
struct baccount qeqe;
return qeqe.deposit;
}
void write_account();
void display_sp(int);
void modify_account(int);
void delete_account(int);
void display_all();
void deposit_withdraw(int, int);
int main()
{
char choice;
int pnum;
do {
system("cls");
cout << "Welcome to Cutaran-Eleria Bank" << endl;
cout << "[1] Create new account" << endl;
cout << "[2] Deposit" << endl;
cout << "[3] Withraw" << endl;
cout << "[4] Show current balance" << endl;
cout << "[5] Check list of accounts" << endl;
cout << "[6] Remove an account" << endl;
cout << "[7] Edit an account" << endl;
cout << "[8] Exit Cutaran-Eleria Bank" << endl;
cout << "Please enter the command you want to do: " << endl;
cin >> choice;
system("cls");
switch (choice) {
case '1':
write_account();
break;
case '2':
cout << "\n\n\tEnter Pin Number: ";
cin >> pnum;
deposit_withdraw(pnum, 1);
break;
case '3':
cout << "\n\n\tEnter The account No. : ";
cin >> pnum;
deposit_withdraw(pnum, 2);
break;
case '4':
cout << "\n\n\tEnter The account No. : ";
cin >> pnum;
display_sp(pnum);
break;
case '5':
display_all();
break;
case '6':
cout << "\n\n\tEnter Pin Number : ";
cin >> pnum;
delete_account(pnum);
break;
case '7':
cout << "\n\n\tEnter Pin Number. : ";
cin >> pnum;
modify_account(pnum);
break;
case '8':
cout << "\n\nThank you for using Cutaran-Eleria Bank";
break;
default:
cout << "\a";
}
cin.ignore();
cin.get();
} while (choice != '8');
return 0;
}
void write_account()
{
struct baccount qeqe;
ofstream newrecord;
newrecord.open("accounts.dat", ios::binary | ios::app);
qeqe.create_account();
newrecord.write(reinterpret_cast<char*>(&qeqe), sizeof(baccount));
newrecord.close();
cout << "Your account is now saved into the system.";
}
void display_sp(int n)
{
baccount bankacc;
bool flag = false;
ifstream oldrecords;
oldrecords.open("accounts.dat", ios::binary);
if (!oldrecords) {
cout << "The account is not in the system";
return;
}
cout << "\nCurrent Balance\n";
while (oldrecords.read(reinterpret_cast<char*>(&bankacc), sizeof(baccount))) {
if (bankacc.retpin() == n) {
bankacc.display_account();
flag = true;
}
}
oldrecords.close();
}
void modify_account(int n)
{
bool found = false;
baccount acc;
fstream File;
File.open("accounts.dat", ios::binary | ios::in | ios::out);
if (!File) {
cout << "Unable to open account.";
return;
}
while (!File.eof() && found == false) {
File.read(reinterpret_cast<char*>(&acc), sizeof(baccount));
if (acc.retpin() == n) {
acc.display_account();
cout << "\n\nEnter The New Details of account" << endl;
acc.modify();
int pos = (-1) * static_cast<int>(sizeof(baccount));
File.seekp(pos, ios::cur);
File.write(reinterpret_cast<char*>(&acc), sizeof(baccount));
cout << "\n\n\t Record Updated";
found = true;
}
}
File.close();
if (found == false)
cout << "\n\n Record Not Found ";
}
void delete_account(int n)
{
baccount acc;
ifstream oldrecords;
ofstream newrecord;
oldrecords.open("accounts.dat", ios::binary);
if (!oldrecords) {
cout << "File could not be opened!!! Press any Key...";
return;
}
newrecord.open("Temp.dat", ios::binary);
oldrecords.seekg(0, ios::beg);
while (oldrecords.read(reinterpret_cast<char*>(&acc), sizeof(baccount))) {
if (acc.retpin() != n) {
newrecord.write(reinterpret_cast<char*>(&acc), sizeof(baccount));
}
}
oldrecords.close();
newrecord.close();
remove("accounts.dat");
rename("Temp.dat", "accounts.dat");
cout << "\n\nRecord Deleted ..";
}
void display_all()
{
baccount acc;
ifstream oldrecords;
oldrecords.open("accounts.dat", ios::binary);
if (!oldrecords) {
cout << "Unable to show accounts";
return;
}
cout << "\n\n\t\tList of Accounts\n\n";
cout << "Pin Number Name CurrentBalance\n";
while (oldrecords.read(reinterpret_cast<char*>(&acc), sizeof(baccount))) {
acc.report();
}
oldrecords.close();
}
void deposit_withdraw(int n, int option)
{
int amt;
bool found = false;
baccount acc;
fstream File;
File.open("accounts.dat", ios::binary | ios::in | ios::out);
if (!File) {
cout << "Unable to access the account.";
return;
}
while (!File.eof() && found == false) {
File.read(reinterpret_cast<char*>(&acc), sizeof(baccount));
if (acc.retpin() == n) {
acc.display_account();
if (option == 1) {
cout << "\n\nEnter The amount to be deposited";
cin >> amt;
acc.depmoney(amt);
}
if (option == 2) {
cout << "\n\nEnter The amount to be withdrawn";
cin >> amt;
int bal = acc.retdeposit() - amt;
if (amt > acc.retdeposit())
cout << "Insufficient balance";
else
acc.drawmoney(amt);
}
int pos = (-1) * static_cast<int>(sizeof(acc));
File.seekp(pos, ios::cur);
File.write(reinterpret_cast<char*>(&acc), sizeof(baccount));
cout << "\n\nRecord Updated";
found = true;
}
}
File.close();
if (found == false)
cout << "\n\n Record Not Found ";
}
你得到的* exact *错误信息是什么? (也就是说哪些名字是未定义的?) – NPE
等等,你知道'retpin'&'retdeposit'会返回垃圾值,因为你从每次调用这些函数时创建的未初始化的'struct baccount qeqe'返回数据吗? – ForceBru
另外,'create_account'就像没有任何方式绑定到结构一样无用。你应该把它叫做'baccount :: create_account'。该结构的作用与一个类相同。 – ForceBru