煤气管理系统一、任务和要求●实现对用户信息的录入●实现水电煤气数据的录入●计算并查询用户应缴费用●查询未缴纳费用名单二、分析本系统要求对于系统的录入与输出,考虑到有两中类型的人,所以设计了两个类一个类用来维护老师的数据,这个主要是考虑到两个数据的某些方面的不同,一个是对于他的所用电费水费的最低标准不同,第二个是考虑到后来可能其中有些的函数的使用和定义可能不同。
在这个程序中打算使用一个共同的基类。
这个类中维护的作为所有的两个类的共同的特征。
对于其中的数据结构打算使用链表的形式来实现因为这中间的好多功能基本上链表都能实现,包括对于其中的删除,增加节点,关于中间对于未缴费的情况可以使用标量flag来记录。
关于其中查询的使用strcmp来实现,通过两个字符串的量的比较实现。
如果这个节点中的数据与传递过来的数据匹配就输出这个数据。
主要的接口函数Student类的接口函数class student:public person{public:student();//构造函数将其中的sum值初始化为零,便于以后的判断。
void output();//输出所有的数据。
void input();//输入数据并进行一系列的计算。
包括sum值的计算。
int getflag();//找到相应的标量。
便于以后的判断。
int* getltime();//读取时间的指针。
后面的都是相同的作用。
获得所有数据的指针。
后面基本是想同的作用。
int* getntime();int* getldu();int* getndu();char* getname_1();char*getid_1();int* getsum();int* inputltime();int* inputntime();int* inputldu();int* inputndu();int* inputsum();char* inputname();char* inputid();static void ainput();private:int ltime[3];//时间数据。
其中包括年月日的信息。
下面的ntime是关于本次时间的录入信息。
int ntime[3];int ldu;//本次获得的度数。
int ndu;int flag;money tmoney;//money的数据类型包括其中的所有操作int sum;static int std_1;//整个类型的基准量};Teacher类的东西和student类的构成基本相同。
template <class T>class node{public:node<T> *getnext();//得到下一个节点void setnext(node<T>*pw);//将next数据赋值。
T *showdata();//得到T数据的指针。
void getdata(T*dj);//将数据输入。
private:node<T> *next;//下一个节点的指针。
T *data;//保存数据的指针。
在节点中只保存数据的指针而不对整个数据体进行维护。
};template <class T>class creatlink{private:node<T> *head,*tail;//保存首地址和尾址,为以后链表的制作和链表的操作提供条件。
int count;//总共的链表节点public:creatlink();void creat(T*pw);//链表的制作。
构造整个链表。
void del(node<T> *pw);//删除其中的某些符合条件的节点。
void find(char *name);//按照名字查找节点数据。
void show_1();void findnotenough();void listall();void creatfile(int dataflag);//将数据写入文件。
其中的参数是用来将判断数据如何写入,文件中的数据是属于哪个链表维护的。
void zhuanhuan(int integer,int&infer,char* chan);//将数字数据转换为字符数据方便写入文件。
int chanback(char* temp,int count);//将字符数据转换为数字数据方便维护。
void readfile(int cho);//读取文件。
};三、主要算法排序算法:在这个中间可以使用冒泡排序,使用count来统计节点的个数,然后使用冒泡排序的知识将中间的数据依次拷贝。
查找算法:遍历整个链表,然后对于中间的传过来的数据进行比较,找到需要的节点进行输出。
template <class T>void creatlink<T>::find(char *name){node<T>*pw;pw=head;T*temp;char*name_1;while(pw!=NULL)//遍历整个链表并比较其中的数据。
{temp=pw->showdata();//得到节点中维护的数据的指针。
通过指针访问所有的数据。
name_1=temp->getname();if(strcmp(name_1,name)==0)//比较是不是需要寻找到的数据,直到整个链表遍历完。
{temp->output();}pw=pw->getnext();//进入下一个节点。
}}删除操作:首先也是遍历整个链表,然后是对于正个链表中数据进行参数的匹配,如果找到相同的数据就进行节点的跳过。
P->next=p->next->next;跳过后面的节点。
template <class T>void creatlink<T>::del(node<T> *pw){node<T>*pj;pj=head;if(head==pw)//如果需要删除的首个节点,那么将首地址改写。
{head=head->getnext();}else{while(pj!=NULL){if(pj->getnext()==pw){pj->setnext(pw->getnext());//跳过需要删除的节点,}pj=pj->getnext();//如果不是继续向下寻找}}}添加数据:增加后面的节点,重新申请节点空间并将节点的插入到链表的后面实现数据的添加。
文件的读取:使用fstream库中的函数来实现。
Fwrite函数,在打开文件的时候使用ios::app的形式打开。
读取的时候使用get来读取,因为在写入文件的时候中间有可能要加入特殊的字符来标记是学生的信息还是老师的信息。
while((!file.eof())&&cho==1)///////********************************** *******判断是否已经到文件尾或者是程序需要读取哪些字段。
需要放在哪个类节点里面。
{getchar=file.get();if(getchar=='#')//数据的写入属于哪个类里面的。
数据的属于标志{if(getchar=='#'){getchar=file.get();//cout<<getchar<<endl;}pw=new T;//申请一块内存用来存放从文件中读取的数据。
count=0;while(getchar!=' ')//文件中是以空格的形式标记每个不同的数据的。
{name_1[count]=getchar;getchar=file.get();count++;}count_1=0;while(count_1<count){temp=pw->inputname();temp[count_1]=name_1[count_1];count_1++;}temp[count_1]='\0';制作字符串getchar=file.get();count=0;while(getchar!=' '){id_1[count]=getchar;getchar=file.get();count++;}id_1[count]='\0';count_1=0;while(count_1<count){temp=pw->inputid();temp[count_1]=id_1[count_1];count_1++;}temp[count_1]='\0';//cout<<pw->inputid()<<endl;count=0;getchar=file.get();while(getchar!=' '){temp_1[count]=getchar;getchar=file.get();count++;}temp_1[count]='\0';//cout<<temp_1<<endl<<count<<endl;temp_2=pw->getltime();temp_2[0]=chanback(temp_1,count);///将文件中的数据读取出来并将其重新转换为字符的变量。
count=0;getchar=file.get();while(getchar!=' '){temp_1[count]=getchar;getchar=file.get();count++;}temp_1[count]='\0';//cout<<temp_1<<endl<<count<<endl;temp_2=pw->getltime();temp_2[1]=chanback(temp_1,count);//同上面的程序的功能。
//cout<<temp_2[1];///一下的一些基本都和上面的是相同的程序的功能。
每个数据都是以空格为一个结尾的。
使得程序对于其中的读取简单些,避免读取到以后的数据。
count=0;getchar=file.get();while(getchar!=' '){temp_1[count]=getchar;getchar=file.get();count++;}temp_1[count]='\0';//cout<<temp_1<<endl<<count<<endl;temp_2=pw->getltime();temp_2[2]=chanback(temp_1,count);//count=0;getchar=file.get();while(getchar!=' '){temp_1[count]=getchar;getchar=file.get();count++;}temp_1[count]='\0';//cout<<temp_1<<endl<<count<<endl;temp_2=pw->getntime();temp_2[0]=chanback(temp_1,count);////cout<<temp_2[0];count=0;getchar=file.get();while(getchar!=' '){temp_1[count]=getchar;getchar=file.get();count++;}temp_1[count]='\0';//cout<<temp_1<<endl<<count<<endl; temp_2=pw->getntime();temp_2[1]=chanback(temp_1,count);//count=0;getchar=file.get();while(getchar!=' '){temp_1[count]=getchar;getchar=file.get();count++;}temp_1[count]='\0';//cout<<temp_1<<endl<<count<<endl; temp_2=pw->getntime();temp_2[2]=chanback(temp_1,count);//count=0;getchar=file.get();while(getchar!=' '){temp_1[count]=getchar;getchar=file.get();count++;}temp_1[count]='\0';//cout<<temp_1<<endl<<count<<endl; temp_2=pw->getldu();*temp_2=chanback(temp_1,count);//count=0;getchar=file.get();while(getchar!=' '){temp_1[count]=getchar;getchar=file.get();count++;}temp_1[count]='\0';//cout<<temp_1<<endl<<count<<endl;temp_2=pw->getndu();*temp_2=chanback(temp_1,count);//creat(pw);}else{continue;//如果没有满足条件那么向后面读取。