| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 642 人关注过本帖
标题:大家帮忙看看这个程序
取消只看楼主 加入收藏
说好。幸福呢
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-11-28
收藏
 问题点数:0 回复次数:0 
大家帮忙看看这个程序
这是个电话薄管理的程序  有三个错误,麻烦大家帮帮忙啊!
//Address.h文件
//通信录定义
#ifndef ADDRESS_H
#define ADDRESS_H
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
class Address
{    bool Status;   //通信录状态
     char Name[31];  //姓名        
     char Phone[21]; //电话
public:
    Address(){Status=true;}   //构造时通信录清空
    string GetName()const;    //取姓名
    string GetPhone()const;   //取电话
    bool isEmpty();   //取通信录状态
    void Enter(string$name,string$phone);  //输入通信录
    void Set();   //置通信录状态0,非空
    void Clear();  //置通信录状态1,非空
};
#endif
//Address.cpp文件
#include"Address.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
string Address::GetName()const
{   string s=Name;
    return s;
}
string Address::GetPhone()const
{    string s=Phone;
    return s;
}
bool Address::isEmpty(){return Status;}
void Address::Enter(string$name,string$phone)
{      int len=name.length();
    if(len>30)len=30;   //输入超长时截断
    name.copy(Name,len,0);
    Name[len]=0;   //字符串结束符,把string转换成char*
    len=phone.length();
    if (len>20) len=20;
    phone.copy(Phone,len,0);
    phone[len]=0;
}
void Address::Set(){Status=false;}
void Address::Clear(){Status=true;}//AddressBook.h文件 通信薄定义
#ifndef ADDRESSBOOK_H
#define ADDRESSBOOK_H
#include "Address.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int ItemNum=100;    //通信录最大数量
class AddressBook
{     Address Item[ItemNum];   //通信录
    int Num;   //通信录数量
    int FindFree();   //查找空的通信录
public:
    AddressBook(){Num=0;}
    void Enter();  //输入
    void Erase();  //删除
    void Load();   //读盘
    void Save();   //存盘
    void List();   //显示
};
#endif
//AddressBook.cpp文件
#include"Address.h"
#include"AddressBook.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
ostream $operator<<(ostream $output,const Address$ addr)
{     //重载<<,直接用cout输出通信录
      output<<setiosflags(ios::left)<<setw(31)
        <<addr.GetName()<<setw(21)<<addr.GetPhone();
    return output;
}
int AddressBook::FindFree()
{     int t;
     for(t=0;t<ItemNum;t++)
        if(Item[t].isEmpty()) return t;
        return -1;    //电话薄已记满
}
void AddressBook::Enter()
{
    string name,phone;
        int pointer;
    pointer=FindFree();
    if(pointer==-1)cout<<"电话薄已记满";
    else{
       cout<<"电话薄中有"<<Num<<"条通信录"<<endl;
       cout<<"输入姓名";
       cin>>name;
       cout<<"输入电话号码";
       cin>>phone;
       Item[pointer].Enter(name,phone);
       Item[pointer].Set();
       Num++;
    }
}
void AddressBook::Erase()
{     int t;
     string s;
     cout<<"电话薄中有"<<Num<<"条通信录"<<endl;
     if(!Num)cout<<"电话薄已空!\n";
     else{
    cout<<"输入姓名:";
    cin>>s;
    for(t=0;t<ItemNum;t++) {
        if(!Item[t].isEmpty()$$Item[t].GetName()==s){
        Item[t].Clear();
        Num--;
        cout<<"已经删除"<<s<<"的通信录。\n";
        break;}
    }
    if(t==ItemNum){
       cout<<"该名字不存在\n";
       cin.get();
    }
        }
}
void AddressBook::List()
{    int t,i,j;
     Address list[ItemNum],temp;
     if(!Num)cout<<"电话薄已空!"<<endl;
    else{
        cout<<"电话薄中有"<<Num<<"条通信录"<<endl;
        for(t=0;t<ItemNum;t++)list[t]=Item[t];
        for(i=0;i<ItemNum;i++)
        {    //排序
            for(j=ItemNum-1;j>i;j--)
                if(list[j-1].GetName()>list[j].GetName())
                {   temp=list[j-1];
                    list[j-1]=list[j];
                    list[j]=temp;
                }
        }
        cout<<setiosflags(ios::left)<<setw(31)<<"姓名"<<setw(21)<<"电话"<<endl;
        for(t=0;t<ItemNum;++t){
            if(!list[t].isEmpty())
                cout<<list[t]<<endl;}
    }
}
void AddressBook::Save()
{       ofstream file;
    int i;
    char fname[41];
    cout<<"输入保存的文件名:";
    cin>>fname;
    file.open(fname,ios::out);
    if(!file){
        cout<<"打开文件失败!\n";
        cin.get();
    }
    else{
        for(i=0;i<ItemNum;i++)
        {
            if(file$$!file.eof())
                file.write(reinterpret_cast<const char*>($Item[i]),sizeof(Address));
        }
        file.close();
    }
}
void AddressBook::Load()
{
    ifstream file;
    int i;
    char fname[41];
    cout<<"输入读取的文件名:";
    cin>>fname;
    file.open(fname,ios::in);
    if(!file){
       cout<<"打开文件失败!";
       cin.get();
}
else{
    Num=0;
    for(i=0.i<ItemNum;i++)
    {
        if(file$$!file.eof())
            file.read(reinterpret_cast<char*>($Item[i]),sizeof(Address));
        if(!Item[i].isEmpty())Num++;
    }
        file.close();
    }
}
//Example 模拟电话薄
#include"Address.h"
#include"AddressBook.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int menu_select();
int main()
{       char choice;
    AddressBook maillist;
    for(;;){   //循环,直到键盘输入结束代码
        choice=menu_select();
        switch(choice){   //根据键盘输入,调用相应的功能
        case 1:maillist.Enter();break;
        case 2:maillist.Erase();break;
        case 3:maillist.List();break;
        case 4:maillist.Save();break;
        case 5:maillist.Load();break;
                case 6:exit(0);
        }
    }
    return 0;
}
int menu_select()
{       //显示主菜单
    char c;
    cout<<"***************************************\n";
    cout<<"*        模拟电话薄    v1.0           *\n";
    cout<<"*                                     *\n";
    cout<<"*      1.添加通信录                   *\n";
    cout<<"*      2.删除通信录                   *\n";
    cout<<"*      3.显示通信录                   *\n";
        cout<<"*      4.电话薄存盘                   *\n";
    cout<<"*      5.读出电话薄                   *\n";
    cout<<"*      6.退出                         *\n";
    cout<<"***************************************\n";
    cout<<"\n请输入(1~6):";
    do{    //键盘输入循环
        cin.get(c);
    }while(c<'1'||c>'6');
    return c-48;
}
搜索更多相关主题的帖子: 通信 电话 include public Phone 
2008-11-28 16:48
快速回复:大家帮忙看看这个程序
数据加载中...
 
   



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

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