| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 335 人关注过本帖
标题:帮忙看一下,这个程序为什么不显示第一个元素的fullname?
只看楼主 加入收藏
qiyonghong
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-3-23
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:1 
帮忙看一下,这个程序为什么不显示第一个元素的fullname?
#include<iostream>
using namespace std;
const int SLEN=30;
struct student
{
    char fullname[SLEN];
    char hobby[SLEN];
    int ooplevel;
};
int getinfo(student pa[],int n);
void display1(student st);
void display2(const student* ps);
void display3(student pa[],int n);
int main()
{
    cout<<"Enter class size: ";
    int class_size;
    cin>>class_size;
    while(cin.get()!='\n')
        continue;
    student* ptr_stu=new student[class_size];
    int entered=getinfo(ptr_stu,class_size);
    for(int i=0;i<entered;i++)
    {
        display1(ptr_stu[i]);
        display2(&ptr_stu[i]);
    }
    display3(ptr_stu,entered);
    delete [] ptr_stu;
    return 0;
}
int getinfo(student pa[],int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        cout<<"Enter element # "<<i+1<<":\n";
        cout<<"Enter student's fullname:";
        while(cin.get()!='\n')
        continue;
        cin.getline(pa[i].fullname,SLEN);
        cin.getline(pa[i].fullname,SLEN);
        cout<<"Enter student's hobby:";
        cin.getline(pa[i].hobby,SLEN);
        cout<<"Enter student's ooplevel:";
        cin>>pa[i].ooplevel;
    }
    return i;
}
void display1(student st)
{
    cout<<"============================\n";
    cout<<"student's fullname="<<st.fullname<<endl;
    cout<<"student's hobby="<<st.hobby<<endl;
    cout<<"student's ooplevel="<<st.ooplevel<<endl;
    cout<<"============================\n";
}
void display2(const student* ps)
{
    cout<<"============================\n";
    cout<<"student's fullname="<<ps->fullname<<endl;
    cout<<"student's hobby="<<ps->hobby<<endl;
    cout<<"student's ooplevel="<<ps->ooplevel<<endl;
    cout<<"============================\n";
}
void display3(student pa[],int n)
{
    cout<<"============================\n";
    for(int i=0;i<n;i++)
       {
          cout<<"student's fullname="<<pa[i].fullname<<endl;
          cout<<"student's hobby="<<pa[i].hobby<<endl;
          cout<<"student's ooplevel="<<pa[i].ooplevel<<endl;
       }
    cout<<"============================\n";
}
搜索更多相关主题的帖子: void class continue include Enter 
2012-03-23 09:20
hellovfp
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:禁止访问
威 望:30
帖 子:2976
专家分:7697
注 册:2009-7-21
收藏
得分:14 
int getinfo(student pa[],int n)
{
    int i;
    for(i=0;i<n;i++)
    {
        cout<<"Enter element # "<<i+1<<":\n";
        cout<<"Enter student's fullname:";
        //while(cin.get()!='\n')
        //continue;
        cin.getline(pa[i].fullname,SLEN);
        //cin.getline(pa[i].fullname,SLEN); 去掉这行就可以显示了
        cout<<"Enter student's hobby:";
        cin.getline(pa[i].hobby,SLEN);
        cout<<"Enter student's ooplevel:";
        cin>>pa[i].ooplevel;
    }
    return i;
}

我们都在路上。。。。。
2012-03-23 10:58
快速回复:帮忙看一下,这个程序为什么不显示第一个元素的fullname?
数据加载中...
 
   



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

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