Thông tin

Tác giả Alexandre Gobeaux
Hạn chót Không có hạn chót
Giới hạn nộp bài Không có giới hạn
Các tag chuyên mục s3, level2, category_malloc, category_pointer, category_struct

Tags

Đăng nhập

[S3] Structures and pointers to structures

Here you will be playing with structures and pointers to structures so that you can understand better how to use one instead of another. You'll have to return the attributes of both and you'll have to compare them.

typedef struct product {
    char *name;
    double price;
} product_t;

Hints :


Câu hỏi 1: Get Price (pointer to the structure)

Write the body of the getPtrPrice function.

/*
 * @ptrProd != NULL
 * @return: the price of the product ptrProd
 */
double getPtrPrice(product_t *ptrProd);
Câu hỏi 2: Get Price

Write the body of the getPrice function.

/*
 * @return: the price of the product prod
 */
double getPrice(product_t prod);
Câu hỏi 3: Get Name (pointer to the structure)

Write the body of the getPtrName function.

/*
 * ptrProd != NULL
 * @name in ptrProd != NULL
 * @return: a string on the heap that contains the name of the product ptrProd or NULL if an error happens
 */
char* getPtrName(product_t *ptrProd);
Câu hỏi 4: Get Name

Write the body of the getName function.

/*
 * @name in prod != NULL
 * @return: a string on the heap that contains the name of the product ptrProd or NULL if an error happens
 */
char* getName(product_t prod);
Câu hỏi 5: Product Equals

Write the body of the prodEquals function.

/*
 * @ptrProd != NULL
 * @name in ptrProd != NULL
 * @name in prod != NULL
 * @return: 1 if the two products are the same, i.e., they have the same price and the same name
 */
int prodEquals(product_t *ptrProd, product_t prod);