Hello, I am a C++ beginner just started to learn, I got a question from my book and I do not have any idea how to start. Can anyone please help me? Thank you in advance.
Here are the questions:
----------------------------------------------------------------
write a project which include:
1. At least one struct or class
2. At least four user-defined (member or non-member) functions
3. Vector
4. Use 'static' variable or function overloading
5. File I/O
----------------------------------------------------------------
I have an idea that I will create a list 3 books into a txt files, then my program will read the 3 book titles from the txt file and create a vector. (File output)
For the struct part, I am thinking I can assign the writer, and price as the preferences of the 3 books.
I will also use static to count how many changes I made to the book's preferences.
Lastly I don't know what to do about the file input.
Again, I am sorry that I did not ask for specific topic, instead I need some direction on how to construct the program.
I have an idea that I will create a list 3 books into a txt files, then my program will read the 3 book titles from the txt file and create a vector. (File output)
Nice Idea
or the struct part, I am thinking I can assign the writer, and price as the preferences of the 3 books.
I'm not quite sure what you mean here, perhaps you want to create
a structure with writer and price as the members ? something like:
1 2 3 4 5
struct Book {
string writer;
double price;
// Don't forget the title
};
Lastly I don't know what to do about the file input.
You might want to create functions to read and write Books to a file, something like:
1 2 3
vector<Book> readFromFile(istream& is);
void writeToFile (const vector<Book>& books, ostream& os);
void writeToFile (const Book& book, ostream& os); // function overload for a single book