正在加载图片...
cou←<"请输入”<<N<<个学生的学号、姓名和成绩"<end; for(F0; <N; i++) cin>>st[i- no>>st. name>>stiscore cout<<"\nIt NO tName\tScroen: cout<<t ∥指针取结构数组首地址 for (F0; K<N; i++) cout<<it'<<p->no<<It'<<p->name<<It'<<p->score<<endl; ∥指针移到下一个结构体元素 3结构体传递参数示例 #includesiostream. h> #define n 4 char name[ 16 int math: int float ave }stN={"Sun",78,91,0},{" Zhang",60,76,0},{Qian",88,95,0},{"Fang",60,70,0}; void show(record s) ave=(s math+s eng)2.0; cout<<s name<<'It<<s math<<'It<<seng<<'t<<s ave<<endl; void maino cou<"姓名"<'<<"数学”<<"t<"英语"<<"t<<"平均分"<endl; cout<<. for(i=0;<N;i++) show(stl) 4返回结构体值的示例 #includesiostream.h> #define n 4 struct record char name 16 int engi float avecout<<"请输入"<<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"; p=st; //指针取结构数组首地址 for (i=0;i<N;i++) { cout<<'\t'<<p->no<<'\t'<<p->name<<'\t'<<p->score<<endl; p++; //指针移到下一个结构体元素 } } 3 结构体传递参数示例 #include<iostream.h> #define N 4 struct record { char name[16]; int math; int eng; float ave; } st[N]={{"Sun",78,91,0},{"Zhang",60,76,0},{"Qian",88,95,0},{"Fang",60,70,0}}; void show(record s) { s.ave=(s.math+s.eng)/2.0; cout<<s.name<<'\t'<<s.math<<'\t'<<s.eng<<'\t'<<s.ave<<endl; } void main() { int i; cout<<"姓名"<<'\t'<<"数学"<<'\t'<<"英语"<<'\t'<<"平均分"<<endl; cout<<"------------------------------\n"; for (i=0;i<N;i++) show(st[i]); } 4 返回结构体值的示例 #include<iostream.h> #define N 4 struct record { char name[16]; int math; int eng; float ave;
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有