正在加载图片...
结构体的有关例题 1.结构体数组元素的输入和输出 #includesiostream.h> #define 4 void main( i struct student char name 16]: float score struct student stN: int 1; cou<"请输入"<<N<"个学生的学号、姓名和成绩"<end; for(i=0; K<N; i++) cin>>sti. no>>sti name>>stiscore; cout<<nIt NO\tName\tScroeln for F0; K<N; i++) cout<<It<<stI. no<<it'<<st[ name<<'It<<st]. score<<endl; 当输入 9911 LiMing 87 9912 liuLiang 78 9913 WangXing 90 9914 ZhaoQin 67 程序运行结果如下: NO LiMin 87 912 liuliang 9913 WangXing 90 14 ZhaoQin 67 2将上例输出语句中结构体数组,改用结构体指针变量。 #includesiostream. h> #define n4 void maino struct student int no char name 16]; float score; struct student stN, "p; int 1;结构体的有关例题 ⒈结构体数组元素的输入和输出 #include<iostream.h> #define N 4 void main() { struct student {int no; char name[16]; float score;} ; struct student st[N]; int i; cout<<"请输入"<<N<<" 个学生的学号、姓名和成绩"<<endl; for (i=0;i<N;i++) cin>>st[i].no>>st[i].name>>st[i].score; cout<<"\n\t NO.\tName\tScroe\n"; cout<<"\t---------------------\n"; for (i=0;i<N;i++) cout<<'\t'<<st[i].no<<'\t'<<st[i].name<<'\t'<<st[i].score<<endl; } 当输入: 9911 LiMing 87 9912 liuLiang 78 9913 WangXing 90 9914 ZhaoQin 67 程序运行结果如下: NO. Name Score 9911 LiMing 87 9912 liuLiang 78 9913 WangXing 90 9914 ZhaoQin 67 2 将上例输出语句中结构体数组,改用结构体指针变量。 #include<iostream.h> #define N 4 void main() { struct student {int no; char name[16]; float score; } ; struct student st[N], *p; int i;
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有