how to make program for car rental

Any one here who can help to create program for car rental please guide me?
I read your question and figured out its about cars

1
2
3
struct Car {
    std::string name;
};


and its about people

1
2
3
struct People {
    std::string name;
};


these are noun. They do something: rent. So they are in a relationship (another noun)

1
2
3
4
struct RentRelationship {
    int carID = -1;
    int peopleID = -1;
};


Now we want many cars

std::map<int, Car> cars;

and many people

std::map<int, People> peoples;

and many people who rent many cars

std::vector<RentRelationship> rents;

add some example data

1
2
3
4
cars.emplace(1, Car{"Car1"});
cars.emplace(11, Car{"Car2"});
peoples.emplace(100, People{"Person 1"});
peoples.emplace(101, People{"Person 2"});


and some rents

1
2
rents.push_back(RentRelationship{1,101});
rents.push_back(RentRelationship{11,100});


and finally print some output

1
2
3
for(const RentRelationship& r : rents) {
        std::cout << "Person: " << peoples[r.peopleID].name << " rent car: " << cars[r.carID].name << "\n";
    }


Put it all together and you have a good example to start.
Last edited on
Hello elenama65,

First take a piece of paper and a pen or pencil and write down what the program needs to do. If you have ever rented a car thing about what you had to do to actually end up with a car to drive. Consider what information you will need to collect from the user.

This will give you an idea of the variables that you will or might need.

I do not know what you know, so I can only guess that yo may want a class or at least a struct to hold information about an individual person.

You could write some pseudo code to give you an idea of how the program will flow.

If this is for class work or homework that is fine, but please post the instructions that you were given. This will help in any guidance given.

When yu can write some code post it here and ideas and guidance will be better once people see what you can do.

Hope that helps,

Andy
@Thomas Huxhorn,

As it has been pointed out to me things like "std::map" and "std::vector" may be beyond what elenama65 has learned so far.

They are nice suggestions, but may not be usable at this time.

I realize that you are fairly new here, but it is often better to see what the OP can do before making suggestions that can not be used.

I am not saying that what you suggested is wrong, but it may be ahead of time for OP.

Andy
@ Handy Andy
Oh okay. std::vector should be the first thing someone should see when he first touch C++. Otherwise it will be a mess with C-like thinking of memory management.

I like to write such small examples. If it is beyond what elenama65 understand, its okay. Maybe he come back some day :)
@elenama65, I think you need to give us more than an essay title to consider.

I actually thought that the structs that @Thomas Huxhorn suggested were eminently sensible, and std::vector was the most appropriate, ahem, vehicle to store dynamic information here.

So, @elenama65, sketch some ideas out on paper and come back to us with some sample code to critique.
Handy Andy wrote:
As it has been pointed out to me things like "std::map" and "std::vector" may be beyond what elenama65 has learned so far.

They are nice suggestions, but may not be usable at this time.

Then the OP needs to tell us what they can and can't use.

Not a lot of information was given to us, other than an implied "do all the work for me for free" bit of begging.

Using STL containers is very likely not allowed, but we don't know they are off limits at this time. The OP says so, then we'll know and will adjust our advice.
Last edited on
Topic archived. No new replies allowed.