Informações

Autores Alexandre Gobeaux
Prazo de entrega Sem prazo
Limite de submissão No limitation
Category tags S3, Level 2, Malloc, Pointer, Struct

Etiquetas

Entrar

[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 :


Questão 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);
Questão 2: Get Price

Write the body of the getPrice function.

/*
 * @return: the price of the product prod
 */
double getPrice(product_t prod);
Questão 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);
Questão 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);
Questão 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);