C language homework (5)

1. Have the following structure and structure variable definitions:

struct student
{
    int id;
    char* name;
    int math;
};
struct student studl;

The correct assignment of structure type variables is (A)
A, studl.id=1001;studl.name=”Tom”;
B, id=1001;*studl.name=”Tom”;
C, studl.id=1001 ;studl.*name=”Tom”;
D. studl.id=1001L;*studl.name=”Tom”;

2. The pointer variable pointing to the structure object can either point to the structure variable or be used to point to (the structure itself).
2.1 There is only one structure type. Is this statement correct? (wrong)
A. correct
B. wrong

3. When specifying a structure variable, the memory allocated to it by the system is (A)
A. The sum of the memory required by each member
B. The amount of memory required by the first member of the structure
C. The one with the largest amount of memory among the members The required capacity
D. The amount of memory required for the last member in the structure

4. In a structure, the default access rights of members are (public).

5. When the default alignment is selected on a 32-bit CPU, there are the following structure definitions:
struct A{
unsigned a : 19;
unsigned b : 11;//1 word
unsigned c : 4;//1 word
unsigned d : 29;//A word
char index;//1 word
};//A word 32bite=4byte, 4*4 16byete
, the value of sizeof(struct A) is (16)
9
12
16
20

6. The functions of the following code include: define an x ​​array, describe a structure, and initialize the variable t at the same time, so that the value of the a member of t is 50, and the value of the b member is the first address of the x array.
Please fill in the appropriate content in the blank (in the box) and complete the above functions.

int x[5]={1,2,3,4,5};
struct {
int a;
int *b;
}t{ (50),(&x) };

7. When developing C code, the following types of structure definitions are often seen:

typedef struct list_t
{
struct list_t *next;//4
struct list_t *prev;//4
char data[0];//0
}list_t;

In a 32-bit system, the value of sizeof(list_t)? 8byte 4byte 8byte
5byte 9byte


8. Define a structure variable (including year, month, and day), and calculate the day in this year? (Note that leap years are considered), and it is required to write a function days to realize the above calculation. The year, month, and day are passed to the days function by the main function, and the days are passed back to the main function output after calculation.

#include<stdio.h>

struct date
{
    int year;
    int month;
    int day;
}d={2017,12,28};

int days(int year,int month,int day)
{
    int month[12]={31,28,31,30,31,30,31,31,30,31,30,31}
    if((year%4==0&&year%100!=0)||(year%400==0))
    {
        monnth[1]=29;
    }
    int i;
    int data = 0;
    for(i=0;i<month - 1;i++)
    {
        data = month[i]+data;
    }


}
int main(void)
{
    int day;
    day = days(d.year,d.month,d.day);
    day = day + data;
    printf("该日是本年的第%d天!.\n",day);
    return 0;
}

9. Suppose there is the following structure of employee information:
struct Employee
{
long eID;
char eName[10];
struct Employee *pNext;
};
where eID represents the employee number, please write a function:
struct Employee *eIDSequence(int eID , char *sName)

struct Employee
{
    int eID;
    char *sName;
    struct Employee *pNext; 
}
struct  Employee *eIDSequence(int eID, char *sName)
{

}

10. Please design a structure type named student. The members of this type have a character type variable named sex, an int type named id, and a variable named character array named name. Create an array of sruc student type in the function, the length of the array is 10, and then design a custom function to implement the input of the structure array, and then design a custom function to find the element with the largest id value in the structure array and Displays the values ​​of its members.

#include<stdio.h>
struct student
{
    char sex;
    int id;
    char name[10];
}s;
int mian(void)
{   

    return 0;
}

11. Program to calculate the straight-line distance between two points.
Requirement: The point coordinate adopts the structure type, the screen obtains the input of two points, and outputs the distance (two digits after the decimal point).

#include<stdio.h>
#include<math.h>
struct data
{
    int x;
    int y;
}d;

int main(void)
{
    typeof(d) A,B;
    printf("请输入A点的坐标x,y");
    scanf("%d,%d",&A.x,&A.y);
    printf("请输入B点的坐标x,y");
    scanf("%d,%d",&B.x,&B.y);
    int lenth;
    lenth = sqrt(((A.x - B.x)*(A.x - B.x))+((A.y - B.y)*(A.y - B.y)));
    printf("A,B两点间的距离为:%d.\n",lenth);
}

12. Title: Phonebook
Management
Title Description:
Input the names and phone numbers of five users by using a structure type array, arrange them in lexicographical order (the names are the same and keep the original position), and output the user's name and phone number. The known structure types are as follows: struct user { char name[20]; char num[10]; };
Input description:
input name string and phone number string.
Output description:
Output the name string and phone number string sorted by name.
Style input:
aa
12345
dd
23456
cc
34567
bb
21456
ee
12456
Style output:
aa
12345
bb
21456
cc
34567
dd
23456
ee
12456

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325919744&siteId=291194637
Recommended