您的位置:首页 > 其它

带参构造函数为结构体对象数组赋值的方法

2013-06-05 21:27 393 查看
struct student
 {  
       char name[10];  
       int sore1,sore2,sore3; 
       student(char a[10],int d,int b,int c)
       {
           strcpy(name,a);
           sore1=d;
           sore2=b;
           sore3=c;
       }
 }; 

int main()
{
    student stud[5]=  
    {  
            student("chenlan",85,78,76),  
            student("huanghong",97,68,87),  
            student("zhanghua",67,98,67),  
            student("yexuan",98,87,76),  
            student("baiwei",87,68,98)  
    };
    for (int i=0;i<5;i++)
    {
        printf("%s\t%d\t%d\t%d\t\n",stud[i].name,stud[i].sore1,stud[i].sore2,stud[i].sore3);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: