首页 > 其他分享 >饭卡

饭卡

时间:2024-01-27 09:34:44浏览次数:14  
标签:饭卡 string cid int money bool cout

#include <iostream>
#include <windows.h>
#include <fstream>
using namespace std;
struct card{
	//属性
	string name;
	int id;
	string classroom;
	float money=0;
	string creat_time;
	bool gua=0;//是否挂失
	//方法
	//开卡
	bool creat(int i,string n,string c){
		name=n;
		classroom=c;
		id=i;
		return true;
	}
	//充钱
	bool Recharge(int m){
		money+=m;
		return true;
	}
	//消费
	bool consumption(int m){
		if(money>=m&&m>0){
			money-=m;
			return true;
		}
			return false;
	}
	//退钱
	bool tuiqian(int m){
		if(money-m<0){
			return false;
		}else{
			money-=m;
			return true;
		}
	}
	//挂失
	bool guashi(bool m){
		gua=m;
		return true;
	}
};
void fen(){
	ifstream file;
	string data;
	file.open("1.txt");
	//getline获取文件的一行数据
	while(getline(file,data)){
		if(data.length()>5){
			string classroom,id,name;
			double money;
			int length;
			do{
				length=data.find("|");
				cout<<data.substr(0,length)<<" ";
				data=data.substr(length+1);
			}while(length>0 && length<data.length());
		}
		//eof 是否到了文件末尾
		if(file.eof()){
			cout<<"end"<<endl;
			break;
		}
	}
	file.close();
}
int main(int argc, char** argv) {
	card cardlist[100];
	int startid=1000;
	int number=0;//当前有几个人办卡
	fen();
	while(1){
		cout<<"**太康一高附属学校充值系统**"<<endl;
		cout<<"*****1.开卡*****"<<endl;
		cout<<"*****2.充值*****"<<endl;
		cout<<"*****3.消费*****"<<endl;
		cout<<"***4.查询余额***"<<endl;
		cout<<"*****5.挂失*****"<<endl;
		cout<<"*****6.退钱*****"<<endl;
		cout<<"***7.退出系统***"<<endl;
		cout<<endl;
		int index;
		cin>>index;
		card c;
		int a;//充值,消费金额,退钱
		int _cid;//卡号
		bool t=0;//挂失
		bool have=false;
		switch(index){
			case 1:
				cout<<"请输入姓名:";
				cin>>c.name;
				c.id=startid+number;
				cardlist[number]=c;
				cout<<"你的学号为"<<cardlist[number].id<<"你的金额为"<<cardlist[number].money;
				number++;
				break;
			case 2:
				cout<<"请输入你的卡号:";
				cin>>_cid;
				for(int i=0;i<=number;i++){
					if(cardlist[i].id==_cid){
					if(cardlist[i].gua==1){
						cout<<"对不起,该同学的卡已挂失";
					}else{
						cout<<cardlist[i].name<<"同学你好,请输入充值金额:";
						cin>>a;
						cardlist[i].Recharge(a);
						cout<<"你的金额有:"<<cardlist[i].money;
						have=true;
						break;
						}
					}
				}
				if(have==false){
					cout<<"对不起,该同学没有创建卡号"<<endl;
				}
				break;
			case 3:
				cout<<"请输入你的卡号";
				cin>>_cid;
				for(int i=0;i<=number;i++){
					if(cardlist[i].id==_cid){
						if(cardlist[i].gua==1){
							cout<<"对不起,该同学的卡已挂失";
						}else{
							cout<<cardlist[i].name<<"同学你好,请输入消费金额: 上限为500"<<endl;
							cin>>a;
							if(a>500){
								cout<<"充值超过上限";
							}else{
								cardlist[i].consumption(a);
								cout<<"你的剩余金额:"<<cardlist[i].money;
							}
							have=true;
							break;
						}
					}
				}
				if(have==false){
					cout<<"对不起,该同学没有创建卡号"<<endl;
				}
				break;
			case 4:
				cout<<"请输入你的卡号";
				cin>>_cid;
				for(int i=0;i<=number;i++){
					if(cardlist[i].id==_cid){
						cout<<cardlist[i].name<<"同学你好,你的余额为"<<cardlist[i].money;
						have=true;
						break;
					}
				}
				if(have==false){
					cout<<"对不起,该同学没有创建卡号"<<endl;
				}
				break;
			case 5:
				cout<<"请输入你的卡号";
				cin>>_cid;
				for(int i=0;i<=number;i++){
					if(cardlist[i].id==_cid){
						cout<<cardlist[i].name<<"同学你好,请输入你要退多少钱"<<endl;
						cin>>a;
						if(cardlist[i].tuiqian(a)==0){
							cout<<"同学,你的余额不足";
						}
						have=true;
						cout<<cardlist[i].name<<"同学,你的余额为"<<cardlist[i].money;
						break;
					}
				}
				if(have==false){
					cout<<"对不起,该同学没有创建卡号"<<endl;
				}
				break;
			case 6:
				cout<<"请输入你的卡号";
				cin>>_cid;
				for(int i=0;i<=number;i++){
					if(cardlist[i].id==_cid){
						t=1;
						cardlist[i].guashi(t);
						cout<<"同学,你的卡已挂失";
						have=true;
						break;
					}
				}
				if(have==false){
					cout<<"对不起,没有该卡"<<endl;
				}
				break;
				case 7:
				return 0;
				break;
		}
		Sleep(500);
		system("cls");
	}
	return 0;
}

  

标签:饭卡,string,cid,int,money,bool,cout
From: https://www.cnblogs.com/boyeyuan/p/17991093

相关文章

  • 饭卡(容器)3.0
    #include<iostream>#include<vector>usingnamespacestd;#definelist1000structa{stringname;intid;intage;stringClass;}index;voidMAIN(){cout<<"欢迎使用学生管理系统"<<endl<<"1.......
  • 饭卡(容器)2.0
    #include<iostream>#include<vector>#include<windows.h>usingnamespacestd;inta=999;intb=0;boolc=false;structstudent{stringname;intage;intcard;intgrade;}s;voidka(){cout......
  • 饭卡
    #include<iostream>#include<vector>#include<windows.h>usingnamespacestd;inta=999;intb=0;boolc=false;structstudent{stringname;intage;intcard;intgrade;}s;voidka(){cout<<"学生管理系统:"&......
  • 容器(饭卡)
    #include<iostream>#include<vector>#include<windows.h>usingnamespacestd;inta=999;structstudent{stringname;intage;intcard;intcroom;}s;voidxitong(){cout<<"学生管理系统:"<<endl;co......
  • 饭卡(容器)
    #include<iostream>#include<vector>#include<windows.h>usingnamespacestd;inta=999;structstudent{ stringname; intage; intcard; intgrade;}s;voidka(){ cout<<"学生管理系统:"<<endl; cout<<"1.新建学生......
  • 饭卡
    #include<iostream>#include<bits/stdc++.h>usingnamespacestd;structcard{ //属性 stringname; intid; stringclassroom; floatmoney; intmoney_type; stringcreat_time; //方法 //开卡 boolcreat(inti,stringn,stringc){ name=n;......
  • 饭卡管理系统&结构体
    #include<iostream>usingnamespacestd;structcard{ stringname; intid; intmoney; boolbuild_card(intx_id,stringx_name){ name=x_name; id=x_id; returntrue; } boolchong(intx_money){ money+=x_money; returntrue; } boolhua(int......
  • 饭卡 (01背包)
    饭卡TimeLimit:5000/1000MS(Java/Others)    MemoryLimit:32768/32768K(Java/Others)TotalSubmission(s):16574    AcceptedSubmission(s):5763ProblemDescription电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商......
  • java大学校园饭卡管理系统饭卡查询系统饭卡挂失网站源码
    springboot开发的大学生饭卡系统,学生可以登录该系统充值饭卡,挂失饭卡,取消挂失,查看自己的所有饭卡,以及发卡的充值记录。超级管理员拥有最大的权限,饭卡管理员可以添加饭卡信......
  • HDU 2546 饭卡
    题目链接:​​传送门​​题面:ProblemDescription电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一......