One, PTA laboratory work (5 points) Topic 1: The structure of the array by total score 1. PTA Submission List (to submit list, not result)
2. Design ideas (pseudo-code or flowchart)
void calc(struct student *p,int n); 累加总分函数定义变量i作为循环变量 for i=0 to n-1p[i].sum=0; 将数组都赋予初值0for j=0 to 2 p[i].sum= p[i].sum+ p[i].score[j]; 将3个学科的分数加到总分上end forvoid sort(struct student *p,int n); 按总分从大到小排名定义一个结构变量struct student m;定义i,j作为循环变量for i=0 to n-1 用选择排序法,找最大值先排列for j = i+1 to n-1 遍历sum数组找出最大分p[i].sum<p[j].sum 如果找到就将两变量的所有内容互换end for
3. Code (note,,,. Do not paste on the blog. No need to use ... syntax to render)
4. Problems encountered in debugging process and PTA Submission List situation description.
- Error is caused by not enclosing content that belongs to a step in parentheses
Topic 2: Time conversion 1. PTA Submission List (to submit list, not result)
2. Design ideas (pseudo-code or flowchart)
struct time { int hour; int min; int sec;}; //该结构体表示时间的小时,分钟,秒定义结构数组存放数据 struct time t[200]; 定义较大以免超范围定义两个字符变量来输入两个:号char ch,op;输入数据后进行判断 小时,分钟及秒加上n秒后有没有大于等于60 有就用时间进位还有最后判断小时是否为24,是则归为0;最后输出
3. Code (note,,,. Do not paste on the blog. No need to use ... syntax to render)
4. Problems encountered in debugging process and PTA Submission List situation description.
- Because the input of the number is not added, and the number is entered directly, the answer is wrong.
Topic 3: Entry and display of contacts 1. PTA Submission List (to submit list, not result)
2. Design ideas (pseudo-code or flowchart)
struct address{ char name[100]; char birthday[100]; char sex[100]; char number[100]; char teleph[100];}; //定义结构储存姓名,生日,性别,号码 ,固话 定义结构数组 struct address p[1000];for i=0 to n-1进行通讯录的录入end for输入要查找的个数 kfor i=0 to k-1 输入要查找的编号x 判断x是否在范围内是则输出下标为x的结构数组所有内容否则输出 no found
3. Code (note,,,. Do not paste on the blog. No need to use ... syntax to render)
4. Problems encountered in debugging process and PTA Submission List situation description.
Finally determine if x is within range of x>=0 this range leads to partial correctness
Second, this week's topic set PTA Final ranking. (2 points)
Third, read the code (2 points)
The bubbling method is implemented with pointers, without return values, to exchange values directly in the array
You can use recursive methods to reverse the output of numbers
Iv. Study Summary of the Week 1. Summarize what you learned this week.
-
- Structure:
```
Definition of structure:
struct student//struct type description and definition are separated. Statement
{
int age; / Age /
Float score; / score /
char sex; / Gender /
};
- The storage layout of a struct type variable is arranged in the order of the members in its type definition, preceded by the definition.
- The element member reference of the structure array passes through '. ' Number, you can also access the struct member pointed to by the pointer, such as P->num = 333 (p is the address)
When accessing struct members with pointers (*p). num = 333 () is not limited.
```
- 2. Shared body
```
1. The same memory segment can be used to store several different types of members, but only one of them is stored at each moment, not several at a time. In other words, only one member works at a time, and the other members do not work, that is, not both in existence and in effect.
2. The member that functions in the common body variable is the last member to be deposited, and when a new member is deposited, the original member loses its role.
3. The address of the shared body variable and the address of its members are the same address.
4. You cannot assign a value to a shared body variable name or attempt to reference a variable name to get a value.
- 5. A common body type can appear in the definition of a struct type, or you can define a common body array. Conversely, structs can also appear in the definition of a common body type, and arrays can also be members of a common body.
It is defined in the following format:
Union Common body Name {
Member List
};
A common body is also sometimes called a union or a union, which is also the meaning of the word Union.
The difference between a struct and a common body is that each member of the struct occupies a different memory and has no effect on each other, while all members of the common body occupy the same memory, and modifying one member affects all remaining members.
The structure consumes more memory than equals the sum of the memory occupied by all members (there may be gaps between the members), and the memory occupied by the common body equals the memory occupied by the longest member. The shared body uses a memory overlay technique that only holds the value of one member at a time, and if the new member is assigned a value, the value of the original member is overwritten.
A common body is also a custom type that can be used to create variables, such as:
Union data{
int n;
Char ch;
Double F;
};
Union data A, B, C;
The above is to define a common body before creating a variable, or you can create a variable while defining a common body:
Union data{
int n;
Char ch;
Double F;
} A, B, C;
If you no longer define a new variable, you can omit the name of the common body:
union{
int n;
Char ch;
Double F;
} A, B, C;
- 3枚举.
Enumeration types are defined in the following form:
Enum typename{valueName1, valueName2, ValueName3, ...};
The enum is a new keyword that is specifically used to define the enumeration type, which is the only use in the C language; TypeName is the name of the enumeration type;
ValueName1, ValueName2, ValueName3, ... is a list of names that correspond to each value. Pay attention to the last; not less.
For example, a list of one weeks has several days:
Enum week{Mon, Tues, Wed, Thurs, Fri, Sat, Sun};
As you can see, we just give the name, but we don't give the value of the name, because the enumeration value starts from 0 and increments by 1 (increment), i.e. Mon, Tues ... in week. The values of Sun correspond to 0, 1 ... 6.
We can also specify a value for each name:
Enum week{Mon = 1, tues = 2, Wed = 3, thurs = 4, Fri = 5, Sat = 6, Sun = 7};
A simpler approach is to specify a value only for the first name:
Enum week{Mon = 1, Tues, Wed, Thurs, Fri, Sat, Sun};
This increments the enumeration value from 1, which is equivalent to the above notation.
An enumeration is a type that allows you to define an enumeration variable:
Enum week A, B, C;
You can also define variables at the same time that you define an enumeration type:
Enum week{Mon = 1, Tues, Wed, Thurs, Fri, Sat, Sun} A, b, C;
With an enumeration variable, you can assign a value in the list to it:
Enum week{Mon = 1, Tues, Wed, Thurs, Fri, Sat, Sun};
Enum Week A = Mon, B = Wed, c = Sat;
Or:
Enum week{Mon = 1, Tues, Wed, Thurs, Fri, Sat, Sun} a = Mon, B = Wed, c = Sat
```
2. List some of the wrong questions this week.
Think that when n is negative, and then recursion will occur error led to choose D, then the teacher explained in class to know
No understanding of the recursive, resulting in errors
First of all, except 10 in the recursive, the last output is the value of n%10 so that recursion can not reverse output, but also output 7534
C Language Blog Job--structure