| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 432 人关注过本帖
标题:求高手带我编程哈!!!!
只看楼主 加入收藏
亦尘
Rank: 1
等 级:新手上路
帖 子:21
专家分:3
注 册:2011-11-16
结帖率:55.56%
收藏
 问题点数:0 回复次数:1 
求高手带我编程哈!!!!
求助啊,帮我看看程序啊
求一名高手带小弟学编程啊,我每次都是有思想但是写的程序老师有错啊!!!!!
下面我的程序求指点
#include<iostream.h>
#include<stdio.h>


class node
{
protected:
    int num;
    node * next;
public:
    node(){}
    ~node(){}
};



class list
{
friend node;
private:
    node * head;   
    static int count;
public:
    list();
    ~list();
    void show();
    void creat();
    void insert(node * currentp);
    void modificate();
    void remove();
    void read();
    void size();
    void turn();
};
list::list()
{
   head=new node;
   cout<<"链表开始!!!";
}
list::~list()
{
    cout<<"链表结束!!!";
}



void list::creat()
{
    int num,i;
    cout<<"请输入您需要输入的数字个数:";
    cin>>num;
    for(i=1;i<=num;i++)
    {
        node *currentp=new node;
        insert(currentp);
    }
}

void list::insert(node * currentp)
{
    int position,i=0;
    node * searchp=new node;
    node *followp=new node;
    cout<<"请输入你要插入的位置:";
    cin>>position;
    while(position>count+1||position<=0)
    {  
        cout<<"您输入的标号无效!!!";
        cout<<"请重新输入你要插入的位置:";
        cin>>position;
    }

    cout<<"请输入该节点的数字:";
    cin>>currentp->num;

    followp=head;

    do{        
        searchp=followp->next;
        followp=followp->next;
        i++;
    }while(i<position-1);
    currentp->next=searchp;
    followp->next=currentp;
    count++;
}


void  list::modificate()
{
    int position,i=0;
    node searchp=new node;
    node followp=new node;
    cout<<"请输入你要修改的位置:";
    cin>>position;
    while(position>count+1||position<=0)
    {  
        cout<<"您输入的标号无效!!!";
        cout<<"请重新输入你要插入的位置:";
        cin>>position;
    }
     searchp=head;
      do{        
        searchp= searchp->next;
        i++;
    }while(i<position);
      cout<<"请重新输入你的数值:";
    cin>>searchp->num;
}

void list::remove( )
{
   int position,i=0;
    node searchp=new node;
    node fllowp=new node;
    cout<<"请输入你要删除的位置:";
    cin>>position;
    while(position>count+1||position<=0)
    {  
        cout<<"您输入的标号无效!!!";
        cout<<"请重新输入你要插入的位置:";
        cin>>position;
    }

    do{        
        searchp=followp->next;
        fllowp=followp->next;
        i++;
    }while(i<num-1)
    currentp->next=searchp->next;
    delete searchep;
    count--;
}

void  list::read()
{
    int position,i=0;
    node *searchp=new node;
    node *followp=new node;
    cout<<"请输入你要读取数据的位置:";
    cin>>position;
    while(position>count+1||position<=0)
    {  
        cout<<"您输入的标号无效!!!";
        cout<<"请重新输入你要插入的位置:";
        cin>>position;
    }
     searchp=head;
      do{        
        searchp= searchp->next;
        i++;
    }while(i<num);
      cout<<"您要的数据是:"<<searchp->num;
}

void list::size()
{
    cout<<"数据总共有"<<count<<"位!!!";
}


void list::show()
{
    int i;
      node * searchp=new node;
      cout<<"所有数据如下:"<<endl;
      searchp=head;
      do{        
        searchp= searchp->next;
        cout<<"[searchp->num|-]->";
        i++;
    }while(i<num||searchp!=NULL);
      if(searchp=NULL)
          cout<<"[searchp->num|NULL]";
}

void menu()
{
    cout<<"链表基本功能菜单"<<endl;
    cout<<"作者:***(部分原创版)"<<endl;
    cout<<"=========="<<endl;
    cout<<"1.输入数据 "<<endl;
    cout<<"2.显示数据(遍历链表中全部数据)"<<endl;
    cout<<"3.修改数据(要求提供位置和新值)"<<endl;
    cout<<"4.插入数据(要求提供位置和新值)"<<endl;
    cout<<"5.删除数据(要求提供位置)"<<endl;
    cout<<"6.读取数据(要求提供位置)"<<endl;
    cout<<"7.求表长度(求出元素个数)"<<endl;
    cout<<"8.数据反转(全部数据反向存储)"<<endl;
    cout<<"9.结束程序"<<endl;
    cout<<"=========="<<endl;
}
void main()
{


void main()
{
    list a;
    int choice;
    do
    {
        system("cls");
        menu();
        cout<<"请输入您的选择:";
        cin>>choice;
        switch(choice)
        {
        case 1:
            system("cls");
            a.creat();
            system("pause");
            break;
        case 2:
            a.show();
            system("pause");
            break;
        case 3:
            a.modificate();
            system("pause");
            break;
        case 4:
            a.insert();
            system("pause");
            break;
        case 5:
            a.remove();
            system("pause");
            break;
        case 6:
            a.read();
            system("pause");
            break;
        case 7:
            a.size();
            break;
        case 8:
            a.turn();
            break;
        case 9:
            break;

        }
    }while(choice>=1&&choice<=9);
   
}
搜索更多相关主题的帖子: void class private include public 
2012-03-13 12:03
Wikyo_hoho
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:31
专家分:188
注 册:2012-3-12
收藏
得分:0 
希望你下次能够注释下
程序代码:
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>//你用system("cls");清屏要加这头文件

class node
{
protected:
    int num;
    node * next;
public:
    node(){}
    ~node(){}
    friend class list;//友元函数加这,这样list才可以调用node
};



class list
{
//friend node;
private:
    node * head;   
    static int count;
    int num;        //至于这俩个,你本来定义在下面函数中,但是他们在函数结束时会直接被释放
    node *currentp;    //所以你想在另外个函数中继续调用,就直接被我拉这来了
public:
    list();
    ~list();
    void show();
    void creat();
    void insert();
    void modificate();
    void remove();
    void read();
    void size();
//    void turn();        你这函数都没定义;
};

int list::count=0;//count记得初始化

list::list()
{
   head=new node;
   cout<<"链表开始!!!";
}
list::~list()
{
    cout<<"链表结束!!!";
}



void list::creat()
{
    int i;
    cout<<"请输入您需要输入的数字个数:";
    cin>>num;
    for(i=1;i<=num;i++)
    {
        currentp=new node;
        insert();
    }
}

void list::insert()//~~~~~链表插入~~~~~~~~因为currentp被我拉到成员里去了,所以调用就省了吧
{
    int position,i=0;
    node * searchp=new node;
    node *followp=new node;
    cout<<"请输入你要插入的位置:";
    cin>>position;
    while(position>count+1||position<=0)
    { 
        cout<<"您输入的标号无效!!!";
        cout<<"请重新输入你要插入的位置:";
        cin>>position;
    }

    cout<<"请输入该节点的数字:";
    cin>>currentp->num;

    followp=head;

    do{       
        searchp=followp->next;
        followp=followp->next;
        i++;
    }while(i<position-1);
    currentp->next=searchp;
    followp->next=currentp;
    count++;
}


void  list::modificate()
{
    int position,i=0;
    node *searchp=new node;
    node *followp=new node;
    cout<<"请输入你要修改的位置:";
    cin>>position;
    while(position>count+1||position<=0)
    { 
        cout<<"您输入的标号无效!!!";
        cout<<"请重新输入你要插入的位置:";
        cin>>position;
    }
     searchp=head;
      do{       
        searchp= searchp->next;
        i++;
    }while(i<position);
      cout<<"请重新输入你的数值:";
    cin>>searchp->num;
}

void list::remove( )
{
   int position,i=0;
    node *searchp=new node;
    node *followp=new node;
    cout<<"请输入你要删除的位置:";
    cin>>position;
    while(position>count+1||position<=0)
    { 
        cout<<"您输入的标号无效!!!";
        cout<<"请重新输入你要插入的位置:";
        cin>>position;
    }

    do{       
        searchp=followp->next;
        followp=followp->next;
        i++;
    }while(i<num-1);
    currentp->next=searchp->next;
    delete searchp;
    count--;
}

void  list::read()
{
    int position,i=0;
    node *searchp=new node;
    node *followp=new node;
    cout<<"请输入你要读取数据的位置:";
    cin>>position;
    while(position>count+1||position<=0)
    { 
        cout<<"您输入的标号无效!!!";
        cout<<"请重新输入你要插入的位置:";
        cin>>position;
    }
     searchp=head;
      do{       
        searchp= searchp->next;
        i++;
    }while(i<num);
      cout<<"您要的数据是:"<<searchp->num;
}

void list::size()
{
    cout<<"数据总共有"<<count<<"位!!!";
}


void list::show()
{
    int i;
      node * searchp=new node;
      cout<<"所有数据如下:"<<endl;
      searchp=head;
      do{       
        searchp= searchp->next;
        cout<<"[searchp->num|-]->";
        i++;
    }while(i<num||searchp!=NULL);
      if(searchp=NULL)
          cout<<"[searchp->num|NULL]";
}

void menu()
{
    cout<<"链表基本功能菜单"<<endl;
    cout<<"作者:***(部分原创版)"<<endl;
    cout<<"=========="<<endl;
    cout<<"1.输入数据 "<<endl;
    cout<<"2.显示数据(遍历链表中全部数据)"<<endl;
    cout<<"3.修改数据(要求提供位置和新值)"<<endl;
    cout<<"4.插入数据(要求提供位置和新值)"<<endl;
    cout<<"5.删除数据(要求提供位置)"<<endl;
    cout<<"6.读取数据(要求提供位置)"<<endl;
    cout<<"7.求表长度(求出元素个数)"<<endl;
    cout<<"8.数据反转(全部数据反向存储)"<<endl;
    cout<<"9.结束程序"<<endl;
    cout<<"=========="<<endl;
}


void main()
{
    list a;
    int choice;
    do
    {
        system("cls");
        menu();
        cout<<"请输入您的选择:";
        cin>>choice;
        switch(choice)
        {
        case 1:
            system("cls");
            a.creat();
            system("pause");
            break;
        case 2:
            a.show();
            system("pause");
            break;
        case 3:
            a.modificate();
            system("pause");
            break;
        case 4:
            a.insert();
            system("pause");
            break;
        case 5:
            a.remove();
            system("pause");
            break;
        case 6:
            a.read();
            system("pause");
            break;
        case 7:
            a.size();
            break;
        case 8:
        case 9:
            break;

        }
    }while(choice>=1&&choice<=9);
}
至于其他的像变量名写错了,我不标出,你自己在错误提示error C2065: 'followp' : undeclared identifier之类里找出,还有定义    node *searchp=new node;
    node *followp=new node;的*号忘了之类的。你自己看看。我就是把你里面的错误都改正,至于能否运行看你的想法是否正确了。
我再提醒下,你这程序的delete得记得。我这就不加了,看你自己了
2012-03-13 18:28
快速回复:求高手带我编程哈!!!!
数据加载中...
 
   



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

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