Hi, do you know how to read from a file?
You should read
http://www.cplusplus.com/doc/tutorial/files/
I feel like the tutorial itself is lacking in some ways, but it's still good to read. Learning "how to learn" and how to look up documentation is a big part of programming.
I also suggest a good book.
https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list
To begin, I'll show you an example of reading from paraData.txt. You know that each line contains 3 numbers, in the form {integer, double, integer}. The tutorial I linked above is lacking in that it doesn't show an example of it, but you can easily parse this using the
>> operator of the file stream (very similar to cin) to extract the three numbers.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#include <iostream>
#include <fstream>
int main()
{
std::ifstream fin("paraData.txt");
if (!fin) // check file is properly opened
{
std::cout << "Error opening paraData.txt" << std::endl;
return 1;
}
// now, we know the file is open successfully
// set up the meaningful variables that we need to read in.
int part_number;
double selling_price;
int quantity_in_stock;
// while able to successfully extract 3 numbers from the stream each time
while (fin >> part_number >> selling_price >> quantity_in_stock)
{
std::cout << "part number: " << part_number << std::endl;
std::cout << "selling price: " << selling_price << std::endl;
std::cout << "quantity in stock: " << quantity_in_stock << std::endl;
}
}
|
Understand this, and then try to apply it to the other files.
I personally hate instructors that have you apply half a dozen different concepts all at once. What you should be doing is practicing each concept at once, and then combining then.
First, make a program that can extract a number from a file, and simply display the number read.
Then, make a program that can extract multiple number from a file, and stop when the number is 0.
Then, make a program that makes a struct, and assigns values to it.
Then, forget files, and make a linked list. Understanding a linked list will probably be the hardest part of this assignment, so don't try to tackle it from the start. Do the other parts first. Then search online for examples of how to make a linked list.
Google C++ linked lists for more information, and try one out yourself. This link I skimmed looks pretty good
https://www.codementor.io/codementorteam/a-comprehensive-guide-to-implementation-of-singly-linked-list-using-c_plus_plus-ondlm5azr
Once you're comfortable, combine the things into one program.