首页 > 编程语言 >2023-2024-1 20231301 《计算机基础与程序设计》第十三周学习总结

2023-2024-1 20231301 《计算机基础与程序设计》第十三周学习总结

时间:2023-12-24 20:13:33浏览次数:44  
标签:stu2 77 struct int 20231301 2024 2023 date 80

2023-2024-1 20231301 《计算机基础与程序设计》第十三周学习总结

作业信息

作业 链接
作业课程 <班级>(2023-2024-1-计算机基础与程序设计
作业要求 <作业>(2023-2024-1计算机基础与程序设计第十三周学习总结)
作业目标 <《C语言程序设计》预习第十二章> 《C语言程序设计》
作业正文 <博客>(第十三周学习总结

目录

学习内容总结

《C语言程序设计》第十二章

12.1 结构体

数组:是将同种属性的数据进行一次处理
结构体:将不同类型的数据成员组织到统一的名字下
共用体:将不同类型的数据成员组织到统一的名字下,但是每一时刻只有一个数据成员起作用

struct student
{
    long studentID;
    char studentName;
    char studentSex;
    int yearOfBirth;
    int score[4];
}stu1;

用typedef定义数据类型
typedef int INTEGER;INTEGER和int是同义词。

typedef struct student STUDENT;
//等价于
typedef struct student
{
long studentID;
char studentName;
char studentSex;
int yearOfBirth;
int score[4];
}STUDENT;

二者为struct student结构体定义了一个新名字STUDENT。

结构体变量的初始化

STUDENT stu1={111,“张三”,“男”,1991,{80,80,80,80}};
//等价于:
struct student stu1={111,“张三”,“男”,1991,{80,80,80,80}};

嵌套的结构体

typedef struct date
{
    int year;
    int month;
    int day;
}DATE;
 
typedef struct student
{
    long studentID;
    char studentName;
    char studentSex;
    DATE Birthday;
    int score[4];
}STUDENT;
STUDENT stu1={111,“张三”,“男”,{1998,6,4},{80,80,80,80}};

结构体变量的引用和赋值

#include<stdio.h>
typedef struct date
{
     int year;
     int month;
     int day;
}DATE;
 
typedef struct student
{
     long studentID;
     char studentName[20];
     char studentSex;
     DATE birthday;
     int score[4];
}STUDENT;
 
int main()
{
     STUDENT stu1={111,"张三","男",{1998,6,4},{80,80,80,80}};
     STUDENT stu2;
     stu2=stu1;//相同类型的结构体的变量可以整体赋值
    printf("%ld%s%c%d/%d/%d%d%d%d%d\n",stu2.studentID,
    stu2.studentName,stu2.studentSex,stu2.birthday.year,
    stu2.birthday.month,stu2.birthday.day,stu2.score[0],
    stu2.score[1],stu2.score[2],stu2.score[3]);
     return 0;
}

并非所有的结构体成员都可以用赋值运算符(=)进行赋值,对于字符数组类型的结构体成员赋值时,必须用字符串处理函数strcpy():strcpy(stu2.studentName,stu2.studentName);

结构体所占内存的字节数

#include<stdio.h>
typedef struct sample
{
    char m1;
    int m2;
    char m3;
}SAMPLE;
int main()
{
    SAMPLE S={'A',2,'b'};
    printf("%d\n",sizeof(s));
    return 0;
}

结构体数组的定义和初始化

#include<stdio.h>
typedef struct date
{
    int year;
    int month;
    int day;
}DATE;
typedef struct student
{
    long studentID;
    char studentName[20];
    char studentSex;
    DATE birthday;
    int score[4];
}STUDENT;
int main()
{
    int i,j,sum[30];
    STUDENT stu[30]={{111,"张三","男",{77,77,77,77}},
    {112,"李四","男",{77,77,77,77}},{113,"王五","女",{77,77,77,77}},
    {114,"周六","女",{77,77,77,77}}};
    for(i=0;i<4;i++)
    {
        sum[i]=0;
        for(j=0;j<4;j++)
        {
            sum[i]+=stu[i].score[j];
        }
        printf("%ld%s%c%d/%d/%d%d%d%d%d%f\n",stu2.studentID,stu2.studentName,
        stu2.studentSex,stu2.birthday.year,stu2.birthday.month,stu2.birthday.day,
        stu2.score[0],stu2.score[1],stu2.score[2],stu2.score[3],sum[i]/4.0);
    }
    return 0;
}

结构体指针定义和初始化

STUDENT *p;
p = &stu1;
//等价于
STUDENT *P = &stu1;

指针变量指向的结构体成员用指向运算符

p->studentID=111;
//等价于:
(*p).studentID=111;
p->birthday.year=1991;//对于结构体内部数组成员的访问

向函数传递结构体

#include<stdio.h>
struct date
{
    int year;
    int month;
    int day;
};
//void fun(struct date *p)
void fun(struct date p)
{
    p.year=2000;
    p.month=5;
    p.day=22;
}
int main()
{
    struct date b;
    b.year=1999;
    b.month=4;
    b.day=21;
    //fun(&b);传址调用,结构体变量的成员值会修改
    fun(b);//结构体变量作为实参,传值调用,结构体变量的成员值不会修改
    return 0;
}
 
 
#include<stdio.h>
struct date
{
    int year;
    int month;
    int day;
};
struct date fun(struct date p)
{
    p.year=2000;
    p.month=5;
    p.day=22;
    return p;
}
int main()
{
    struct date b;
    b.year=1999;
    b.month=4;
    b.day=21;
    b=fun(b);//将函数返回值作为结构体变量的值
    return 0;
}

12.2共用体

#include<stdio.h>
union sample
{
    short i;
    char ch;
    float f;
};
typedef union sample SAMPLE;
int main()
{
    printf("%d\n",sizeof(SAMPLE));
    SAMPLE num; 
    num.i=20;
    return 0;
}

枚举数据类型

enum response{no,yes,none};//定义了一个枚举类型,no->0,yes->1,none->2;
enum response answer;//定义了一个枚举类型的变量
if(answer==yes)
{
    …;
}
//定义并初始化
enum{no,yes,none}answer;

定义一个枚举类型的数组

enum response answer[10];
enum response{no=-1,yes=1,none=0};//指定枚举常量的值
enum response{no=1,yes,none};//其后依次递增1

12.3动态数据结构—单向链表

//链表只能顺序访问,不能随机访问,尾插法
#include<stdio.h>
struct link
{
    int date;
    struct link *next;
};
struct link *AppendNode(struct link *head)
{
    struct link *p=NULL,*pr=head;
    int date;
    p=(struct link *)malloc(sizeof(struct link));
    if(p==NULL)
    {
        exit(0);
    }
    if(head==NULL)
    {
        head=p;
    }
    else
    {
        while(pr->next!=NULL)
        {
            pr=pr->next;
        }
        pr->next=p;
        scanf("%d",&date);
        p->date=date;
        p->next=NULL;
        return head;
    }
}
 
void DisplyNode(struct link *head)
{
    struct link *p=head;
    while(p!=NULL)
    {
       printf("%d ",p->date);
        p=p->next;
    }
}
 
void DeleteMemory(struct link *head)
{
    struct link *p=head,*q=NULL;
    while(p!=NULL)
    {
        q=p;
        p=p->next;
        free(q);
    }
}
 
int main()
{
    int i=0;//节点的个数
    char c;
    struct link *head=NULL;
    scanf(" %c",&c);//前面有一个空格
    while(c='y'||c='Y')
    {
        head=AppendNode(head);
        DisplyNode(head);
        scanf(" %c",&c);
        i++;
    }
    DeleteMemory(head);
    return 0;
}

学习中的问题

1.keepass口令管理实践
2.GPG实践
3.OpenSSL(系列)

标签:stu2,77,struct,int,20231301,2024,2023,date,80
From: https://www.cnblogs.com/twilight0966/p/17924683.html

相关文章

  • 2023-2024-1 20231325 《计算机基础与程序设计》第13周学习总结
    ###目录*作业信息*教材学习内容总结1.《c语言程序设计》第12章*基于AI的学习*上周错题*学习进度条作业信息这个作业属于哪个课程2023-2024-1《计算机基础与程序设计》这个作业的要求在哪里1.学习《C语言程序设计》第12章并完成云班课测试。作业正文......
  • USACO 2023 Pt T2
    有趣的小清新数据结构题。首先考虑这个合并每次找到最小的边的过程很类似于Kruskal最小生成树的合并过程,只不过每次是钦定了合并一个大联通块和一个点。由于需要从不同的起点开始考虑,也就是需要多次处理这个类似Kruskal的过程,自然想到Kruskal重构树。我们考虑建出Kruskal......
  • 2023-2024-1 学号20231324《计算机基础与程序设计》第十三周学习总结
    2023-2024-1学号20231324《计算机基础与程序设计》第十二周学习总结作业信息这个作业属于哪个课程2023-2024-1-计算机基础与程序设计这个作业要求在哪里2023-2024-1计算机基础与程序设计第十三周作业这个作业的目标《C语言程序设计》第12章并完成云班课测......
  • 2023-2024-1 学号:20231305 《计算机基础与程序设计》第13周学习总结
    2023-2024-1学号:20231305《计算机基础与程序设计》第13周学习总结作业信息这个作业属于哪个课程<班级的链接>(如2022-2023-1-计算机基础与程序设计)这个作业要求在哪里<作业要求的链接>(如2022-2023-1计算机基础与程序设计第一周作业)这个作业的目标<自学教材《C......
  • 学年(2023-2024-1)学号(20231311)《计算机基础与程序设计》第13周学习总结
    2023-2024-120231311《计算机基础与程序设计》第13周学习总结作业信息这个作业属于哪个课程2023-2024-1-计算机基础与程序设计这个作业要求在哪里2023-2024-1计算机基础与程序设计第十二周作业这个作业的目标学习《C语言程序设计》第12章并完成云班课测试作业......
  • 涛思数据荣登2023胡润全球猎豹企业榜,胡润研究院首次发布
    12月19日,胡润百富在广州南沙举办“2023胡润全球猎豹企业大会”暨《2023胡润全球猎豹企业榜》。据了解,《2023胡润全球猎豹企业榜》(HurunGlobalCheetahIndex2023)是提供全球最大独角兽及未来独角兽榜单的胡润研究院与广州南沙联合发布,榜单列出了全球成立于2000年之后,五年内......
  • #2023-2024-1 20231408《计算机基础与程序设计》第十三周学习总结
    作业信息这个作业属于哪个课程<2023-2024-1-计算机基础与程序设计>这个作业要求在哪里<2023-2024-1计算机基础与程序设计第十三周作业>这个作业的目标<《C语言程序设计》第12章,上周测试题>作业正文https://www.cnblogs.com/jfxyh061028/p/17924320.html教......
  • 再创佳绩!拓数派荣获 2023年度技术卓越奖
    近日,由知名IT信息科技门户网站IT168正式公布了“2023年度技术卓越奖”评选结果,拓数派凭借自主研发的大模型数据计算系统「πDataCS」斩获2023年度技术卓越奖奖项。拓数派本次获得年度技术卓越奖是市场、媒体、与社区的多重认可成果,充分肯定了拓数派的技术研发实力与产品创新......
  • 学期2023-2024-1 20231409 《计算机基础与程序设计》第十三周学习总结
    学期2023-2024-120231409《计算机基础与程序设计》第十三周学习总结作业信息这个作业属于哪个课程2023-2024-1-计算机基础与程序设计这个作业要求在哪里2023-2024-1计算机基础与程序设计第十三周作业这个作业的目标自学《C语言程序设计》第十二章并完成云班课测试......
  • Pycharm最新版2023.3.1激活教程 亲测有效
    第一步:官网下载安装包官网下载链接https://www.jetbrains.com/pycharm/download直接点击Download下载,等待安装程序下载完成。第二步:安装Pycharm最新版惯例哈,安装新版本之前先卸载老版本的程序,然后再安装新的。这里演示,默认安装路径了,最好安装在非系统盘路径,防止后期越用越大,电脑卡......