How to inactivate an element in C?

Asked

Viewed 64 times

-3

As from the following structs, would like to know how to inactivate a property.

A real estate company has a set of 100 properties for rent. On each property the application must allow storing: the type of property, location, address, minimum price, advised price, year of construction, allows animals, Obs ... The application must allow : "Inactivate a property...

typedef struct imoveis{
    int tipo, cod;
    int ano;
    char cidade[100], morada[100], animais[20], obs[100]; 
    float preco_min, preco_acons;
}INFO;

typedef struct imovel{
    INFO info;
    struct imovel *seguinte;
    struct imovel *anterior; 
}IMOVEL;
  • 3

    Set "inactivate a property", please.

  • The issue at issue is: Inactivating a property: The possibility of renting the property can be inactivated by a period of time, for example for works;

  • 2

    Where did you get this piece of text? Is it an enunciation or something? If it is, it would be interesting to post it in full in the question.

  • 1

    You can add a Flag with the name Active and put the value 1 to symbolize active and 0 to inactive.

  • "A real estate company has a set of 100 properties for rent. On each property the application must allow storing: the type of property, location, address, minimum price, advised price, year of construction, allows animals, Obs ... The application must allow : "Inactivate a property..."

  • @Anap The answer solved your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

Show 1 more comment

1 answer

2

Some considerations about this code:

Strange a structure that stores data of A property call imoveis. And a list of real estate call imovel. It gets worse when the guy in that structure calls INFO.

float is not suitable for monetary values. But it’s okay for an exercise, as long as you understand that you shouldn’t use it in production, because in production it’s unlikely to use array char strings. Probably even use in ano, if it is only descriptive, as seems to be the case. It would only make sense to be int whether to do accounts with it. I can’t tell if other types are suitable for not knowing the requirements.

As for activity status you can use a simple char to store this information. There you could store S or N, or 0 or 1 as a character or ASCII code. You could use an int also, but it does not seem to be the best option. Depending on the compiler could wear a bool, or you can fake it: Simulate boolean type in C.

typedef struct {
    int tipo, cod;
    int ano;
    char cidade[100], morada[100], animais[20], obs[100]; 
    float preco_min, preco_acons;
    char ativo;
} Imovel;

typedef struct {
    Imovel info;
    struct imovel *seguinte;
    struct imovel *anterior; 
} Imoveis;

I put in the Github for future reference.

When initializing you need to adopt a semantic pattern for this field. Something like this:

imovel.ativo = 1;

or

imovel.ativo = '1';

or

imovel.ativo = 'S';

This is more or less valid for any field that has a limited and previously known set of options. If it is 2, 3, theoretically up to 256 (you can use a enum if the compiler allows, in some cases are 2 but is not something boolean, it is not a matter of being only a yes or no in the case of a status, even if it starts with 2 it may be that there is something intermediate ahead, then it can be useful. If you need to pass 256 options you can still use one short or int, although when it has a lot of option it is not always interesting to have an enumeration simulation like this.

  • About defining a enum for the values of ativo, what is your opinion?

  • @Andersoncarloswoss as I edit? Related: https://answall.com/q/21997/101, https://answall.com/q/50363/101, https://answall.com/q/81801/101 and https://answall.com/q/180014/101

Browser other questions tagged

You are not signed in. Login or sign up in order to post.