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

📄 现金处理系统.txt

📁 个人财务管理的一个小程序
💻 TXT
字号:
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
class moneystring
{
private:
	long double amount;
	long integer;
	float fraction;
	char amountstr[30];
	char fracstr[10];
private:
	void format();
	void insertcomma();
public:
	moneystring();
	moneystring(long double);
	void newvalue(long double);
	void display()
	{
		cout<<amountstr;
	}
	moneystring operator-(moneystring&money)
	{
		amount=amount-money.amount;
		return moneystring(amount);
	}
	moneystring operator+(moneystring&money)
	{
		amount=amount+money.amount;
		return moneystring(amount);
	}
	moneystring operator*(float x)
	{
		float s=amount*x;
		return moneystring(s);
	}
};
moneystring::moneystring()
{
	amount=0;
	integer=0;
	fraction=0.0;
	for(int i=0;i<=30;i++)
	{
		amountstr[i]='\0';
	}
	for(int j=0;j<=10;j++)
	{
		fracstr[10]='\0';
	}
}
moneystring::moneystring(long double cash)
{
	amount=cash;
	integer=floor(cash);
	fraction=cash-integer;
	for(int i=0;i<=30;i++)
	{
		amountstr[i]='\0';
	}
	for(int j=0;j<=10;j++)
	{
		fracstr[10]='\0';
	}
	format();
}
void moneystring::newvalue(long double cash)
{
	amount=cash;
	integer=floor(cash);
	fraction=cash-integer;
	for(int i=0;i<=30;i++)
	{
		amountstr[i]='\0';
	}
	for(int j=0;j<=10;j++)
	{
		fracstr[10]='\0';
	}
	format();
}
void moneystring::format()
{
	ltoa(integer,amountstr,10);
	amountstr[strlen(amountstr)]='.';
	fraction*=100;
	ltoa(fraction,fracstr,10);
	strcat(amountstr,fracstr);
	insertcomma();
}
void moneystring::insertcomma()
{
	int count=0;
	int counter=1;
	while(amountstr[count]!='.')
	{
		count++;
	}
	while(count>0)
	{
		if((count==3)&&(amountstr[count-1]!='.')&&(count!=1))
		{
			count--;
		for(int i=strlen(amountstr);i>=count;i--)
		{
			amountstr[i+1]=amountstr[i];
		}
		amountstr[count]=',';
		counter=1;
		}
		count--;
		if(count==3)counter=1;
		else counter++;
	}
}
void main()
{
	cout<<"\n:\n";
	moneystring sales(75453.89);
	moneystring purchases(60278.50);
	moneystring profit;
	profit=sales-purchases;
	cout<<"\nsales:";sales.display();
	cout<<"\npurchase:";purchases.display();
	cout<<"\nprofit:";profit.display();
	cout<<endl;
	cout<<"\n以下是对程序做一个数据更新的测试:\n";
	sales.newvalue(102560.25);
	purchases.newvalue(85642.66);
	profit=sales-purchases;
	cout<<"\nsales:";sales.display();
	cout<<"\npurchase:";purchases.display();
	cout<<"\nprofit:";profit.display();
	cout<<endl;
	cout<<"请按enter键进入程序";
	cin.get();
	double s1,s2;
	cout<<"\n		$	欢迎进入现金处理系统	$";
	cout<<"\n		*****************************************";
	cout<<"\n		*请输入您本月的销售额(输入结束时请按Enter键):";
	cin>>s1;
	cout<<"\n		*请输入您本月的投入额(输入结束时请按Enter键):";
	cin>>s2;
	cout<<"			*****************************************";
	moneystring sales1(s1);
	moneystring purchases1(s2);
	moneystring profit1;
	moneystring profit2;
	moneystring tax1;
	profit1=sales1-purchases1;
	tax1=profit*0.2;
	profit2=profit1*0.8;
	cout<<"\n\n				!您本月的销售额为:";sales1.display();
	cout<<"\n\n				!您本月的投入额为:";purchases1.display();
	cout<<"\n\n				!您本月的毛利润为:";profit1.display();
	cout<<"\n\n				!^__^不好意思,您所的的毛利润的20%将用来缴税";
	cout<<"\n\n				!您应缴的税为:";tax1.display();
	cout<<"\n\n				!恭喜!您本月的净利润为:";profit2.display();
	cout<<"\n\n				!感谢您使用本系统,再见!";
	cout<<endl;
}

⌨️ 快捷键说明

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