Programming Assignment

I'm very new to programming, and I would really like help, just enough to know where to start this problem, everyone in my class is having troubles with it too because our professor didn't really teach us that well. Please help me know where to start. This is in c++ format, and I am using visual studio.

A text file partData.txt contains information on parts sold by a company. Each line in the file contains information on one part as follows:
Part number (an integer), selling price (a double) and the quantity in stock (an integer).
Another text file orders.txt contains information on order requests to the company. Each line in the file contains information on one order as follows:
Order number (an integer), part number (an integer) and quantity requested (an integer)
Both files are in arbitrary order. Both files contains a single 0 indicate end of data.

Write a program to read and store the part information from partData.txt into a linked list of an appropriate structure type. Read, but do not store, the orders.txt file and print for each successful order, the order number, part number, quantity requested and invoice total. A successful order is one where the part has been found and there is enough quantity in stock to fulfill the order. As an order is completed, you must make appropriate changes to the quantity remaining in stock for each part. If an order cannot be completed, an appropriate message that indicates the problem must be output. You must also print after processing the orders, the total number of orders fulfilled and total orders unfulfilled. All output is to be done to the file report.txt.
Last edited on
Hi, do you know how to read from a file?
You should read
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.

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.

#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
Once you're comfortable, combine the things into one program.
Last edited on
Topic archived. No new replies allowed.