| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 559 人关注过本帖
标题:棘手的问题,高手进来
只看楼主 加入收藏
qq8801103
Rank: 5Rank: 5
来 自:苏州中科大软件学院
等 级:职业侠客
威 望:1
帖 子:422
专家分:340
注 册:2009-10-8
结帖率:73.96%
收藏
已结贴  问题点数:20 回复次数:4 
棘手的问题,高手进来
程序代码:
#include "stdafx.h"
#include <string.h>
#include <iostream>
using namespace std;
int count = 0;

struct student
{
    int num;     //学号
    char name[15];   //姓名 
    int age;    //年龄
    int sex;   //1代表男,0代表女
    char borntime[15]; //出生年月
};
struct student stu[50];

//输入学生信息
struct student  input()
{
    float sum = 0;
    struct student st;
    cout<<"\n\t请输入学员的信息\n";
    cout<<"\n请输入学号:";
    cin>>st.num;
    cout<<"请输入姓名:";
    fflush(stdin);
    cin>>st.name;
    cout<<"请输入年龄:";
    cin>>st.age;
    cout<<"请输入性别";
    cout<<"(1代表男性,0代表女性)";
    cin>>st.sex;
    cout<<"请输入出生年月:";
    fflush(stdin);
    cin>>st.borntime;
    return st;
}

//打印学生信息
void display()
{
    int i;
    for(i = 0;i<count;i++)
    {
        cout<<"\n--------------学号:"<<stu[i].num;
        cout<<"\n--------------姓名:"<<stu[i].name;
        cout<<"\n--------------年龄:"<<stu[i].age;
        cout<<"\n--------------性别:"<<stu[i].sex;
        cout<<"\n----------出生年月:"<<stu[i].borntime;
    }

}

//删除学生信息
void deleted ()
{
    int n,i,j=0;
    //寻找
    cout<<"\n请输入要删除的学生的学号:";
    cin>>n;
    for(i=0;i<count;i++)
    {
        if(n==stu[i].num)
            break;
    }
    if(i<count - 1)
    {
        for(j=i;j<count-1;j++)
        {
            stu[j]=stu[j+1];
        }
        count--;
    }
    else if(i==count-1)
        count--;
}


//插入学生信息
void insert ()
{
    //struct student stu1;    //定义一个结构体变量
    cout<<"\n请输入要插入的学生信息:";
    stu[count++]=input();
}



int _tmain(int argc, _TCHAR* argv[])
{
    struct student *p;
    int i=0;
    int cout1=1;
    int flag = 1,choose;
    p = &stu[i];
    cout<<"\n\t    学生信息管理系统";
    while(cout1)
    {
        cout<<"\n------------1-输入学生信息------------";
        cout<<"\n------------2-插入学生信息------------";
        cout<<"\n------------3-删除学生信息------------";
        cout<<"\n------------4-显示学生信息------------";
        cout<<"\n------------0-----退出----------------\n";
        cin>>choose;
        switch(choose)
        {
        case 1:
            {
                while(flag==1)
                {

                    for(i=0;i<50;i++)
                    {
                        stu[i]=input();
                        count++;
                        cout<<"是否继续输入:(y/n)";
                        fflush(stdin);
                        if((getchar())=='n'||(getchar())=='N')
                        {   
                            flag = 0;
                            break;
                        }
                    }
                }
                continue;

            }
        case 2:
            {
                insert();
                continue;
            }
        case 3:
            {
                deleted();
                continue;
            }
        case 4:
            {
                display();
                continue;
            }
        case 0:
            {   
                cout<<"\n\t谢谢使用!\n";
                cout1=0;
                break;
            }
        }
    }
    return 0;
}
用VS2010编写的学生信息算法,怎么把结构体数组转换成C++中的容器来做
搜索更多相关主题的帖子: color 
2011-10-24 19:48
a373339205
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:30
专家分:134
注 册:2011-6-9
收藏
得分:5 
vector<struct student> stu[50];
只要容器的类型是struct student就可以了
2011-10-24 21:31
cosam
Rank: 4
等 级:业余侠客
帖 子:146
专家分:259
注 册:2011-8-25
收藏
得分:10 
学容器前最好先学了模板、类,这样容器会很容易理解,
当然如果你能有数据结构的知识,会更加容易用容器。
2011-10-31 00:40
jcw08120110
Rank: 8Rank: 8
来 自:南京
等 级:蝙蝠侠
帖 子:272
专家分:742
注 册:2009-6-8
收藏
得分:5 
向量就是一种模板类~ 所有使用模板的对象的定义都要用到尖括号<> !!!!

君生我未生 我生君以老
2011-10-31 14:55
sandunban
Rank: 1
等 级:新手上路
帖 子:6
专家分:3
注 册:2011-11-7
收藏
得分:0 
学习学习。   新手  看不懂呃
2011-11-07 12:40
快速回复:棘手的问题,高手进来
数据加载中...
 
   



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

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