您的位置:首页 > 其它

大二课程设计(题目1)

2015-01-11 23:16 288 查看
题目 1.小明是一个计算机专业top
student,祝贺他毕业了。并准备到银行参加工作。上班第一天,经理叫他编制一个实现一个活期储蓄处理程序,算作考查。上班第一天, 一定要给领导一个好印象,小明二话没说,就答应了。现要你是小明了,请完成如下题目功能。储户开户、销户、存入、支出活动频繁,系统设计要求:(1)能比较迅速地找到储户的帐户,以实现存款、取款记账;

(2)能比较简单,迅速地实现插入和删除,以实现开户和销户的需要。
小明需要编写的活期储蓄处理程序具有以下功能:
1 储户开户和销户
2 余额和资料查询
3存款和取款
4存款和取款记录(加载中..............)
运用的知识点:
采用线性表的逻辑结构和单链表的存储结构,采用C++中的类和结构体。
设计思路
定义一个银行管理系统的类,类里包含开户、销户、存款、取款等函数;各函数采用单链表的方法进行运算;其中,处理存款不需要进行密码认证外,其余销户、取款等需要进行密码认证。
头文件:
#ifndef TheBank_H
#define TheBank_h
#include <string.h>
#include<iostream>
using namespace std;
struct Yonghu
{
string Name;//用户名
string Tel;//用户电话
string ID;//用户身份证
string Zhanghao;//用户账号
unsigned int Mima;//密码
float Yue;//余额
Yonghu*next;
};
class TheBank//银行类
{
public:
TheBank();//构造函数
~TheBank(){};//析构函数
void Kaihu();//开户函数
void Cunkuan(int j);//存款函数
void Qukuan(int k);//取款函数
void Show(int i);//界面函数
void Del(int i);//销户函数
int Chaxun(string s);//查询函数
private:
Yonghu *first;
};
#endif

类:
#include "TheBank.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
TheBank::TheBank()
{
first=new Yonghu;
first->next=NULL;
}
void TheBank::Kaihu()//开户函数
{
Yonghu *p=new Yonghu;
p=first;
while(p->next!=NULL)
{
p = p->next;
}
Yonghu *s=new Yonghu;
cout<<"\t开始填写账户资料:"<<endl;
cout<<"\t      姓名:";
cin>>s->Name;
cout<<"\t身份证号码:";
cin>>s->ID;
cout<<"\t  电话号码:";
cin>>s->Tel;
cout<<"\t      账号:";
cin>>s->Zhanghao;
cout<<"\t      密码:";
cin>>s->Mima;
cout<<"\t      存款:";
cin>>s->Yue;
s->next = p->next;
p->next =s;
}
void TheBank::Del(int i)//销户函数
{
Yonghu *p=first;
int count = 0;
while(p!=NULL&&count<i-1)
{
p = p->next;
count++;
}
if(p == NULL || p->next == NULL)throw"位置错误";
else
{
Yonghu *q=new Yonghu;
q = p->next;
p->next = q->next;
delete q;
}
}
void TheBank::Cunkuan(int j)//存款函数
{
Yonghu *p = first;
int count=0;
while(p!=NULL&&count<=j-1)
{
p = p->next;
count++;
}
cout<<"姓名:"<<p->Name<<endl;
cout<<"账号:"<<p->Zhanghao<<endl;
double Money;
cout<<"请输入要存入的金额:";
cin>>Money;
p->Yue = p->Yue+Money;
}
void TheBank::Qukuan(int k)//取款函数
{
Yonghu *p = first;
int count = 0;
while(p !=NULL&&count <= k - 1)
{
p = p->next;
count++;
}
cout<<"姓名:"<< p->Name<<endl;
cout<<"账号:"<< p->Zhanghao<<endl;
unsigned int Mima;
cout<<"请输入账户密码:";
cin>>Mima;
cout<<endl;
if(p->Mima==Mima)
{
double Money;
cout<<"请输入取出金额:";
cin>>Money;
p->Yue=p->Yue-Money;
}
else cout<<"密码错误!";
}
void TheBank::Show(int i)//界面函数
{
Yonghu *p=first;
int count=0;
while(p!=NULL&&count<=i-1)
{
p=p->next;
count++;
}
cout<<"姓名:"<<p->Name<<endl;
cout<<"账号:"<<p->Zhanghao<<endl;
cout<<"身份证:"<<p->ID<<endl;
cout<<"电话:"<<p->Tel<<endl;
cout<<"账户余额:"<<p->Yue<<endl;
system("pause");
}
int TheBank::Chaxun(string s)//查询函数
{
Yonghu *p;
p=first->next;
int count=1;
while(p!=NULL)
{
if(s==p->Name)
return count;
p=p->next;
count++;
}
return 0;
}
主函数:
#include<iostream>
#include"TheBank.h"
#include<iomanip>
#include<cstdlib>
#include<string>
using namespace std;

void Show1();
int main()
{
system("color F0");
TheBank A;
short sel;
while(1)
{
Show1();//操作界面函数
cout<<"请输入选项:";
cin>>sel;
switch(sel)
{
case 0://退出系统
char w;
cout<<"确定退出系统?(Y/N)";
cin>>w;
if(w=='Y'||w=='y')
{
cout<<"已退出"<<endl;
system("pause");
return 0;
}
else
cout<<"取消退出";
break;
case 1://开户
A.Kaihu();
break;

case 2://存款
{
cout<<"请输入姓名:";
string s1;
cin>>s1;
int j;
j=A.Chaxun(s1);
if (j==0)
{
cout<<"您输入的名字错误!";
system("pause");
break;
}
else
{
A.Cunkuan(j);
break;
}
}
case 3://取款
{
cout<<"请输入姓名:";
string s2;
cin>>s2;
int k;
k=A.Chaxun(s2);
if(k==0)
{
cout<<"您输入的名字错误!";
system("pause");
break;
}
else
{
A.Qukuan(k);
break;
}
}
case 4://查询
{
cout<<"请输入姓名:";
string s3;
cin>>s3;
int i;
i=A.Chaxun(s3);
if(i==0)
{
cout<<"您输入的名字错误!";
system("pause");
break;
}
else
{
A.Show(i);
break;
}
}
case 5://销户
{
int a;
string h;
cout<<"请输入姓名:"<<endl;
cin>>h;
a=A.Chaxun(h);
if(a==0)
{
cout<<"您输入的姓名错误!"<<endl;
system("pause");
break;
}
else
{
A.Show(a);
cout<<"请确认是否删除?(Y/N)";
char sel_1;
cin>>sel_1;
if(sel_1=='Y'||sel_1=='y')
{
A.Del(a);
break;
}
else
{
break;
}
}
}
default:
cout<<"输入错误,请重新输入!"<<endl;
break;
}
}
return 0;
}

void Show1()//操作界面函数
{
system("cls");
cout<<"\t********银行管理系统********"<<endl;
cout<<endl;
cout<<"\t***       1--开户---     ***"<<endl;
cout<<endl;
cout<<"\t***       2--存款---     ***"<<endl;
cout<<endl;
cout<<"\t***       3--取款---     ***"<<endl;
cout<<endl;
cout<<"\t***       4--查询---     ***"<<endl;
cout<<endl;
cout<<"\t***       5--销户---     ***"<<endl;
cout<<endl;
cout<<"\t**********0--退出---********"<<endl;
cout<<endl;
cout<<"\t\t请选择操作:(0--5)"<<endl;

}


各功能操作截图如下:

















课程设计心得:
由于大一的C++面向对象设计学得不够扎实,所有在编辑过程中经常遇到一些定义问题或者是函数的调用问题,经过将近一星期的努力,终于大致明白了。在对单链表的存储结构进行实现时,只能仿照着书本和实验的课本推敲,无法快速地实现心中所想的方法。经常还会遇到指针指代混乱等问题。感觉我还没有正式踏入C++编程的大门,现在我真心希望能更深入地了解C++。很庆幸能在大二遇到明哥你,让我对这门课程又重新燃起了希望,真心谢谢,希望以后能够多多交流。起步比别人慢,就要更加地努力,笨鸟先飞!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: