注册 登录
编程论坛 C++教室

函数可以相互调用吗?

BNV 发布于 2010-12-21 01:43, 708 次点击
只给部分代码


void Insert()
{
    int a;
    char b[20],c[30],d[20],e[20],f;
    cin>>a;
    if(a!=1&&a!=2&&a!=3&&a!=4&&a!=5)
    {
        cout<<"输入错误!请再次输入:        "<<endl;
    }
    if(a==5)
    {
        /*    退出程序 */
    }

    else if(a<5&&a>0)
    {
        cout<<"请输入信息:        "<<endl;
        cout<<"姓名:";
        cin>>b;
        cout<<"所学专业:";
        cin>>c;
        cout<<"所在部门:";
        cin>>d;
        cout<<"具体授课:";
        cin>>e;
        if(a==1)
        {
            student s(b,c,d,e);
            cout<<"需要显示信息吗?(y or n):"<<endl;
            cin>>f;
            if(f=='y'||f=='Y')
            {
                cout<<s.Print1();
            }
            if(f=='n'||f=='N')
            {
                PrintMenu();
            }
        }
        else if(a==2)
        {
            staff s(b,c,d,e);
            cout<<"需要显示信息吗?(y or n):"<<endl;
            cin>>f;
            if(f=='y'||f=='Y')
            {
                cout<<s.Print2();
            }
            if(f=='n'||f=='N')
            {
                PrintMenu();
            }
        }
        else if(a==3)
        {
            teacher t(b,c,d,e);
            cout<<"需要显示信息吗?(y or n):"<<endl;
            cin>>f;
            if(f=='y'||f=='Y')
            {
                cout<<t.Print3();
            }
            if(f=='n'||f=='N')
            {
                PrintMenu();
            }
        }
        else
        {
            snt s(b,c,d,e);
            cout<<"需要显示信息吗?(y or n):"<<endl;
            cin>>f;
            if(f=='y'||f=='Y')
            {
                cout<<s.Print4();
            }
            if(f=='n'||f=='N')
            {
                PrintMenu();
            }
        }
    }   
}
void PrintMenu()
{
   
    cout<<"==============================================================="<<endl;
    cout<<"*****************欢迎使用学院人员信息管理系统******************"<<endl<<endl<<endl;
    cout<<"1.    学生信息管理"<<endl;
    cout<<"2.    职员信息管理"<<endl;
    cout<<"3.    教师信息管理"<<endl;
    cout<<"4.    在职读书教师管理"<<endl;
    cout<<"5.    退出本系统"<<endl<<endl<<endl;
    cout<<"==============================================================="<<endl;
    cout<<"请选择:        ";
    void Insert();
}



像这样的函数可以相互调用么???
如果不可以,要实现这样的功能应该怎么解决
4 回复
#2
2010-12-21 08:34
可以   
#3
BNV2010-12-21 13:32
回复 2楼 cacker
#include<iostream.h>
void aaa()
    {
        int a;
        cin>>a;
        cout<<"asdgdfg"<<endl;
        cout<<a;
        bbb();
    }
    void bbb()
    {
        int a;
        cin>>a;
        cout<<"wtgtrfhsdgdfg"<<endl;
        cout<<a;
        aaa();
    }
void main()
{
    cout<<"159357";
    bbb();
}


为什么这个不可以啊
#4
zhoufeng19882010-12-21 13:49
当然。

我想楼主可以深入了解一下C/C++声明与定义。
Effective C++里面讲得很清楚。

记住:用使用一个变量或者函数必须先声明才能使用。
3楼的代码,aaa函数中调用bbb函数。但程序执行时,aaa函数并不知道有bbb这样一个函数~
所以你得先声明一下。在aaa函数前加上 void bbb();
这样就可以了。

详情:参照Effective C++。
#5
BNV2010-12-21 17:21
回复 4楼 zhoufeng1988
很好,明白了
非常感谢!!!
1