מידע

יוצרים Alexandre Gobeaux
מועד הגשה אין מועד הגשה
מגבלת הגשות אין הגבלה
תגיות קטגוריה S3, Level 2, Malloc, Pointer, Struct

תגיות

כניסה

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


שאלה 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);
שאלה 2: Get Price

Write the body of the getPrice function.

/*
 * @return: the price of the product prod
 */
double getPrice(product_t prod);
שאלה 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);
שאלה 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);
שאלה 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);