⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rememberthemoney.txt

📁 本软件用于电信计费
💻 TXT
字号:
	#include <iostream.h>
	#include <fstream.h>
	#include <string.h>
	#include <iomanip.h>
	#define monthcost 25
	#define functionhcost 6
	int	compute(char btime[30],char etime[30]);
	double judgecost(char callto[30], int stime);
	void list(char c,char *number,char *peoplename,char *peoplename1,int mc,int fc,double ic,double lc);
	void save(char c1,char *number1,char *peoplename1,char *peoplename2,int mc1,int fc1,double ic1,double lc1);
	void openfile();
	struct orgcall                                  //话单文件
	{
		char from[30];
		char to[30];
		char btime[30];
		char etime[30];
	}orgcalllist[100];
	struct people                                  //用户资料
	{
		char name[20];
		char name1[20];
		char number[20];
		char ch;
		double longcost1;
		double incost1;
	}peopleinformation[100];
	main()                                          //主函数
	{
		int line1=0,i=0;
		ifstream f1("date2.txt");
		if(!f1)
		{
			cout<<"fail to open file"<<endl;
		}
		while(!f1.eof())
		{
			f1>>orgcalllist[i].from>>orgcalllist[i].to>>orgcalllist[i].btime>>orgcalllist[i].etime;
			line1++;
			i++;
		}
		for(i=0;i<=line1;i++)
		{
			cout<<orgcalllist[i].from<<"  "<<orgcalllist[i].to<<"  "<<orgcalllist[i].btime<<"   "<<orgcalllist[i].etime<<endl;
		}
		f1.close();
		int line2=0,j=0;
		ifstream f3("date1.txt");
		if(!f3)
		{
			cout<<"fail to open file"<<endl;
		}
		while(!f3.eof())
		{
			f3>>peopleinformation[j].name>>peopleinformation[j].name1>>peopleinformation[j].number>>peopleinformation[j].ch;
			j++;
			line2++;
		}
		for(j=0;j<=line2;j++)
		{	
			cout<<peopleinformation[j].name<<"  "<<peopleinformation[j].name1<<"  "<<peopleinformation[j].number<<"  "<<peopleinformation[j].ch<<endl;
		}
		f3.close();
		int flag=1;
		int n;
		int spendtime[30];
		double longcost[30],incost[30];
		for(i=0;i<=line1;i++)
		{		
			peopleinformation[i].longcost1=0;
			peopleinformation[i].incost1=0;
		}
		while(flag)                                //输出用户选择界面
		{
		
			cout<<"---------------------------------欢迎进入系统----------------------------------"<<endl;
			cout<<"                                   菜单 "<<endl;
			cout<<"                                  0 计算"<<endl;
			cout<<"                                  1 打表"<<endl;
			cout<<"                                  2 保存"<<endl;
			cout<<"                                  3 退出"<<endl;
			cout<<"请输入你的选择:"<<endl;
			cin>>n;
		switch(n)
		{
		case 0:
			for(i=0;i<=line1;i++)
			{
				spendtime[i]=compute(orgcalllist[i].btime,orgcalllist[i].etime);
				if(strlen(orgcalllist[i].to)<9)
				{
					incost[i]=judgecost(orgcalllist[i].to,spendtime[i]);
					longcost[i]=0;
				}
				if(strlen(orgcalllist[i].to)>9)
				{
					longcost[i]=judgecost(orgcalllist[i].to,spendtime[i]);
					incost[i]=0;
				}
			}
			for(i=0;i<=line1;i++)
			{
				for(j=0;j<=line1;j++)
				{
					if(strcmp(peopleinformation[i].number,orgcalllist[j].from)==0)
					{
						peopleinformation[i].longcost1=peopleinformation[i].longcost1+longcost[j];
						peopleinformation[i].incost1=peopleinformation[i].incost1+incost[j];
					}
				}
			}
			cout<<"---------------------------------计算完毕--------------------------------------"<<endl;
			cout<<endl;
			cout<<endl;
			cout<<endl;
			break;
		case 1:
			cout<<"电话号码"<<setw(15)<<"用户姓名"<<setw(10)<<"月租费"<<setw(10)<<"功能费"<<setw(12)<<"市内电话费"<<setw(12)<<"长途电话费"<<setw(8)<<"合计"<<endl;
			for(i=0;i<=line1-1;i++)
			{
				list(peopleinformation[i].ch,peopleinformation[i].number,peopleinformation[i].name,peopleinformation[i].name1,monthcost,functionhcost,peopleinformation[i].incost1,peopleinformation[i].longcost1);
			}
			break;
		case 2:
			openfile();                               //调用函数在文件中打印头表
			for(i=0;i<=line1;i++)
			{
				save(peopleinformation[i].ch,peopleinformation[i].number,peopleinformation[i].name,peopleinformation[i].name1,monthcost,functionhcost,incost[i],longcost[i]);
			}
			cout<<"--------------------------------保存完毕--------------------------------------"<<endl;
			cout<<"------------------------------已存入文件test----------------------------------"<<endl;
			cout<<endl;
			cout<<endl;
			cout<<endl;
			break;
		default:
			cout<<"---------------------------------谢谢使用本次程序软件--------------------------"<<endl;
			flag=0;
			break;
		}
		}
		return 0;
	}
	int	compute(char btime[30],char etime[30])                  //计算通话时间函数
	{
		int eyear,byear;                                        //年
		int emonth,bmonth;                                       //月
		int eday,bday;                                           //日
		int ehour,bhour;                                         //时
		int eminute,bminute;                                      //分
		int esecond,bsecond;                                     //秒
		eyear=(int)etime[3]-48;
		byear=(int)btime[3]-48;                                         //计算年月日时分秒的值
		emonth=(int)etime[4]*10-480+(int)etime[5]-48;
		bmonth=(int)btime[4]*10-480+(int)btime[5]-48;
		eday=(int)etime[6]*10-480+(int)etime[7]-48;
		bday=(int)btime[6]*10-480+(int)btime[7]-48;
		ehour=(int)etime[8]*10-480+(int)etime[9]-48;
		bhour=(int)btime[8]*10-480+(int)btime[9]-48;
		eminute=(int)etime[10]*10-480+(int)etime[11]-48;
		bminute=(int)btime[10]*10-480+(int)btime[11]-48;
		esecond=(int)etime[12]*10-480+(int)etime[13]-48;
		bsecond=(int)btime[12]*10-480+(int)btime[13]-48;
		int daynumber;                                             //判断月所有天数
		switch(bmonth)                                                  //判断各月天数
			{
			case 1:
			case 3:
			case 5:
			case 7:
			case 8:
			case 10:
			case 12:
				daynumber= 31;
				break;
			case 4:
			case 6:
			case 9: 
			case 11:
				daynumber = 30;
				break;
			case 2:
				if( (byear % 4 == 0 && byear % 100 != 0 )||(byear % 400 == 0))
					daynumber = 29;
				else
					daynumber = 28;
				break;
		}
		int day,hour,minute,second,year,month;	
		year=eyear-byear;
		month=emonth-bmonth;
		day=eday-bday;
		hour=ehour-bhour;
		minute=eminute-bminute;
		second=esecond-bsecond;
		if (second < 0)
			{
				second = second + 60;
				minute = minute - 1;
			}
			if (minute < 0)
			{
				minute = minute + 60;
				hour = hour - 1;
			}
			if (hour < 0)
			{
				hour = hour + 24;
				day = day - 1;
			}
			if (day < 0)
			{
				day = day + daynumber;
				month = month - 1;
			}
			if (month < 0 )
			{
				month = month + 12;
				year = year - 1;
			}
	      int spendtime;
		  if(second==0)
		  {
			  spendtime=day*24*60+hour*60+minute;
		  }
		  else
		  {
			  spendtime=day*24*60+hour*60+minute+1;
		  }
			return spendtime;
	}
	double judgecost(char callto[30],int stime)                 //计算通话费用函数
	{
		double cost;
		if(strlen(callto)>9)                                    //判断是否为长途
		{
			cost=stime*0.7;                            
		}
		else
		{
			cost=stime*0.1;                                     //市内电话
		}
		return cost;
	}
	void list(char c,char *number,char *peoplename,char *peoplename1,int mc,int fc,double ic, double lc)
	{
		double sum;                                    //输出列表函数,打印在屏幕上
		if(c=='Y')
		{
			sum=mc+fc+lc+ic;
			cout<<setiosflags(ios::left)<<number<<"   "<<setw(5)<<peoplename<<" "<<setw(12)<<peoplename1<<setw(10)<<mc<<setw(8)<<fc<<setw(12)<<ic<<setw(12)<<lc<<setw(12)<<sum<<endl;
		}
		if(c=='N')
		{
			sum=mc+lc+ic;
			cout<<number<<"   "<<setw(5)<<peoplename<<" "<<setw(12)<<peoplename1<<setw(10)<<mc<<setw(8)<<"0"<<setw(12)<<ic<<setw(12)<<lc<<setw(12)<<sum<<endl;
		}
	}
	void save(char c1,char *number1,char *peoplename1,char *peoplename2,int mc1,int fc1,double ic1,double lc1)
	{
		double sum;
		if(c1=='Y')                      //存入文件函数,文件名为"test.txt"
		{
			sum=mc1+fc1+lc1;
			ofstream fs;
			if(!fs)
			{
				cout<<"fail to open file"<<endl;
			}
			fs.open("test.txt",ios::app);
			fs<<number1<<"   "<<setw(5)<<peoplename1<<" "<<setw(7)<<peoplename2<<setw(10)<<mc1<<setw(8)<<fc1<<setw(12)<<ic1<<setw(12)<<lc1<<setw(12)<<sum<<endl;
			fs.close();
		}
		if(c1=='N')
		{
			sum=mc1+lc1+ic1;
			ofstream fs;
			if(!fs)
			{
				cout<<"fail to open file"<<endl;
			}
			fs.open("test.txt",ios::app);
			fs<<number1<<"   "<<setw(5)<<peoplename1<<" "<<setw(7)<<peoplename2<<setw(10)<<mc1<<setw(8)<<"0"<<setw(12)<<ic1<<setw(12)<<lc1<<setw(12)<<sum<<endl;
			fs.close();
		}
	}
	void openfile()                                          //在文件中打出头表,文件名为"test.txt"
	{
		ofstream ft("test.txt");
		if(!ft)
		{
			cout<<"fail to open file"<<endl;
		}
		ft<<"电话号码"<<setw(15)<<"用户姓名"<<setw(12)<<"月租费"<<setw(10)<<"功能费"<<setw(12)<<"市内电话费"<<setw(12)<<"长途电话费"<<setw(8)<<"合计"<<endl;
		ft.close();
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -