首页 > 代码库 > C++数据结构课程设计报告(1号题)【物联网1132-11】

C++数据结构课程设计报告(1号题)【物联网1132-11】

#include<iostream>
#include<fstream>
using namespace std;
const int m=100; //定义常量m
class BankStore
{
private:
	int banknumber;   //银行账号
	char name[20];  //人名
	double inputprice;  //存入金额
	int income;  //收入金额
	int charge;  //支出金额
	int tradeAmount;  //当前交易(或办理业务)次数
	int amount;
public:
	void Input();
	int Input_2();
	void Dig();
	void changeMessage();
	void Search_banknumber();
	void Search_name();
	void Show();
	void DeleteAccount();
}people[m];

void BankStore::Input()
{
	int i,n;
	cout<<"来了开户的客户的数目:";
	cin>>amount;
	cout<<endl;
	for(i=0;i<amount;i++)
	{
		cout<<"这是第"<<(i+1)<<"客户的信息"<<endl;
		people[i].banknumber=i+1;
		cout<<"客户的名字:";
		cin>>people[i].name;
		cout<<"一次性存入的金额:";
		cin>>people[i].inputprice;
		cout<<"收入:";
		cin>>people[i].income;
		cout<<"支出:";
		cin>>people[i].charge;
		cout<<endl;
	}
	cout<<"\n这些客户的信息如下:"<<endl;
	for(i=0;i<amount;i++)
	{
		cout<<"客户的信息:"<<people[i].banknumber<<ends;
		cout<<"客户的名字:"<<people[i].name<<ends;
		cout<<"一次性存入的金额:"<<people[i].inputprice<<ends;
		cout<<"收入:"<<people[i].income<<ends;
		cout<<"支出:"<<people[i].charge<<ends<<endl;
	}
	ofstream os("people.txt",ios_base::out|ios_base::binary);  //创建、打开文件
	for(n=0;n<amount;n++)
	{
		os.write( reinterpret_cast<char*>(&(people[n])),sizeof(BankStore) );  //导出文件
	}
	os.close();  //关闭文件
}

int BankStore::Input_2()  //文件读入
{

	int i,n;
	ifstream is("people.txt",ios_base::in|ios_base::binary);
	if(!is)
	{
		cout<<"打开失败"<<endl;
		return 0;
	}
	for(i=0;is.read( reinterpret_cast<char *>(people+i) , sizeof(BankStore) );i++)
	amount=i;
	cout<<"当前操作过的客户的信息:"<<endl;
	for(n=0;n<amount;n++)
	{
		cout<<"客户的信息:"<<people[i].banknumber<<ends;
		cout<<"客户的名字:"<<people[i].name<<ends;
		cout<<"一次性存入的金额:"<<people[i].inputprice<<ends;
		cout<<"收入:"<<people[i].income<<ends;
		cout<<"支出:"<<people[i].charge<<ends<<endl;
	return 1;
}

void BankStore::Dig()
{
	int i,n,m;
	cout<<"请输入后来的客户的人数:";
	cin>>n;
	cout<<endl;
	for(i=0;i<n;i++)
	{
		cout<<"这是第"<<(i+1)<<"客户的信息"<<endl;
		people[amount+i].banknumber=amount+i+1;
		cout<<"客户的名字:";
		cin>>people[amount+i].name;
		cout<<"一次性存入的金额:";
		cin>>people[amount+i].inputprice;
		cout<<"收入:";
		cin>>people[amount+i].income;
		cout<<"支出:";
		cin>>people[amount+i].charge;
		cout<<endl;
	}
	cout<<"\n这些客户的信息如下"<<endl;
	for(i=0;i<amount+n;i++)
	{
		cout<<"客户的信息:"<<people[i].banknumber<<ends;
		cout<<"客户的名字:"<<people[i].name<<ends;
		cout<<"一次性存入的金额:"<<people[i].inputprice<<ends;
		cout<<"收入:"<<people[i].income<<ends;
		cout<<"支出:"<<people[i].charge<<ends<<endl;
	}
	amount=amount+n;
	ofstream os("people.txt",ios_base::out|ios_base::binary);  //创建、打开文件
	for(m=0;m<amount;m++)
	{
		os.write( reinterpret_cast<char*>(&(people[m])),sizeof(BankStore) );  //导出文件
	}
	os.close();  //关闭文件
}

void BankStore::changeMessage()  //办理(交易开始)信息
{
	int n,i,m;
	cout<<"第几个客户想要办理业务(输入客户账号):";
	cin>>n;
	cout<<endl;
	cout<<"请输入修改的信息"<<endl;
	cout<<"客户名字:";
	cin>>people[n-1].name;
	cout<<"实时存款余量:";
	cin>>people[n-1].inputprice;
	cout<<"收入了多少钱:";
	cin>>people[n-1].income;
	cout<<"花费了多少钱:";
	cin>>people[n-1].charge;
	cout<<endl;
	cout<<"办理业务后的客户信息:"<<endl;
	people[n-1].tradeAmount++;
	for(i=0;i<amount;i++)
	{
		cout<<"客户的信息:"<<people[i].banknumber<<ends;
		cout<<"客户的名字:"<<people[i].name<<ends;
		cout<<"一次性存入的金额:"<<people[i].inputprice<<ends;
		cout<<"收入:"<<people[i].income<<ends;
		cout<<"支出:"<<people[i].charge<<ends<<endl;
	}
	ofstream os("people.txt",ios_base::out|ios_base::binary);  //创建、打开文件
	for(m=0;m<amount;m++)
	{
		os.write( reinterpret_cast<char*>(&(people[m])),sizeof(BankStore) );  //导出文件
	}
	os.close();  //关闭文件
}

void BankStore::Search_banknumber()  //按账号查
{
	int n;
	cout<<"请输入客户账号:(查询按次算,每次一个)";
	cin>>n;
	cout<<endl;
	if(n<=amount)
	{
		cout<<"客户的信息:"<<people[i].banknumber<<ends;
		cout<<"客户的名字:"<<people[i].name<<ends;
		cout<<"一次性存入的金额:"<<people[i].inputprice<<ends;
		cout<<"收入:"<<people[i].income<<ends;
		cout<<"支出:"<<people[i].charge<<ends<<endl;
	}
	cout<<"查询结束或者输入错误,请选择:"<<endl;
	cout<<"1、再次查询(可以换方式噢)。2、回到主菜单。"<<endl;
}

void BankStore::Search_name()  //按客户名字查
{
	int i;
	char x[20];
	cout<<"请输入客户的名字:(查询按次算,每次一个)";
	cin>>x;
	cout<<endl;
	for(i=0;i<amount;i++)
	{
		if(strcmp(people[i].name,x)==0) //strcmp 用来比较字符串.tname和x
		{
			cout<<"客户的信息:"<<people[i].banknumber<<ends;
			cout<<"客户的名字:"<<people[i].name<<ends;
			cout<<"一次性存入的金额:"<<people[i].inputprice<<ends;
			cout<<"收入:"<<people[i].income<<ends;
			cout<<"支出:"<<people[i].charge<<ends<<endl;
		}
	}
	cout<<"查询结束或者输入错误,请选择:"<<endl;
	cout<<"1、再次查询(可以换方式噢)。2、回到主菜单。"<<endl;
}

void BankStore::Show()  //显示信息
{
	int i;
	for(i=0;i<amount;i++)
	{
		cout<<"客户的信息:"<<people[i].banknumber<<ends;
		cout<<"客户的名字:"<<people[i].name<<ends;
		cout<<"一次性存入的金额:"<<people[i].inputprice<<ends;
		cout<<"收入:"<<people[i].income<<ends;
		cout<<"支出:"<<people[i].charge<<ends<<endl;
	}
}

void BankStore::DeleteAccount()
{
	char y[20];
	int n,m;
	cout<<"前来销户的客户的名字:";
	cin>>y;
	for(int i=0;i<amount;i++)
	{
		if(strcmp(people[i].name,y)==0)//strcmp 用来比较字符串.tname和y
		{
			for(;i<amount;i++)
			{
				people[i]=people[i+1];
				people[i].num=i+1;
			}
			amount=amount-1; 
		}
	}
	cout<<"删除后客户的总信息有:"<<endl;
	for(m=0;m<amount;m++)
	{
		cout<<"客户的信息:"<<people[i].banknumber<<ends;
		cout<<"客户的名字:"<<people[i].name<<ends;
		cout<<"一次性存入的金额:"<<people[i].inputprice<<ends;
		cout<<"收入:"<<people[i].income<<ends;
		cout<<"支出:"<<people[i].charge<<ends<<endl;
	}
	ofstream os("people.txt",ios_base::out|ios_base::binary);  //创建、打开文件
	for(n=0;n<amount;n++)
	{
		os.write( reinterpret_cast<char*>(&(people[n])),sizeof(BankStore) );  //导出文件
	}
	os.close();  //关闭文件
}

void Clear()  //清屏函数
{
	char a;
	a=getchar();
	system("cls");
}

void menuPrint()  //主菜单
{
	cout<<"\t***** Tin's Bank *****"<<endl;
	cout<<"\t*   1.    开户       *"<<endl;
	cout<<"\t*   2.查询客户信息   *"<<endl;
	cout<<"\t*   3.显示客户信息   *"<<endl;
	cout<<"\t*   4.显示交易频率   *"<<endl;
	cout<<"\t*   5.    销户       *"<<endl;
	cout<<"\t*   6.  退出系统     *"<<endl;
	cout<<"\t*7.刷屏一次而且不退出*"<<endl;
	cout<<"\t**********************"<<endl;
	cout<<"请输入你要进行的操作(1~7):"<<endl;
}



int main()  //主函数
{
	BankStore tin;  //定义对象
	int n;
	do
	{
		menuPrint();  //调用主菜单
		cin>>n;
		cout<<endl;
		switch(n)
		{
		case 1:  //开户
			{
				int a;
				cout<<"  输入方式"<<endl;
				cout<<"1.开户"<<endl;
				cout<<"2.导入客户信息"<<endl;
				cout<<"3.加户"<<endl;
				cout<<"4.交易(修改)"<<endl;
				cout<<"5.返回主菜单"<<endl;
				cin>>a;
				cout<<endl;
				switch(a)
				{
				case 1:  //调用创建函数
					people.Input();
					break;
				case 2:  //调用文件读入函数
					people.Input_2();
					break;
				case 3:  
					people.Dig();
					break;
				case 4:  
					people.changeMessage();
					break;
				case 5:
					break;
				default:
					cout<<"您的输入有误,请重新选择"<<endl;
					break;
				}
				break;
			}
		case 2:  //查询
			{
				int a;
				cout<<"  查询方式"<<endl;
				cout<<"1.按账号查询"<<endl;
				cout<<"2.按客户名字查询"<<endl;
				cout<<"3.返回主菜单"<<endl;
				cin>>a;
				cout<<endl;
				switch(a)
				{
				case 1:  
					people.Search_banknumber();
					int f;
					cin>>f;
					switch(f)
					{
					case 1:
						people.Search_name();
					break;
					case 2:
						cout<<"请搞清楚了再查询,谢谢!"<<endl;
						cout<<endl;
					break;
					}	
					break;
				case 2:  //调用函数(按货名查)
					people.Search_name();
					int o;
					cin>>o;
					switch(o)
					{
					case 1:
						people.Search_name();
					break;
					case 2:
						cout<<"请搞清楚了再查询,谢谢!"<<endl;
						cout<<endl;
					break;
					}
					break;
				case 3:
					break;
				default:
					cout<<"您的输入有误,请重新选择"<<endl;
					break;
				}
				break;
			}
		case 3:  //显示
			people.Show();
			break;
		case 4:
			cout<<"要看哪个客户的交易频率:(输入客户账号)"<<endl;
			cin>>k;
			cout<<people[k].tradeAmount<<"次"<<endl;
			break;
		case 5:  //删除信息
			people.DeleteAccount();
			break;
		case 6:  //退出
			exit(0);
			break;
		case 7:
			Clear();
			break;
		default:
			cout<<"您的输入有误,请重新选择"<<ends;
			break;
		}
	}while(1);
	return 0;
}
看来要大修整了,这个程序是不可以交差的。哈哈,我努力。

C++数据结构课程设计报告(1号题)【物联网1132-11】