Hey guys need help realy fast , i am young engineer student, i have to finish my program tomorrow. I need to make 2 programms, first one should make a text file which contains 10. different cars, i should show its brand, gear(manual,automatical), cars year,and registration number. i have already done that.
The second program should search for cars. I need to find cars with typing manual or automatical. it need to show automatical gear cars if i write automatical or if i write manual, it should show manual cars. I have 24 hours from right now could anybody help me?
I have to make it in dev c++.
So far it depends on how you've written the first program ie how the format of how the data is saved from the file. your program will read from the file line by line so your data in the file would look something like this:
Car1, Brand, Gear, year,
Car2,Brand, Gear, Year,
once your program reads back the file once it identifies that a kewyword manual or automatic it then displays that line of string.
Thats one way how to do it.
If you add some code to show that would help;
I'm afraid with dev-cpp you'd be fighting with one hand tied behind your back but given your time constraints its probably unwise to switch to Code::Blocks or Visual Studio 2017 now
Anyway, consider using a struct:
# include <iostream>
# include <string>
# include <vector>
# include <algorithm>
# include <fstream>
# include <sstream>
//now overload ctor with these data members
//overload input operator >> for Car
//overload output operator << for Car
//use emplace_back() to create 10 Car instances in-situ within carsVec;
//use overloaded >> operator to write carsVec to file
//for searching manual/automatic cars you could either do it from the file or ...
// ... read all the Car objects back from file into another vector and ...
// use std::find_if() on the second vector
//either way you'd probably need std::istringstream to read the file
If this approach is of interest research all unfamiliar terms thoroughly and, only then, come back here with specific questions if you have any
First you will have to know how the data file is written before you can read the file. Since you have not shown what the data file looks like or any attempt you have made on the second program. All I can suggest what you can do.
I am thinking of a struct to hold the data for each car and a vector of these structs to make searching easier.
Until I know what you have done it is hard to go any farther.