这次敲大作业感受良多,尽管是一个相对简单地题目(也许是我写的功能太少了...)
其中出现了很多很多的bug让我一度崩溃,各种逻辑错误层出不穷,通过反复请教度娘解决了产生bug的人后终于完成了。。
这次的C++代码使用单链表来存储,通过设置密码来限制访问。用结构体作为链表的结点,没有使用类的多态性主要是觉得没有必要。。。下面附上代码吧,把bug解决了之后还是很自豪的,希望毕业了能做个程序猿,工作个三五年之后回头看现在这个代码能好好地批评一顿现在的我,这么垃圾的代码写出来还自豪什么o(▼皿▼メ;)o
#include<iostream>
#include<string>
using namespace std;
struct account
{
int count; //编号
double data; //余额
account *next;
char name[20]; //帐号人姓名
char password[20]; //密码
};
#include<string>
using namespace std;
struct account
{
int count; //编号
double data; //余额
account *next;
char name[20]; //帐号人姓名
char password[20]; //密码
};
class ConsumerList
{
public:
ConsumerList();
~ConsumerList();
int Locate(); //按编号查找
char Get(); //按名字查找
void Add(); //入户
void Delete();
int PrintList(); //遍历所有人的信息
void Print(account *p);
int Deposit(account *p); //存款
int Withdrawal(account *p); //取款
private:
account *first;
int count;
};
{
public:
ConsumerList();
~ConsumerList();
int Locate(); //按编号查找
char Get(); //按名字查找
void Add(); //入户
void Delete();
int PrintList(); //遍历所有人的信息
void Print(account *p);
int Deposit(account *p); //存款
int Withdrawal(account *p); //取款
private:
account *first;
int count;
};
ConsumerList::ConsumerList()
{
first=new account;
first->next=NULL;
first->count=0;
first->data=0;
strcpy(first->name,"NULL");
strcpy(first->password,"0");
}
{
first=new account;
first->next=NULL;
first->count=0;
first->data=0;
strcpy(first->name,"NULL");
strcpy(first->password,"0");
}
ConsumerList::~ConsumerList()
{
account *q=NULL;
while(first!=NULL)
{
q=first;
first=first->next;
delete q;
}
}
{
account *q=NULL;
while(first!=NULL)
{
q=first;
first=first->next;
delete q;
}
}
void ConsumerList::Add()
{
double data;
char *p=new char[20];
{
double data;
char *p=new char[20];