+ 17
[SOLUTION] C++ I need help
There are several (N) cars in the repair shop. We have the following information about them: number, brand, owner's name, date of last repair (day, month, year), date of repair (day, month, year). Develop a sort program using the direct addition method (optional): 1. Arrange the names of car owners in alphabetical order and print information about their cars accordingly. https://code.sololearn.com/cb1Xfhx1zi7Y/?ref=app
11 Respostas
+ 5
Flash yes I used free instead of delete because I don't know C++. I corrected it. Thanks.
+ 4
All right I checked on the web and yes, even in C++ you need to allocate memory for your pointers. So after you declare:
mashine *car[5];
you need this:
for(int i = 0; i < 5; ++i ) {
car[i] = new mashina;
}
Also you need to correct the function call in line 69 like that:
saralash(car, 5);
Because by dereferencing car (i.e. writing *car) you would pass a pointer to mashina rather than an array of pointers to mashina.
+ 3
â Sanjar â
maybe no need of raw pointers. Try to use references if applicable. here is a solution using OOP of task 1. I didnât get âdirect addition methodâ part.
https://code.sololearn.com/c8rEUBoH4G7F/?ref=app
+ 2
I don't know C++ but the problem may be that you use the pointers to mashina without allocating memory for them.
+ 2
I also noticed that saralash() was giving a segmentation fault. I fixed it. Pointers are your main problem. Look for more information about them, the web is full of resources.
https://code.sololearn.com/cUeQhcFcokw0/?ref=app
+ 2
Flash yes, I added a line at the end. Thanks for the heads up
+ 2
â Sanjar â you are welcome đ€
+ 1
shouldnât you also address memory leaks? Davide
0
Davide didnât check it before. your code leaks memory. donât call c deallocator to deallocate c++ objects. you had 5 pointers. free deleted the first and one destructor was called. rest is lost hence leaks memory. pay attention to line 20, 86, 87. malloc()-free();new-delete;new[]-delete[]; I think you wrote you didnât know C++. anyway, hope this helps. here is the code:
https://code.sololearn.com/czuNaX7onK0r/?ref=app