c++ 自定义数据结构运用

教学内容:  
定义结构
定义结构变量
访问结构成员  
定义结构数组
实例运用
 
例:记录学生到校时间(精确到秒)
     
 struct mytime
{
  int hour;//
  int min;//
  int sec;//
};


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h> 
#include <time.h>

 
 
 
 int main(int argn,char* argv[])// int a[1]//a[0]
 {       
     struct mytime
     {   
         //char name[256];
         int hour;//
         int min; //
         int sec; //
     };

     struct stu_data
     {
         char name[256];//学生名字
         struct mytime stuTime;//签到时间

     }  ;

     struct stu_data stu[50];
     time_t t;// long int
     struct tm * timfo;
     int i;
 
     
     
     for (i=0;i<3;i++)
     {
         scanf("%s",&stu[i].name);
         time(&t);
         timfo= localtime(&t); //取当前系统时间
         stu[i].stuTime.hour=timfo->tm_hour;//
         stu[i].stuTime.min=timfo->tm_min;//
         stu[i].stuTime.sec=timfo->tm_sec;//



     }
     //显示学生到校时间
     for (i=0;i<3;i++)
     {
         
         time(&t);
         timfo= localtime(&t); //取当前系统时间
         printf("%s,到校时间:%d时%d分%d秒\n",stu[i].name, stu[i].stuTime.hour, stu[i].stuTime.min, stu[i].stuTime.sec);



     }

 

posted @ 2016-12-02 17:20  whzym111  阅读(272)  评论(0编辑  收藏  举报