| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 527 人关注过本帖
标题:[求助]文件的读入与查询
只看楼主 加入收藏
guyanjianghu
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2007-3-27
收藏
 问题点数:0 回复次数:1 
[求助]文件的读入与查询

//Function.h
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<iomanip>
#include<fstream>
#include<ostream>
#include<istream>
using namespace std;
class Base{
int year;
int month;
int day;
char place[50];
char act_type[50];
char name[30];//委托人名字;
int number;//委托人电话
double earnest;//所交定金

public:
//Base(int y,int m,int d){year=y,month=m,day=d;}
virtual void gett();
virtual void putt();
virtual void base();
virtual void view();
friend void conduct(Base & y,Base & m,Base & d);
};

class Commemorate:public Base{ //纪念
int pigeon;//和平鸽数
int programe;//准备节目数
double com_money;//活动后应付总金
double com_tax;//活动后应交税
double rent;//场地租金

public:

virtual void gett();
virtual void putt();
void account_c();
virtual void base();
virtual void view();
};
class Wedding:public Base
{
int n;//车总数,要用函数
int aodi;
int baoma;
int benchi;
int zhongba;
int load_num;//总载客人数;需要用函数算
double w_feast;//宴席单价
int w_number;//宴席数量;
double w_cracker;//爆竹总格;
double w_corbeil;//花篮总格
double wed_money;//活动后应付总金
double wed_tax;//活动后应交税
public:
virtual void gett();
virtual void putt();
virtual void base();
void account_w();
virtual void view();
};
class Practice:public Base
{ double p_feast;
int p_number;
double p_cracker;
double p_corbeil;
double pra_money;//活动后应付总金
double pra_tax;//活动后应交税

public:
virtual void gett();
virtual void putt();
void base();
void account_p();
virtual void view();

};
//.cpp

#include"Function.h"

void Base:: gett(){
cout<<"请输入举办活动年份:\n";
cin>>year;
cout<<"请输入举办活动月份:\n";
cin>>month;
cout<<"请输入举办活动日:\n";
cin>>day;
cout<<"请输入举办活动地点:\n";
cin>>place;
cout<<"请输入举办活动类型:\n";
cin>>act_type;
cout<<"请输入委托人姓名:\n";
cin>>name;
cout<<"请输入委托人电话号码:\n";
cin>>number;
cout<<"请输入定金数额:\n";
cin>>earnest;
}
void Base::putt(){
cout<<"举办活动时间:"<<year<<"."<<month<<"."<<day<<endl;
cout<<"举办活动地点:"<<place<<endl;
cout<<"举办活动类型:"<<act_type<<endl;
cout<<"委托人姓名:"<<name<<endl;
cout<<"委托人电话号码:"<<number<<endl;
cout<<"定金数额:"<<earnest<<endl;
}
void test(Base & h){
h.gett();
h.putt();
}
void cun(Base & p){
p.base();
}
void cha(Base & f){
f.view();
}
void Base::base(){
Base b;
ofstream ba("Base.txt",ios::out|ios::app);
test(b);
ba.write((char*)&b,sizeof(b));
ba.close();
}

void Base::view(){
Base be;
ifstream pp("base.txt",ios::in);
pp.read((char*)&be,sizeof (be));
pp.close();
int tmp=sizeof(be);
pp.seekg(-tmp,ios::end);
pp.read((char*)& be,sizeof(be));
pp.close();
}
void conduct(Base & y,Base & m,Base & d){
cout<<"输入年:";
cin>>y.year;
cout<<"输入月:";
cin>>m.month;
cout<<"输入日:";
cin>>d.day;
}

void Commemorate::gett(){
cout<<"请输入和平鸽数:\n";
cin>>pigeon;
cout<<"请输入准备节目数:\n";
cin>>programe;
cout<<"请输入租场费:\n";
cin>>rent;
}
void Commemorate::putt(){
cout<<"和平鸽数:"<<pigeon<<endl;
cout<<"准备节目数:"<<programe<<endl;
cout<<"租场费:"<<rent<<endl;
}
void Commemorate::account_c(){
com_money=pigeon*2+programe*50+rent;
cout<<"活动后应交总金:"<<com_money<<endl;
com_tax=com_money*0.15;
cout<<"活动后应交税金:"<<com_tax<<endl;
}
void Commemorate::base(){
Commemorate c;
ofstream co("commemorate.txt",ios::out|ios::app);
test(c);
c.account_c();
co.write((char*)&c,sizeof(c));
co.close();
}
void Commemorate::view(){
Commemorate C;
ifstream CC("Base.txt",ios::in);
CC.read((char*)&C,sizeof C);
CC.close();
int tmp=sizeof(C);
CC.seekg(-tmp,ios::end);
CC.read((char*)& C,sizeof(C));
CC.close();
}

void Wedding::gett(){
cout<<"请输入预定aodi车数:\n";
cin>>aodi;
cout<<"请输入预定baoma车数:\n";
cin>>baoma;
cout<<"请输入预定benchi车数:\n";
cin>>benchi;
cout<<"请输入预定zhongba车数:\n";
cin>>zhongba;
cout<<"请输入宴席单价:\n";
cin>>w_feast;
cout<<"请输入准备的宴席数:\n";
cin>>w_number;
cout<<"请输入爆竹的金额:\n";
cin>>w_cracker;
cout<<"请输入花篮的金额:\n";
cin>>w_corbeil;
}
void Wedding::putt(){
cout<<"预定aodi车数:"<<aodi<<endl;
cout<<"预定baoma车数:"<<baoma<<endl;
cout<<"预定benchi车数:"<<benchi<<endl;
cout<<"预定zhongba车数:"<<zhongba<<endl;
}
void Wedding::account_w(){
wed_money=aodi*30+baoma*40+benchi*50+zhongba*40+w_feast*w_number+w_cracker+w_corbeil;
cout<<"活动后应付总金:"<<wed_money<<endl;
wed_tax=wed_money*0.20;
cout<<"活动后应交税金:"<<wed_tax<<endl;
}
void Wedding::base(){
Wedding w;
ofstream we("wedding.txt",ios::out|ios::app);
test(w);
w.account_w();
we.write((char*)&w,sizeof(w));
we.close();
}
void Wedding::view(){
Wedding W;
ifstream WW("wedding.txt",ios::in);
WW.read((char*)&W,sizeof W);
WW.close;
int dmp=sizeof(W);
WW.seekg(-dmp,ios::end);
WW.read((char*)& W,sizeof(W));
WW.close();
}
void Practice::gett(){
cout<<"请输入宴席单价:\n";
cin>>p_feast;
cout<<"请输入准备的宴席数:\n";
cin>>p_number;
cout<<"请输入爆竹的金额:\n";
cin>>p_cracker;
cout<<"请输入花篮的金额:\n";
cin>>p_corbeil;
}
void Practice::putt(){
cout<<"宴席单价:"<<p_feast<<endl;
cout<<"准备宴席数:"<<p_number<<endl;
cout<<"爆竹金额:"<<p_cracker<<endl;
cout<<"花篮金额:"<<p_corbeil<<endl;
}
void Practice::account_p(){
pra_money=p_feast*p_number+p_cracker+p_corbeil;
cout<<" 活动后应付总金:"<<pra_money<<endl;
pra_tax=pra_money*0.17;
cout<<"活动后应叫税款:"<<pra_tax<<endl;
}
void Practice::base(){
Practice p;
ofstream pr("programe.txt",ios::out|ios::app);
test(p);
p.account_p();
pr.write((char*)&p,sizeof(p));
pr.close();
}
void Practice::view(){
Practice P;
ifstream PP("programe.txt",ios::in);
PP.read((char*)&P,sizeof (P));
PP.close();
int emp=sizeof(P);
PP.seekg(-emp,ios::end);
PP.read((char*)& P,sizeof(P));
PP.close();
}

void main(){
Base B;
Commemorate C;
Wedding W;
Practice P;
bool sj=true;
cout<<"1.添加新纪念类信息:"<<endl;
cout<<"2.添加新婚礼类信息:"<<endl;
cout<<"3.添件新开业类信息:"<<endl;
cout<<"4.查看某一天的预定情况:"<<endl;
cout<<"5.退出:"<<endl;
while(sj)
{ Base c;Base d;Base f;
cout<<"请输入1—5的数字:";
int a;
cin>>a;
switch(a)
{
case 1:
cout<<"1.添加新纪念类信息"<<endl;
test(B);
test(C);
break;
case 2:
cout<<"添加新婚礼类信息:"<<endl;
test(B);
test(W);
break;
case 3:
cout<<"添加新开业类信息:"<<endl;
test(B);
test(P);
break;
case 4:
cout<<"查看某一天的预定情况:"<<endl;
cout<<"请输入要查询的时间:"<<endl;

conduct(c,d,f);
cha(B);
cha(C);
cha(W);
cha(P);
break;
case 5:
cout<<"5.退出:"<<endl;
sj=false;
break;
default:;
}
}
}

void main()中的case 4只能输入要查询的时间,下面的查询功能就无法实行了,那位大虾有时间帮忙看一下,是不是我的文件存储与读写出了问题。

搜索更多相关主题的帖子: int include 文件 Base 委托人 
2007-07-23 15:28
野比
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:24
帖 子:1627
专家分:516
注 册:2007-5-24
收藏
得分:0 

太长了... 我最缺的是时间...


女侠,约吗?
2007-07-24 20:40
快速回复:[求助]文件的读入与查询
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034370 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved