| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 439 人关注过本帖
标题:纠正错误,谢!代码没错误,但是没法执行,求解。
取消只看楼主 加入收藏
zpjm
Rank: 2
等 级:论坛游民
帖 子:36
专家分:21
注 册:2011-3-2
结帖率:75%
收藏
已结贴  问题点数:40 回复次数:0 
纠正错误,谢!代码没错误,但是没法执行,求解。
#include<cassert>
template<class T>
class Array{
    private:
        T*list;
        int size;
    public:
        Array(int sz=50);
        Array(const Array<T>&a);
        ~Array();
        Array<T>&operator=(const Array<T>&rhs);
        T&operator[](int i);
        const T &operator[](int i)const;
        operator T*();
        operator const T*()const;
        int getSize()const;
        void resize(int sz);
};
template<class T>
Array<T>::Array(int sz){
    assert(sz>=0);
    size=sz;
    list=new T[size];
}
template<class T>
Array<T>::~Array(){
    delete[]list;
}
template<class T>
Array<T>::Array(const Array<T>&a){
    size=a.size;
    list=new T[size];
    for(int i=0;i<size;i++)
        list[i]=a.list[i];
}
template<class T>
Array<T>&Array<T>::operator=(const Array<T>&rhs){
    if(&rhs!=this){
        if(size!=rhs.size){
            delete[]list;
            size=rhs.size;
            list=new T(size);
        }
        for(int i=0;i<size;i++)
            list[i]=rhs.list[i];
    }
    return*this;
}
template<class T>
T &Array<T>::operator[] (int n){
    assert(n>=0&&n<size);
    return list[n];
}
template<class T>
const T &Array<T>::operator[] (int n) const{
    assert(n>=0&&n<size);
    return list[n];
}
template<class T>
Array<T>::operator T*(){
    return list;
}
template<class T>
Array<T>::operator const T*() const{
    return list;
}
template<class T>
int Array<T>::getSize() const{
    return size;
}
template<class T>
void Array<T>::resize (int sz){
    assert(sz>=0);
    if(sz==size)
        return;
    T*newlist=new T[sz];
    int n=(sz<size)?sz:size;
    for(int i=0;i<n;i++)
        newlist[i]=list[i];
    delete[]list;
    list=newlist;
    size=sz;
}





#include"Array.h"
#include<iostream>
#include<string>
using namespace std;
class Contacts
{
private:
    string name;
    string adress;
    string number;
    string post;
    string QQ;
public:
    Contacts(string name,string adress,string number,string post,string QQ);
    ~Contacts(){}
    /*void add_contact(std::string newname,std::string newadress,std::string newnumber,std::string newpost,std::string newQQ);*/
    void show_contact();
    void edit_contacts(string name,string adress,string number,string post,string QQ);
};
Contacts::Contacts(string name,string adress,string number,string post,string QQ): name(name),adress(adress), number(number), post(post),QQ(QQ)
{
    cout<<name<<"is created"<<endl;
}
/*void Contacts::add_contact(std::string newname,std::string newadress,std::string newnumber,std::string newpost,std::string newQQ)
{
    cout<<"name:";
    cin>>name;
    cout<<"adress";
    cin>>adress;
    cout<<endl<<"number:";
    cin>>number;
    cout<<endl<<"post";
    cin>>post;
    cout<<endl<<"QQ";
    cin>>QQ;
    cout<<endl<<"contact is created!"<<endl;
}*/
void Contacts::show_contact()
{
    cout<<"name"<<name<<endl;
    cout<<"number"<<number<<endl;
    cout<<"adress"<<adress<<endl;
    cout<<"post"<<post<<endl;
    cout<<"QQ"<<QQ<<endl;
}
void Contacts::edit_contacts(string name,string adress,string number,string post,string QQ)
{
    name=name;
    adress=adress;
    number=number;
    post=post;
    QQ=QQ;
}
int main()
{
    string name;
    string adress;
    string number;
    string post;
    string QQ;
    /*Contacts c1("zhangsan","yantai","123","123@.com","35689");
    Contacts c2("lisi","zaozhuang","456","456@.com","78912");
        Contacts*Contacts[]={&c1,&c2};*/
    Array<class Contacts*>Contacts(0);
    cout<<"(a)add_contact,(d)delete_contact,(s)show_contact,(c)correct_contact,(e)exit"<<endl;
 /* const int n=sizeof(Contacts);*/

char cmd;
do{
    int n;
Array<class Contacts*>Contacts;
cin>>cmd;
switch(cmd){

case'a':
        
         cout<<"please enter name:";
            cin>>name;
        cout<<"please enter number:";
        cin>>number;
    cout<<"please enter adress:";
    cin>>adress;
    cout<<"please enter post";
    cin>>post;
    cout<<"please enter QQ";
    cin>>QQ;

Contacts.resize(Contacts.getSize()+1);
Contacts[Contacts.getSize()-1]->edit_contacts(name, adress, number, post, QQ);
    break;
case'd':
    cout<<"the one you want to delete"<<endl;
    cin>>n;
    delete Contacts[n-1];
    for(n;n<Contacts.getSize();)
        Contacts[n]=Contacts[++n];
Contacts.resize(Contacts.getSize()+1);

 
    break;
case's':
    for( n=0;n<Contacts.getSize();n++)
    {
        cout<<"["<<n<<"]"<<endl;
        Contacts[n]->show_contact();
        cout<<endl;
    }
    break;
case'c':
        cin>>n;
        cout<<"please enter name:";
            cin>>name;
        cout<<"please enter number:";
        cin>>number;
    cout<<"please enter adress:";
    cin>>adress;
    cout<<"please enter post";
    cin>>post;
    cout<<"please enter QQ";
    cin>>QQ;
    Contacts[n]->edit_contacts(name, adress, number,post, QQ);

    break;
}
}while(cmd!='e');
return 0;
}
搜索更多相关主题的帖子: private include public 
2011-06-22 17:19
快速回复:纠正错误,谢!代码没错误,但是没法执行,求解。
数据加载中...
 
   



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

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