CellPhone 发布的文章

#include<iostream>
using namespace std;
struct teacher
{
    char name[20];
    int teachage;
    float pay;
};
int main()
{
    int x, y;
    cout << "请输入教师职工的信息\n";
    struct teacher th[5];               //定义结构体数组
    for (x = 0; x < 5; x++)
    {
        cout << "请输入第" << x+1 << "位教师职工的姓名:";
        cin >> th[x].name;
        cout << "请输入第" << x+1 << "位教师职工的教龄:";
        cin >> th[x].teachage;
        cout << "请输入第" << x+1 << "位教师职工的工资总额:";
        cin >> th[x].pay;
        cout << "\n";
    }
    cout << "这5位教师职工的信息如下:\n";
    cout << "姓名\t" << "教龄\t" << "工资总额\n";
    for (y = 0; y < 5; y++)            //输出结构体数组里的元素
    {
        cout << th[y].name << "\t" << th[y].teachage << "\t" << th[y].pay << "\n";
    }
    system("pause");
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    char x[5];
    char *p;
    cout << "请输入一个字符串(5位):\n";
    cin >> x;
    cout << "字符串反转后为:";
    for (p = &x[5];p >= x; p--)
    {
        cout << *p;
    }
    system("pause");
    return 0;
}

/********************************************************************
*  功能:实现将一个字符串连接到另一个字符串尾部,并输出结果  *
*                                                                                              *
********************************************************************/
#include<iostream>
using namespace std;
int main()
{
    char x[50], y[50];               //定义两个字符数组
    int a, x1, x2;
    cout << "请输入字符串X:\n";      //从键盘为两个字符数组赋值
    cin >> x;
    cout << "请输入字符串Y:\n";
    cin >> y;
    x1 = strlen(x);          //取字符串x的长度(不包括'\0')
    x2 = strlen(y);
    for (a = 0; y[a] != '\0'; a++)
    {
        x[a + x1] = y[a];           //将字符串y赋值到x
    }
    x[x1 + x2] = '\0';              //字符串缺少必要的结尾符'\0'会出现“烫”字错误
    cout <<"连接后的字符串X为:"<< x << "\n";          //输出连接后的字符串
    system("pause");
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    int a[5] = { 1,2,3,4,5 };
    int *p = 0;
    cout << "下标运算a[i]:" << "\n";
    for (int x = 0; x < 5; x++)
    {
        cout << a[x];
    }
    cout << "\n指针运算(*p):" << "\n";
    for (p = a; p < &a[5]; p++)
    {
        cout << *p;
    }
    system("pause");
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
    int i, z = 0, min, max;
    int a[8] = { 12,23,34,45,56,67,78,89 };
    max = a[0];
    min = a[0];
    for (i = 0; i < 8; i++)
    {
        if (min > a[i])
            min = a[i];
        else
            if (max < a[i])
                max = a[i];
    }
    cout << "该数组中最大值为:"<<max<<"\n最小值为:"<<min;
    system("pause");
    return 0;
}