2022-2023-1 20221320 《计算机基础与程序设计》第十一周学习总结

学期(2022-2023-1) 学号(20221320) 《计算机基础与程序设计》第十一周学习总结

作业信息

各项要求 具体内容
<班级的链接> 2022-2023-1-计算机基础与程序设计
<作业要求的链接> 2022-2023-1计算机基础与程序设计第十一周作业
作业的目标 1.学习目标: 计算机网络,网络拓扑,云计算,网络安全,Web,HTML,CSS,Javascript,XML
作业的目标 2.学习任务:加入云班课,参考本周学习资源、计算机科学概论第15,16章 并完成云班课测试、《C语言程序设计》第10章并完成云班课测试
作业的目标 3.参考上面的学习总结模板,把学习过程通过博客(随笔)发表,博客标题“学年 学号 《计算机基础与程序设计》第十一周学习总结”,博客(随笔)要通过作业提交,截至时间本周日 23:59。
作业正文

教材学习内容总结

《计算机科学概论》第15,16章:1.计算机网络、各种类型的网络和特征、局域网的各种拓扑、开放式系统实现网络技术、包交换、网络协议的基本职责、防火墙、主机名和IP地址、域名系统、云计算。
2.比较Internet和万维网。Web处理。
3.编写基本的HTML 文档、定义观看XML文档、HTML标记和用途。
4.Java小程序、Java服务器页。
5.比较HTML和XML。
《C语言程序设计》第10章:11.7的课上汪老师讲述了如何向函数传递指针,具体总结如下||参考博文指针作为函数参数传递
1.整形作为函数参数
先来看一下没有用到指针传递的函数:

void change(int p1, int p2) {
    int p;
    p = p1;
    p1 = p2;
    p2 = p;
}
void main() {
    int a, b;
    a = 1;
    b = 2;
    printf("before change a=%d,b=%d\n",a,b);
    change(a, b);
    printf("after change a=%d,b=%d",a,b);
}

看到该函数,以为有运行结果为

before change a=1,b=2
after change a=2,b=1

实际上该函数运行的结果为:

before change a=1,b=2
after change a=1,b=2 

为什么会这样呢?
这里就要引入两个概念:形参和实参,代码void change(int p1,int p2)里面的p1,p2是形参,而main函数里面给change传递的a,b则为实参。
该程序运行时,首先会在内存中创建两个实参a与b,接着把实参传递到chang(int p1,int p2)函数中,该传递是复制,即系统会开辟另一个地址给p1与p2, 然后让p1的值与p2的值和a,b相等。这样就相当于有四个变量,在chang()中,改变的只是p1与p2而对main()中的a和b没有影响,所以a与b的位置并没有交换。画图表示为:

接下来对程序进行稍微修改有:

void change1(int &p1, int &p2 ) {
    int p;
    p = p1;
    p1 = p2;
    p2 = p;
}
void main() {
    int a, b;
    a = 1;
    b = 2;
    printf("before change a=%d,b=%d\n",a,b);
    change1(a, b);
    printf("after change a=%d,b=%d",a,b);
}

可以看到对程序仅有的改动是change1(int &p1,int &p2),change1的参数发生了变化,加入了"&",该参数的意思是“引用”p1与p2引用a与b,而不是给p1与p2新开辟一个空间此时此时,运行的结果为:

before change a=1,b=2
after change a=2,b=1

图画为:

void change2(int* p1, int* p2) {
    int p;
    p = *p1;
    *p1 = *p2;
    *p2 = p;
}
 
void change3(int *p1,int *p2) {
    int* p;
    p = p1;
    p1 = p2;
    p2 = p;
}
 
void main() {
    int a, b,c,d;
    a = 1;
    b = 2;
    c=1;
    d=2;
    printf("before change a=%d,b=%d\n",a,b);
    change2(&a, &b);
    printf("after change a=%d,b=%d\n\n",a,b);
    printf("before changec=%d,d=%d\n",a,b);
    change3(&c, &d);
    printf("after change c=%d,d=%d",c,d);
}

接着看这些代码
运行的结果为:

before changea=1,b=2
after changea=2,b=1

before changec=1,d=2
after changec=1,d=2

可以看到change3并没有发挥作用,而chang2却发挥了作用 。
对于change2,这个函数,可以看到形参为“*”指针,要求调用者传递整形指针:

  1  int p;
  2  p = *p1;
  3  *p1 = *p2;
  4  *p2 = p;

用图片表示为

对于change3,这个函数,与chang2颇为相似:,内存仍用图片表示

接着学习了函数指针

了解了函数指针定义时的常见错误
uploading-image-585697.png

再讲了一个函数指针的应用



11.9汪老师在课上讲了指针与一维数组、指针和二维数组、指针数组及其应用、动态内存分配、字符串常量和字符指针的问题。
现总结以下内容
数组元素的等价引用形式

a[i]
*(a+i)
pa[i]
*(pa+i)

如何用指针在函数中访问数组

指针在二维数组中的应用

动态内存的分配
申请内存

释放内存

字符串的储存

教材学习中的问题和解决过程

暂无

  • 代码调试中的问题和解决过程

  • 问题1:怎么做到在进行成绩处理的时候换下一个菜单不需要进行重新输入成绩
  • 问题1解决方案:
#include <stdio.h>
#include <stdlib.h>
void AppendRecord(int m,int score[],long studentID[]);
void CalculateTotalAndAverageScoreOfCourse(int m,int score[]);
void SortInDescendingOrderByScore(int m,int score[],long studentID[]);
void SortInAscendingOrderByNumber(int m,int score[],long studentID[]);
void SearchByNumber(int m,int score[],long studentID[]);
void StatisticAnalysis(int m,int score[],long studentID[]);
void ListRecord(int m,int score[],long studentID[]);
int main()
{
    int x,n,Score[40]={0},counter=0;
    long StudentID[40]={0};
    B:printf("(1)Append record\n");
    printf("(2)Calculate total and average score of course\n");
    printf("(3)Sort in descending order by score\n");
    printf("(4)Sort in ascending order by number\n");
    printf("(5)Search by number\n");
    printf("(6)Statistic analysis\n");
    printf("(7)List record\n");
    printf("(8)Exit\n");
    printf("Choose the function you want to run by input the number before it:\n");
    scanf("%d",&x);
    counter++;
    if(counter>1)
        goto C;
    printf("How many students will be analyze?\n");
    scanf("%d",&n);
    AppendRecord(n,Score,StudentID);
    C:switch(x)
    {
    case 1:
        if(counter>1)
            printf("You have done it!\n");
        break;
    case 2:
        CalculateTotalAndAverageScoreOfCourse(n,Score);
        break;
    case 3:
        SortInDescendingOrderByScore(n,Score,StudentID);
        break;
    case 4:
        SortInAscendingOrderByNumber(n,Score,StudentID);
        break;
    case 5:
        SearchByNumber(n,Score,StudentID);
        break;
    case 6:
        StatisticAnalysis(n,Score,StudentID);
        break;
    case 7:
        ListRecord(n,Score,StudentID);
        break;
    case 8:
        exit(0);
        break;
    }
    goto B;
    return 0;
}

void AppendRecord(int m,int score[],long studentID[])
{
    printf("Please input each students'ID:\n");
    int i;
    for(i=0;i<m;i++)
    {
        scanf("%ld",&studentID[i]);
    }
    printf("Please input the students'score:\n");
    for(i=0;i<m;i++)
    {
        scanf("%d",&score[i]);
    }
}

void CalculateTotalAndAverageScoreOfCourse(int m,int score[])
{
    int i,total=0;
    for(i=0;i<=m;i++)
    {
        total+=score[i];
    }
    printf("Total score is %d\n",total);
    printf("Average score is %d\n",total/m);
}
void SortInDescendingOrderByScore(int m,int score[],long studentID[])
{
    int i,j,temp,k;
    for(i=0;i<=m-1;i++)
    {
        k=i;
        for(j=i+1;j<=m;j++)
        {
            if(score[j]>score[k])
            {
                temp=score[j];
                score[j]=score[i];
                score[i]=temp;
                temp=studentID[j];
                studentID[j]=studentID[i];
                studentID[i]=temp;
            }
        }
    }
    int p;
    for(p=0;p<m;p++)
    {
        printf("%6ld",studentID[p]);
    }
    printf("\n");
}
void SortInAscendingOrderByNumber(int m,int score[],long studentID[])
{
    int i,j,temp,k;
    for(i=0;i<=m-1;i++)
    {
        k=i;
        for(j=i+1;j<=m;j++)
        {
            if(studentID[j]<studentID[k])
            {
                temp=studentID[j];
                studentID[j]=studentID[i];
                studentID[i]=temp;
                temp=score[j];
                score[j]=score[i];
                score[i]=temp;
            }
        }
    }
    int p;
    for(p=1;p<m+1;p++)
    {
        printf("%4d",score[p]);
    }
    printf("\n");
}
void SearchByNumber(int m,int score[],long studentID[])
{
    long student;
    printf("Input the student you want to find\n");
    scanf("%ld",&student);
    int i,j,temp,k;
    for(i=0;i<=m-1;i++)
    {
        k=i;
        for(j=i+1;j<=m;j++)
        {
            if(score[j]>score[k])
            {
                temp=score[j];
                score[j]=score[i];
                score[i]=temp;
                temp=studentID[j];
                studentID[j]=studentID[i];
                studentID[i]=temp;
            }
        }
    }
    for(i=0;i<m;i++)
    {
        if(studentID[i]==student)
            printf("%4d",score[i]);
    }
    printf("\n");
}
void StatisticAnalysis(int m,int score[],long studentID[])
{
    int i,counterA=0,counterB=0,counterC=0,counterD=0,counterE=0;
    float rateA=0,rateB=0,rateC=0,rateD=0,rateE=0;
    for(i=0;i<=m-1;i++)
    {
        if((score[i]>=90)&&(score[i]<=100))
           counterA++;
        else if((score[i]>=80)&&(score[i]<90))
           counterB++;
        else if((score[i]>=70)&&(score[i]<80))
           counterC++;
        else if((score[i]>=60)&&(score[i]<70))
           counterD++;
        else if((score[i]>=0)&&(score[i]<60))
           counterE++;
    }
    rateA=(float)(counterA*100)/(counterA+counterB+counterC+counterD+counterE);
    rateB=(float)(counterB*100)/(counterA+counterB+counterC+counterD+counterE);
    rateC=(float)(counterC*100)/(counterA+counterB+counterC+counterD+counterE);
    rateD=(float)(counterD*100)/(counterA+counterB+counterC+counterD+counterE);
    rateE=(float)(counterE*100)/(counterA+counterB+counterC+counterD+counterE);
    printf("The excellent number of students is %d, and the rate is %f%%\n",counterA,rateA);
    printf("The good number of students is %d, and the rate is %f%%\n",counterB,rateB);
    printf("The middle number of students is %d, and the rate is %f%%\n",counterC,rateC);
    printf("The passing number of students is %d, and the rate is %f%%\n",counterD,rateD);
    printf("The failed number of students is %d, and the rate is %f%%\n",counterE,rateE);
}
void ListRecord(int m,int score[],long studentID[])
{
    int i;
    printf("student's ID");
    for(i=0;i<m;i++)
        printf("%6ld\t",studentID[i]);
    printf("\n");
    printf("scores   are");
    for(i=0;i<m;i++)
        printf("%6d\t",score[i]);
    printf("\n");
    int total=0;
    for(i=0;i<=m;i++)
    {
        total+=score[i];
    }
    printf("Total score is %d\n",total);
    printf("Average score is %d\n",total/m);

主要是在case1的版块做了调整

  • 问题2:
    冒泡排序(Bubble Sort),也称为沉降排序(Sinking Sort),之所以称其为冒泡排序,是因为算法中值相对较小的数据会像水中的气泡一样逐渐上升到数组的最顶端。与此同时,较大的数据逐渐地下沉到数组的底部。这个处理过程需在整个数组范围内反复执行多遍。每一遍执行时,比较相邻的两个元素。若顺序不对,则将其位置交换,当没有数据需要交换时,数据也就排好序了。编程将排序函数DataSort()改用冒泡法实现。
    **输入格式要求:"%d" 提示信息:"Input n:" "Input %d numbers:"
    **输出格式要求:"Sorting results:" "%4d"
    程序运行示例如下:
    Input n:10
    Input 10 numbers: 2 9 3 4 0 6 8 7 5 1
    Sorting results: 0 1 2 3 4 5 6 7 8 9
    但是之前的程序没有输出
  • 问题2解决方案:
#include<stdio.h>
void main()
{
	int n[10] ;
	int i, j, temp,m;
	printf("Input n:");
	scanf("%d",&m);
	printf("Input %d numbers:",m);
	for(i=0;i<10;i++)
        scanf("%d",&n[i]);
	for (i = 1; i <= 9; i++)
	{
		for (j = 0; j <= 9 - i; j++)
		{
			if (n[j] > n[j + 1])
			{
				temp = n[j];
				n[j] = n[j + 1];
				n[j + 1] = temp;
			}
		}
	}
	printf("Sorting results:");
	for (i = 0; i < 10; i++)
	printf("%4d", n[i]);
	printf("\n");
}

  • 问题2:
    求矩阵A(23)的转置B(32)。如

123=A
456

14=B
24
36
**输出格式要求:"%d "
程序运行示例如下:
1 4
2 5
3 6
可是之前的程序的输出结果不对

#include<stdio.h>
int main()
{
    int aaa[2][3] = {{1, 2, 3}, {4, 5, 6}}, bbb[3][2];
    int i, j;
    for (i = 0; i <= 1; i++)
    {
        for (j = 0; j <= 2; j++)
        {
            bbb[j][i] = aaa[i][j];
        }
    }
    for (i = 0; i <= 1; i++)
    {
        for (j = 0; j <= 2; j++)
        {
            printf("%d", bbb[i][j]);
        }
        printf("\n");
    }
    return 0;
}



  • 问题2解决方案:
#include<stdio.h>
void main()
{
int ch[2][3]={{1,2,3},{4,5,6}};
int i=0,j=0;
for(j=0;j<=2;j++)
{
for(i=0;i<=1;i++)
printf("%d",ch[i][j]);
printf("\n");
}
}

上周考试错题总结

其他(感悟、思考等)

学习进度条

博客量(新增/累计) 代码行数(新增/累计) 学习时间(新增/累计) 重要成长
目标 70 3000 300
第一周 2/2 0 10/10 开始学习写博客
第二周 1/3 300/300 20/30 学习如何自主预习,初识信息安全专业
第三周 6/9 250/550 20/50 各种进制表数方法
第四周 1/10 50/600 15/65 逻辑电路
第五周 3/13 100/700 10/75 博客排版和编辑走上正轨
第六周 1/14 100/800 10/85 解决问题的Polya新思想 ,选择结构
第七周 1/15 300/1100 20/105 抽象数据类型,循环结构
第八周 2/17 150/1250 20/125 函数的定义,不同范型的编程语言
第九周 1/18 300/1550 20/145 数组,函数,操作系统,文件系统和目录
第十周 1/18 300/1850 10/155 二维数组
第十一周 1/19 500/2350 10/165 指针
posted @ 2022-11-13 22:17  20221320冯泰瑞  阅读(57)  评论(0编辑  收藏  举报