求程序,用c++函数调用!

函数的综合应用
题目:定义子函数,利用函数调用实现“数组篇理系统”的功能。
系统基本功能要求:
数组管理系统
1.输入教组元素
2.输出数组元表
3.数组升序输出
4.插入数组元素
5.删除数组元素
6.寻找数组最大值
7.交换数组元素
0.退出系统

菜单输出是独立的函数文件

代码如下:

#include <iostream>
using namespace std;

void input(int a[],int n)
{
    for (int i = 0;i<n;i++)
    {
        cin >> a[i];
    }
}
void show(int a[],int n)
{
    for (int i = 0;i<n;i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}

//冒泡排序
void bubble_sort(int a[],int n)
{
    int i,j,t;
    for (i=0;i<n-1;i++)
    {
        for (j=0;j<n-1-i;j++)
        {
            if(a[j] > a[j+1])  //从小到大,升序
            {
                t = a[j];
                a[j]=a[j+1];
                a[j+1]=t;
            }
        }
    }
}

//pos从1-n
int insert(int a[],int &n,int pos,int data)
{
    if(pos<=0 || pos >n+1)
    {
        cout << "插入位置非法,插入失败"<<endl;
        return 0;
    }
    pos--;
    for (int j=n;j>pos;j--)
    {
        a[j] = a[j-1];
    }
    a[pos] = data;
    n++;
    return 1;
}

//删除
int deleteEld(int a[],int &n,int pos)
{
    if(pos<=0 || pos >n)
    {
        cout << "删除位置非法,删除失败"<<endl;
        return 0;
    }
    pos--;
    for (int j=pos;j<n-1;j++)
    {
        a[j] = a[j+1];
    }
    n--;
    return 1;
}

int max(int a[],int n)
{
    int mm = a[0];
    for (int i = 1;i<n;i++)
    {
        if(a[i] > mm)
            mm = a[i];
    }
    return mm;
}

//交换
int change(int a[],int n,int p1,int p2)
{
    if(p1<=0 || p1 >n || p2<=0 || p2 >n)
    {
        cout << "交换位置非法,交换失败"<<endl;
        return 0;
    }
    p1--;
    p2--;
    int t = a[p1];
    a[p1] = a[p2];
    a[p2] = t;
    return 1;
}

int main()
{
    int a[100],n;
    cout << "请输入数组元素个数:";
    cin >> n;
    cout << "请输入数组元素:";
    input(a,n);
    cout << "输出数组元素:";
    show(a,n);
    cout << "数组升序排序后:";
    bubble_sort(a,n);
    show(a,n);

    cout << "请输入插入位置(从1开始)和插入数据:";
    int pos,data;
    cin >> pos >> data;
    insert(a,n,pos,data);
    cout << "插入后数组元素:";
    show(a,n);

    cout << "请输入删除位置:";
    cin >> pos;
    deleteEld(a,n,pos);
    cout << "删除后数组元素:";
    show(a,n);

    cout << "数组中最大的数是:" << max(a,n)<<endl;

    cout << "请输入需要交换的两个位置:";
    int p1,p2;
    cin >> p1>>p2;
    change(a,n,p1,p2);
    cout << "交换位置后数组元素:";
    show(a,n);

    return 0;
}


这是问答版块,不是下需求板块