正在加载图片...
实验8结构体的应用 【实验目的】 1掌握结构的概念、定义及应用; 2掌握结构变量的定义和初始化: 3掌握结构成员的访问、结构赋值的含义以及结构与指针、函数的关系。 【实验内容】 1.输入你的学号、姓名、性别、年龄、出生日期,然后输出 # include≤ iostream. h> #include <iomanip. h> struct date ∥定义出生日期结构体类型 short year; short month; short day: struct man char num 5 char name 201: char sex: int struct date birthday void main( cout<<"input num, name, sex, age, birthday(year, month, day): <<endl; ly l. in>>emply l. birthday year>>emply l birthday month cin>>emply l birthday day cout<<setw(5 <<"num"<<setw(10<<name<<setw(5<<"sex (13 <<"birthd cout<<setw(5 <<emply l num<<setw(10<<emply l name<<setw(5)<<emply lsex; cout<<setw (5 <<emply l age<<setw (8 <<emply l birthday year<<.; cout<<emply l birthday month<<. <<emply l birthday day<<endl; 2打印出你宿舍的通讯录。该通讯录包括:姓名、住址、电话、E-mail等。 #includesiostream. h> 0 i struct student char name 20 char adres char phone 20; char email30B; struct student stN; cout<<"请输入"<<N<<”个学生的姓名、地址、电话和E-mai"<end for(F0; K<N; i++)实验 8 结构体的应用 【实验目的】 1 掌握结构的概念、定义及应用; 2 掌握结构变量的定义和初始化; 3 掌握结构成员的访问、结构赋值的含义以及结构与指针、函数的关系。 【实验内容】 ⒈输入你的学号、姓名、性别、年龄、出生日期,然后输出。 #include <iostream.h> #include <iomanip.h> struct date //定义出生日期结构体类型 {short year; short month; short day;}; struct man {char num[5]; char name[20]; char sex; int age; struct date birthday;}; void main( ) { man emply1; cout<<"input num,name,sex,age,birthday(year,month,day):"<<endl; cin>>emply1.num>>emply1.name>>emply1.sex>>emply1.age; cin>>emply1.birthday.year>>emply1.birthday.month; cin>>emply1.birthday.day; cout<<setw(5)<<"num"<<setw(10)<<"name"<<setw(5)<<"sex"; cout<<setw(5)<<"age"<<setw(13)<<"birthday"<<endl; cout<<setw(5)<<emply1.num<<setw(10)<<emply1.name<<setw(5)<<emply1.sex; cout<<setw(5)<<emply1.age<<setw(8)<<emply1.birthday.year<<'.'; cout<<emply1.birthday.month<<'.'<<emply1.birthday.day<<endl; } ⒉打印出你宿舍的通讯录。该通讯录包括:姓名、住址、电话、E-mail 等。 #include<iostream.h> #define N 4 void main() { struct student {char name[20]; char adress[80]; char phone[20]; char email[30];} ; struct student st[N]; int i; cout<<"请输入"<<N<<" 个学生的姓名、地址、电话和 E-mail"<<endl; for (i=0;i<N;i++)
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有