示例#1
0
int main()
{
    // new一个班级对象
    // 后面向该班级的学生做一些操作
    MyClass* myclass = new MyClass;

    do
    {
        setup();
        int nMenu;
        cin >> nMenu;
        clean();
        switch (nMenu)
        {
        case 1: // 录入学生记录
            myclass->addStudent();
            clean();
            break;
        case 2: // 列出学生信息
        {
            if( myclass->getCount() == 0)
                cout << "当前班级学生数为0,请录入学生记录。";
            else
                myclass->printInfo();

            system("pause");
            clean();
        };
            break;
        case 3: // 修改学生信息
            if( myclass->getCount() == 0)
                cout << "当前班级学生数为0,请录入学生记录。";
            else
            {
                myclass->printInfo();
                cout << "输入要修改的学生的学号:";
                int id;
                cin >> id;
                myclass->edit(id);
            }
            system("pause");
            clean();
            break;
        case 4: // 删除学生信息
            if( myclass->getCount() == 0)
                cout << "当前班级学生数为0,请录入学生记录。";
            else
            {
                myclass->printInfo();
                cout << "输出要删除的学生的学号:";
                int id;
                cin >> id;
                if ( myclass->remove(id) )
                    cout << "删除成功!";
                else
                    cout << "删除失败!没有该学号。";
            }
            system("pause");
            clean();
            break;
        case 5: // 排序
            if( myclass->getCount() == 0)
                cout << "当前班级学生数为0,请录入学生记录。";
            else
            {
                cout << "当前班级学生升序排序结果: \n";
                cout<< "学号\t姓名\t年龄\t电话\t班级\t性别\n";
                myclass->ascSort();
            }
            system("pause");
            clean();
            break;
        case 6: // 计数
            cout << "当前班级学生总数为: " << myclass->getCount() << endl;
            system("pause");
            clean();
            break;
        case 7: // 退出
            cout << "按回车退出程序。";
            return 0;
        }
    }while(1);

    return 0;
}
示例#2
0
int main()
{
    // TestCase Group1:
    MemPool objMemPool;
    MemPool *pMemPool = &objMemPool;
    int32_t nCount = 10;
    char *pszArray = NEW_VEC(pMemPool, char, nCount);
    int32_t *pnArray = NEW_VEC(pMemPool, int32_t, nCount);
    float *pfArray = NEW_VEC(pMemPool, float, nCount);
    for (int i = 0; i < nCount; i++) {
        pszArray[i] = 'a' + i;
        pnArray[i] = i;
        pfArray[i] = 1.0 * i;
    }
    for (int i = 0; i < nCount; i++) {
        fprintf(stdout, "pszArray[%d]:\t%c\n", i, pszArray[i]);
        fprintf(stdout, "pnArray[%d]:\t%d\n", i, pnArray[i]);
        fprintf(stdout, "pfArray[%d]:\t%f\n", i, pfArray[i]);
    }
    pMemPool->reset();

    // TestCase Group2:
    MemPool objMemPool2;
    MemPool *pMemPool2 = &objMemPool2;
    int32_t nCount2 = 10;
    MyClass *pMyClass = NEW(pMemPool2, MyClass);
    fprintf(stdout, "pMyClass:\t%d\n", pMyClass->getCount());
    MyClass *pMyClass2 = NEW(pMemPool2, MyClass)(100);
    fprintf(stdout, "pMyClass2:\t%d\n", pMyClass2->getCount());
    MyClass *pMyClassArray = NEW_ARRAY(pMemPool2, MyClass, nCount2);
    for (int i = 0; i < nCount2; i++) {
        fprintf(stdout, "pMyClassArray[%d]:\t%d\n", i, pMyClassArray[i].getCount());
    }
    pMemPool2->reset();

    // TestCase Group3:
    MemPool objMemPool3;
    MemPool *pMemPool3 = &objMemPool3;
    MemMonitor memMonitor(pMemPool3, 1);
    pMemPool3->setMonitor(&memMonitor);
    memMonitor.enableException();
    int32_t nCount3 = 1;
    char *pszArray3 = NEW_VEC(pMemPool3, char, nCount3);
    if (!pszArray3) {
        printf("pszArray3 NEW_VEC Err!\n");
    }
    nCount3 = 1024;
    int32_t *pnArray3 = NEW_VEC(pMemPool3, int32_t, nCount3);
    if (!pnArray3) {
        printf("pnArray3 NEW_VEC Err!\n");
    }
    float *pfArray3 = NEW_VEC(pMemPool3, float, nCount3);
    if (!pfArray3) {
        printf("pfArray3 NEW_VEC Err!\n");
    }
    for (int i = 0; i < nCount3; i++) {
        pszArray3[i] = 'a' + i;
        pnArray3[i] = i;
        pfArray3[i] = 1.0 * i;
    }
    for (int i = 0; i < nCount3; i++) {
        fprintf(stdout, "pszArray3[%d]:\t%c\n", i, pszArray3[i]);
        fprintf(stdout, "pnArray3[%d]:\t%d\n", i, pnArray3[i]);
        fprintf(stdout, "pfArray3[%d]:\t%f\n", i, pfArray3[i]);
    }
    pMemPool3->reset();

    // TestCase Group4:
    MemPool objMemPool4;
    MemPool *pMemPool4 = &objMemPool4;
    MemMonitor memMonitor4(pMemPool4, 1);
    pMemPool4->setMonitor(&memMonitor4);
    memMonitor4.enableException();
    
    int32_t nCountsz4 = 1024;
    char *pszArraysz4 = NEW_VEC(pMemPool4, char, nCountsz4);
    if (!pszArraysz4) {
        printf("pszArraysz4 is NULL\n");
    }
    MyClass *pMyClass4 = NEW(pMemPool4, MyClass);
    if (!pMyClass4) {
        printf("pMyClass4 is NULL\n");
    }
    fprintf(stdout, "pMyClass4:\t%d\n", pMyClass4->getCount());

    int32_t nCountsz4_1 = 1024;
    char *pszArraysz4_1 = NEW_VEC(pMemPool4, char, nCountsz4_1);
    if (!pszArraysz4_1) {
        printf("pszArraysz4_1 is NULL\n");
    }
    MyClass *pMyClass4_1 = NEW(pMemPool4, MyClass)(100);
    if (!pMyClass4_1) {
        printf("pMyClass4_1 is NULL\n");
    }
    fprintf(stdout, "pMyClass4_1:\t%d\n", pMyClass4_1->getCount());
    
    int32_t nCountsz4_2 = 1024;
    char *pszArraysz4_2 = NEW_VEC(pMemPool4, char, nCountsz4_2);
    if (!pszArraysz4_2) {
        printf("pszArraysz4_2 is NULL\n");
    }
    int32_t nCount4_2 = 1;
    MyClass *pMyClassArray4_2 = NEW_ARRAY(pMemPool4, MyClass, nCount4_2);
    if (!pMyClassArray4_2) {
        printf("pMyClassArray4_2 is NULL\n");
    }
    for (int i = 0; i < nCount4_2; i++) {
        fprintf(stdout, "pMyClassArray4_2[%d]:\t%d\n", i, pMyClassArray4_2[i].getCount());
    }
    pMemPool4->reset();

    return 0;
}