zoukankan      html  css  js  c++  java
  • 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秒
    ",stu[i].name, stu[i].stuTime.hour, stu[i].stuTime.min, stu[i].stuTime.sec);
    
    
    
         }
  • 相关阅读:
    How to print GETDATE() in SQL Server with milliseconds in time?
    StarLink卫星网络如何工作
    Chinasat16
    天线增益计算
    Schemachine
    源代码之整洁代码
    关于进程内缓存与分布式缓存
    IOT物联网时代测试演化
    互联网大促运维实践案例
    Kubernetes应用场景
  • 原文地址:https://www.cnblogs.com/whzym111/p/6126534.html
Copyright © 2011-2022 走看看