C程式設計(譚浩強)第五版課後題答案 第九章

来源:https://www.cnblogs.com/lazyheartkx/archive/2022/05/18/16285105.html
-Advertisement-
Play Games

大家好,這篇文章分享了C程式設計(譚浩強)第五版第九章課後題答案,所有程式已經測試能夠正常運行,如果小伙伴發現有錯誤的的地方,歡迎留言告訴我,我會及時改正!感謝大家的觀看!!! ...


1.定義一個結構體變數(包括年、月、日)。計算該日在本年中是第幾天,註意閏年問題。

#include <stdio.h>

struct Date{
    int year;
    int month;
    int day;
};

int main()
{
    struct Date date;
    int i=0,no=0;
    int Month[12]={31,28,31,30,31,30,31,31,30,31,30,31};

    printf("請輸入日期(年、月、日):");
    scanf("%d %d %d",&date.year,&date.month,&date.day);

    no+=date.day;
    for(i=0;i<date.month-1;i++)
        no+=Month[i];

    if(date.year%4==0 && date.year%100!=0 || date.year%400==0)
        no+=1;

    printf("%d月%d日是%d年的第%d天!\n",date.month,date.day,date.year,no);
    return 0;
}

 

2.寫一個函數days,實現第1 題的計算。由主函數將年、月、日傳遞給days函數,計算後將日子數傳回主函數輸出。

#include <stdio.h>

struct Date{
    int year;
    int month;
    int day;
};

int main()
{
    struct Date date;
    int i=0,no;
    int days(struct Date date);

    printf("請輸入日期(年、月、日):");
    scanf("%d %d %d",&date.year,&date.month,&date.day);

    no=days(date);
    
    printf("%d月%d日是%d年的第%d天!\n",date.month,date.day,date.year,no);
    return 0;
}
int days(struct Date date)
{
    int i,no=0;
    int Month[12]={31,28,31,30,31,30,31,31,30,31,30,31};

    no+=date.day;
    for(i=0;i<date.month-1;i++)
        no+=Month[i];

    if(date.year%4==0 && date.year%100!=0 || date.year%400==0)
        no+=1;
    return no;
}

 

3.編寫一個函數print,列印一個學生的成績數組,該數組中有5個學生的數據記錄,每個記錄包括num,name,score[3],用主函數輸人這些記錄,用print函數輸出這些記錄。

#include <stdio.h>
#define M 20

struct student{
    int num;
    char name[M];
    int score[3];
};

int main()
{
    int i;
    struct student stu[5];
    void myprint(struct student stu[5]);

    printf("請按以下格式依次輸入5名學生的信息:\n");
    printf("num name score1 score2 score3\n");
    for(i=0;i<5;i++)
        scanf("%d %s %d %d %d",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);

    myprint(stu);

    return 0;
}
void myprint(struct student stu[5])
{
    int i;
    printf("num name score1 score2 score3\n");
    for(i=0;i<5;i++)
        printf("%3d %3s %3d %3d %3d\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
}

 

4.在第3題的基礎上,編寫一個函數input,用來輸人5個學生的數據記錄。

#include <stdio.h>
#define M 20

struct student{
    int num;
    char name[M];
    int score[3];
};

int main()
{
    struct student stu[5];
    void myprint(struct student stu[5]);
    void input(struct student stu[5]);

    input(stu);
    myprint(stu);

    return 0;
}
void myprint(struct student stu[5])
{
    int i;
    printf("num name score1 score2 score3\n");
    for(i=0;i<5;i++)
        printf("%3d %3s %3d %3d %3d\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
}

void input(struct student stu[5])
{
    int i;
    printf("請按以下格式依次輸入5名學生的信息:\n");
    printf("num name score1 score2 score3\n");
    for(i=0;i<5;i++)
        scanf("%d %s %d %d %d",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}

 

5.有10個學生,每個學生的數據包括學號、姓名、3門課程的成績,從鍵盤輸人10個學生數據,要求輸出3門課程總平均成績,以及最高分的學生的數據(包括學號、姓名、3門課程成績、平均分數)。

#include <stdio.h>
#define M 10

struct student{
    int num;
    char name[20];
    int score[3];
};

int main()
{
    struct student stu[M];
    void myprint(struct student stu[M]);
    void input(struct student stu[M]);
    void max_aver(struct student stu[M]);

    input(stu);
    myprint(stu);
    max_aver(stu);

    return 0;
}
void myprint(struct student stu[M])
{
    int i;
    printf("num name score1 score2 score3\n");
    for(i=0;i<M;i++)
        printf("%3d %3s %3d %3d %3d\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
}

void input(struct student stu[M])
{
    int i;
    printf("請按以下格式依次輸入%d名學生的信息:\n",M);
    printf("num name score1 score2 score3\n");
    for(i=0;i<M;i++)
        scanf("%d %s %d %d %d",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
}
void max_aver(struct student stu[M])
{
    int i,j,id,max;
    float sum;
    for(i=0;i<3;i++)
    {
        sum=0;
        max=0;
        for(j=0;j<M;j++)
        {
            sum+=stu[j].score[i];
            if(max<stu[j].score[i])
            {
                max=stu[j].score[i];
                id=j;
            }
        }
        printf("第%d門課的平均分是%.2f\n",i+1,sum/M);
        printf("第%d門課的最高分是%d\n",i+1,max);
        printf("這名學生的信息如下:\n");
        printf("num name score1 score2 score3\n");
        printf("%3d %3s %3d %3d %3d\n",stu[id].num,stu[id].name,stu[id].score[0],stu[id].score[1],stu[id].score[2]);
        printf("\n");
    }
}

 

6.13個人圍成一圈,從第1個人開始順序報號1,2,3。凡報到3者退出圈子。找出最後留在圈子中的人原來的序號。要求用鏈表實現。

解題思路:

創建一個環形鏈表,給鏈表中的每一個節點從1~13編號,然後開始淘汰過程,對於淘汰的節點,序號置為0,淘汰完成之後,找到序號不為0的即為最後留下的。

#include <stdio.h>
#define M 13

struct people{
    int num;
    struct people *next;
};

int main()
{
    int i,count;
    struct people peo[M],*head;
    head=peo;

    for(i=0;i<M;i++)
    {
        head->num =i+1;
        head->next=&peo[i+1];
        head=head->next;        
    }
    peo[M-1].next=peo;                        //最後一個元素指向第一個元素

    i=0;
    count=M;
    head=peo;
    while(count>1)
    {
        i++;
        if(head->num==0)
        {
            head=head->next;
            continue;
        }
        if(i==3)
        {
            printf("%d號被淘汰\n",head->num);
            head->num=0;
            count--;
            i=0;
        }
        head=head->next;
    }

    printf("\n");
    while(head->num==0)
    {
        head=head->next;
        if(head->num!=0)
            printf("最後留下的是%d號\n",head->num);
    }

    return 0;
}

 

7.在第9章例9.9和例9.10的基礎上,寫一個函數del,用來刪除動態鏈表中指定的節點

解題思路:

首先創建一個帶頭的單鏈表,然後讓用戶輸入需要刪除的節點,調用del函數,找到需要刪除的節點,把待刪除節點的前驅和後繼重新鏈接。

#include <stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct LNode)

struct LNode{
    long num;
    struct LNode *next;
};

int n;

int main()
{
    long m;
    struct LNode *pt;
    struct LNode * creat();
    void print(struct LNode * head);
    void del(struct LNode * head,long m);

    printf("建立鏈表(輸入0停止建立)\n");

    pt=creat();

    print(pt);


    printf("要刪除的節點是: \n");
    scanf("%ld",&m);

    del(pt,m);

    print(pt);

    return 0;
}

struct LNode * creat()
{
    struct LNode *head,*p1,*p2;
    head=(struct LNode *)malloc(LEN);
    n=0;
    p1=p2=(struct LNode *)malloc(LEN);

    printf("請輸入第1個數據:");
    scanf("%ld",&p1->num);
    printf("\n");

    head=NULL;

    while(p1->num!=0)
    {
        n=n+1;
        if(n==1)
            head=p1;
        else
            p2->next=p1;
        p2=p1;
        p1=(struct LNode *)malloc(LEN);
        printf("請輸入第%d個數據:",n+1);
        scanf("%ld",&p1->num);
        printf("\n");
    }
    p2->next=NULL;
    return(head);
}

void print(struct LNode * head)
{
    struct LNode *p;
    printf("鏈表的數據如下:\n");
    p=head;
    if(head!=NULL)
    do
    {
        printf("%ld ",p->num);
        p=p->next;
    }while(p!=NULL);
    printf("\n");
}

void del(struct LNode * head,long m)
{
    struct LNode *p1,*p2;
    if(head==NULL)
        printf("list null!\n");
    p1=head;

    while(p1->num!=m && p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(p1->num==m)
    {
        if(p1==head)
            head=p1->next;
        else
            p2->next=p1->next;
        n=n-1;
    }
    else
        printf("%ld 未找到\n",m);
}

 

8.寫一個函數insert,用來向一個動態鏈表插入結點

#include <stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct LNode)

struct LNode{
    long num;
    struct LNode *next;
};

int n;

int main()
{
    int insert_id,insert0;
    struct LNode * creat(),*pt;
    void print(struct LNode * head);
    void insert(struct LNode * head,int insert_id,int insert0);

    printf("建立鏈表(輸入0停止建立)\n");

    pt=creat();
    print(pt);

    printf("請輸入要插入的位置以及數據:");
    scanf("%d %d",&insert_id,&insert0);
    
    insert(pt,insert_id,insert0);

    print(pt);

    return 0;
}

struct LNode * creat()
{
    struct LNode *head,*p1,*p2;
    head=(struct LNode *)malloc(LEN);
    n=0;
    p1=p2=(struct LNode *)malloc(LEN);

    printf("請輸入第1個數據:");
    scanf("%ld",&p1->num);
    printf("\n");

    head=NULL;

    while(p1->num!=0)
    {
        n=n+1;
        if(n==1)
            head=p1;
        else
            p2->next=p1;
        p2=p1;
        p1=(struct LNode *)malloc(LEN);
        printf("請輸入第%d個數據:",n+1);
        scanf("%ld",&p1->num);
        printf("\n");
    }
    p2->next=NULL;
    return(head);
}

void print(struct LNode * head)
{
    struct LNode *p;
    printf("鏈表的數據如下:\n");
    p=head;
    if(head!=NULL)
    do
    {
        printf("%ld ",p->num);
        p=p->next;
    }while(p!=NULL);
    printf("\n");
}

void insert(struct LNode * head,int insert_id,int insert0)
{
    struct LNode *p1,*p2;
    p1=head;

    insert_id-=1;
    while(--insert_id)
    {
        p1=p1->next;
    }
    
    p2=(struct LNode *)malloc(LEN);
    p2->num=insert0;
    p2->next=p1->next;
    p1->next=p2;
}

 

9.綜合本章例9.9(建立鏈表的函數creat)、例9.10(輸出鏈表的函數print)和本章習題第7題(刪除鏈表中結點的函數del)、第8題(插入結點的函數insert),再編寫一個主函數,先後調用這些函數。用以上5個函數組成一個程式,實現鏈表的建立、輸出、刪除和插入,在主函數中指定需要刪除和插人的結點的數據。

#include <stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct LNode)

struct LNode{
    long num;
    struct LNode *next;
};

int n;

int main()
{
    char c;
    int insert_id,insert0,m,flag=1;
    struct LNode * creat(),*pt;
    void print(struct LNode * head);
    void insert(struct LNode * head,int insert_id,int insert0);
    void del(struct LNode * head,long m);

    pt=creat();
    print(pt);
    
    while(flag==1)
    {
        printf("插入數據(1) 刪除數據(2) 結束(3):");
        getchar();
        scanf("%c",&c);
        
        if(c=='1')
        {
            printf("請輸入要插入的位置以及數據:");
            scanf("%d %d",&insert_id,&insert0);
            insert(pt,insert_id,insert0);
            print(pt);
        }
        if(c=='2')
        {
            printf("請輸入要刪除的數據:");
            scanf("%ld",&m);
            del(pt,m);
            print(pt);
        }
        if(c=='3')
            flag=0;
    }
    print(pt);

    return 0;
}

struct LNode * creat()
{
    struct LNode *head,*p1,*p2;
    head=(struct LNode *)malloc(LEN);
    n=0;
    p1=p2=(struct LNode *)malloc(LEN);

    printf("請輸入第1個數據:");
    scanf("%ld",&p1->num);
    printf("\n");

    head=NULL;

    while(p1->num!=0)
    {
        n=n+1;
        if(n==1)
            head=p1;
        else
            p2->next=p1;
        p2=p1;
        p1=(struct LNode *)malloc(LEN);
        printf("請輸入第%d個數據:",n+1);
        scanf("%ld",&p1->num);
        printf("\n");
    }
    p2->next=NULL;
    return(head);
}

void print(struct LNode * head)
{
    struct LNode *p;
    printf("鏈表的數據如下:\n");
    p=head;
    if(head!=NULL)
    do
    {
        printf("%ld ",p->num);
        p=p->next;
    }while(p!=NULL);
    printf("\n");
}

void insert(struct LNode * head,int insert_id,int insert0)
{
    struct LNode *p1,*p2;
    p1=head;

    insert_id-=1;
    while(--insert_id)
    {
        p1=p1->next;
    }
    
    p2=(struct LNode *)malloc(LEN);
    p2->num=insert0;
    p2->next=p1->next;
    p1->next=p2;
}
            
void del(struct LNode * head,long m)
{
    struct LNode *p1,*p2;
    if(head==NULL)
        printf("list null!\n");
    p1=head;

    while(p1->num!=m && p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(p1->num==m)
    {
        if(p1==head)
            head=p1->next;
        else
            p2->next=p1->next;
        n=n-1;
    }
    else
        printf("%ld 未找到\n",m);
}

 

10.已有a,b兩個鏈表,每個鏈表中的結點包括學號、成績。要求把兩個鏈表合併, 按學號升序排列。

#include <stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct student)

struct student{
    int num;
    double grade;
    struct student *next;
};

int main()
{
    int i;
    struct student a[4]={{1,99},{2,98.5},{5,99.1},{6,99.2}};
    struct student b[5]={{3,99.3},{4,99.4},{9,99.6},{7,99.7},{8,99.8}};
    struct student *Merge( struct student *L1,struct student *L2 );
    struct student *head1,*head2,*p1,*p2,*p;

    head1=a;
    head2=b;

    printf("a鏈表的數據如下:\n");
    p1=head1;
    for(i=1;i<=4;i++)
    {
        if(i<4)
            p1->next=a+i;
        else
            p1->next=NULL;
        printf("%d %.2lf\n",p1->num,p1->grade);
        if(i<4)
            p1=p1->next;
    }

    printf("b鏈表的數據如下:\n");
    p2=head2;
    for(i=1;i<=5;i++)
    {
        if(i<5)
            p2->next=b+i;
        else
            p2->next=NULL;
        printf("%d %.2lf\n",p2->num,p2->grade);
        if(i<5)
            p2=p2->next;
    }

    p=Merge(head1,head2);
    printf("排序後的鏈表如下:\n");
    while(p!=NULL)
    {
        printf("%4d %7f  \n",p->num,p->grade);
        p=p->next;
    }
    return 0;
}

struct student *Merge(struct student *a,struct student *b)
{
    int num;
    double grade;
    struct student *head,*pre;
    head=a;
    while(a->next!=NULL)
        a=a->next;
    a->next=b;
    pre=head;
    while(pre->next!=NULL)
    {
        a=pre->next;
        while(a!=NULL)
        {
            if(pre->num > a->num)
            {
                num=pre->num;
                grade=pre->grade;
                pre->num=a->num;
                pre->grade=a->grade;
                a->num=num;
                a->grade=grade;
            }
            a=a->next;
        }
        pre=pre->next;
    }
    return head;
}

 

11.有兩個鏈表a和b,設結點中包含學號、姓名。從a鏈表中刪去與b鏈表中有相同學號的那些結點。

解題思路:

對於b鏈表中的每一個節點,都從a鏈表的表頭開始查找,如果可以找到,直接刪除,如果找不到,繼續從a鏈表表頭找下一個b的節點。

 

#include <stdio.h>
#include <string.h>
#define LA 4
#define LB 5
struct  student{
    int num;
    char name[8];
    struct student *next;
} a[LA],b[LB];

int main()
{
    struct student a[LA]={{101,"Wang"},{102,"Li"},{105,"Zhang"},{106,"Wei"}};
    struct student b[LB]={{103,"Zhang"},{104,"Ma"},{105,"Chen"},{107,"Guo"},{108,"lui"}};
    int i;
    struct student *p,*p1,*p2,*head1,*head2;

    head1=a;
    head2=b;
    printf(" list A:  \n");
    p1=head1;
    for(i=1;i<=LA;i++)
    {
        if(i<LA) 
            p1->next=a+i;
        else 
            p1->next=NULL;
        printf("%4d%8s\n",p1->num,p1->name);
        if(i<LA) 
            p1=p1->next;
    } 
    printf("\n list B:\n");
    p2=head2;
    for(i=1;i<=LB;i++)
    {
        if(i<LB) 
            p2->next=b+i;
        else 
            p2->next=NULL;
        printf("%4d%8s\n",p2->num,p2->name);
        if(i<LB) 
            p2=p2->next;
    }

    p1=head1;
    while(p1!=NULL)
    {
        p2=head2;
        while((p1->num != p2->num) && (p2->next!=NULL))        //p1與p2的值依次比較
            p2=p2->next;
        if(p1->num == p2->num)                                //p1=p2時
        {
            if(p1==head1)
                head1=p1->next;
            else
            {
                p->next=p1->next;
                p1=p1->next;
            }
       }
        else        //比較到結束,p1與p2沒有相同的
        {
            p=p1;
            p1=p1->next;
        }
    }

    printf("\nresult:\n");
    p1=head1;
    while(p1!=NULL)
    {
        printf("%4d %7s  \n",p1->num,p1->name);
        p1=p1->next;
    }
    return 0;
}

 

12.建立一個鏈表,每個結點包括:學號、姓名、性別、年齡。輸入一個年齡,如果鏈表中的結點所包含的年齡等於此年齡,則將此結點刪去。

#include <stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct student)

struct student{
    int num;
    char name[20];
    char sex[6];
    int age;

    struct student *next;
};

int n;

int main()
{
    int years;
    struct student * creat(),*pt;
    void print(struct student * head);
    void del(struct student * head,int delage);

    pt=creat();
    print(pt);

    printf("請輸入要刪除的年齡:");
    scanf("%d",&years);

    del(pt,years);
    print(pt);

    return 0;
}

struct student * creat()
{
    struct student *head,*p1,*p2;
    head=(struct student *)malloc(LEN);
    n=0;
    p1=p2=(struct student *)malloc(LEN);

    printf("請按以下格式輸入每名學生的信息(輸入0 停止錄入):\n");
    printf("num name sex age");
    printf("請輸入第1個學生信息:");
    scanf("%d%s%s%d",&p1->num,p1->name,p1->sex,&p1->age);
    printf("\n");

    head=NULL;

    while(p1->num!=0)
    {
        n=n+1;
        if(n==1)
            head=p1;
        else
            p2->next=p1;
        p2=p1;
        p1=(struct student *)malloc(LEN);
        printf("請輸入第%d個同學信息:",n+1);
        scanf("%d%s%s%d",&p1->num,p1->name,p1->sex,&p1->age);
        printf("\n");
    }
    p2->next=NULL;
    return(head);
}

void print(struct student * head)
{
    struct student *p;
    printf("鏈表的數據如下:\n");
    p=head;
    if(head!=NULL)
    do
    {
        printf("%3d %3s %3s %3d\n",p->num,p->name,p->sex,p->age);
        p=p->next;
    }while(p!=NULL);
    printf("\n");
}

void del(struct student * head,int delage)
{
    struct student *p1,*p2;
    if(head==NULL)
        printf("list null!\n");
    p1=head;

    while(p1->age!=delage && p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(p1->age==delage)
    {
        if(p1==head)
            head=p1->next;
        else
            p2->next=p1->next;
    }
    else
        printf("%d 未找到\n",delage);
}

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 知識回顧 解析完Bean信息的合併,可以知道Spring在實例化Bean之後,屬性填充前,對Bean進行了Bean的合併操作,這裡的操作主要做了對Bean對象標記了@Autowired、@Value、@Resource、@PostConstruct、@PreDestroy註解的欄位或者方法進行解析, ...
  • Cookied的設置會造成XSS攻擊,所以出現了防禦機制HttpOnly標誌(可選),客戶端腳本將無法訪問cookie(如果瀏覽器支持該標誌的話)。因此即使客戶端存在跨站點腳本(XSS)漏洞,瀏覽器也不會將Cookie透露給第三方。Cookie和Session後面還會設計到xss和csrf漏洞的利用... ...
  • 為了修複生產數據,需要執行一段一次性的代碼。 鑒於是spring老項目,就想到了InitializingBean。 代碼如下。服務啟動後,log里發現出現2條“一次性任務開始”。 好在裡面邏輯做了防重控制,沒有受到什麼影響。 @Slf4j @Component public class TransT ...
  • 什麼是隱藏類 隱藏類,是一種不能被其他類直接使用的類。引入隱藏類的主要目的是給框架來使用,使得框架可以在運行時生成類,並通過反射間接使用它們。可能有點抽象,不要緊,下麵我們通過一個例子來直觀的認識它! 隱藏類案例 第一步:先創建一個普通的Java類 public class JEP371Hidden ...
  • 下麵介紹的是JUC包下一些線程安全類的一些簡單使用和一些小demo。 Semaphore 信號量,即可以同時使用的線程數,tryrequire就是將信號量減一,release就是信號量+1,當等於0就會阻塞,大於零才會喚醒。 當需要控制線程訪問數量,可以使用信號量來做控制,比較簡單。 下麵是使用信號 ...
  • Spring Ioc源碼分析系列--Ioc容器註冊BeanPostProcessor後置處理器以及事件消息處理 前言 上一篇分析了BeanFactoryPostProcessor的作用,那麼這一篇繼續在refresh()方法里游蕩,相信對Spring熟悉點的朋友,在看完BeanFactoryPost ...
  • 大家好,這篇文章分享了C程式設計(譚浩強)第五版第十章課後題答案,所有程式已經測試能夠正常運行,如果小伙伴發現有錯誤的的地方,歡迎留言告訴我,我會及時改正!感謝大家的觀看!!! ...
  • 高精度 運算:加法、減法、階乘、乘法 翻轉: 這些運算都是從小位開始,所以一般需要翻轉。以字元串儲存:reverse(a.begin(),a,end())。以數組儲存: for (int i1 = lena1 - 1; i1 >= 0; i1--) { a1[lena1-1-i1] = a[i1] ...
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...