Open and Read file question?

Hi! I was just wondering if I could get a little direction on my final project. I'm a super noob so apologies beforehand!

A little back story: I work in a blood center that supplies blood product to local and regional hospitals. These hospitals only accept product that have a specific minimum outdate (expiration date). It varies from 7/10 days to 2/3/4 week outdates. We currently use an archaic system where I look at an Excel file that contains minimum dates they take and I look at a calendar on the board and figure out from there.

In my program you should be able to enter the current day's date and the hospital code that is being sent product. It will then output the correct minimum expiration date they are able to take.

My question is, is the best way to do this to open and read a file? If so, how should I gather the data? At first I thought separate the hospital into their own files by outdate, but that's quite a few files. Will it work if I gather it all on one document? I also don't want to write to a new file, I just want it to pull the data from the file and create an expression that will calculate the correct date. Is this plausible or am I making up something that won't logistically work??

To be honest, I think I might've bit off more than I could chew. This C++ class is only an intro to, and we've only briefly touched on open/read/write files.

Thank you! Any suggestions are appreciated. And if you have any specific links that my be helpful, I will forever be in your debt.
Hello suzernator,

This sounds like something I first wrote when I started with C++.

I would start with looking at the Excel file when Excel is running. Write down what information is there. From this it will give you an idea of what you will want in your program.

At some point you will need to save the Excel file as a CSV, (Comma Separated Value), file for the program to work with.

With that design a data structure for your program. This would be a struct, maybe a class if you are that far, to work with in your program.

Some questions to think about:
For a hospital when looking at the out date how many are there? Is it always the same amount or does it vary? The out date is not a problem, but will require dealing with a line in the file differently.

The best approach is to design the program before you code. This makes it easier to code when you have a direction.

Andy
Reading and writing files is fairly trivial.

Where it all gets complicated is how the information in those files is formatted.

Text files are the easiest to deal with, and C++ has plenty of tools in the standard library to deal with strings of characters.

https://en.wikipedia.org/wiki/Comma-separated_values
This is a common format for data interchange between database/spreadsheet type applications. Reading lines and extracting fields in C++ is straight forward.

There are also standard functions for dealing with dates and times, so for example you work out how many days lie between two dates without writing masses of code.

> We currently use an archaic system where I look at an Excel file that contains minimum
> dates they take and I look at a calendar on the board and figure out from there.
Really old Excel file formats are closed proprietary format binary files that definitely not beginner material.
Modern Excel typically uses some form of XML.
https://en.wikipedia.org/wiki/Microsoft_Office_XML_formats
XML is nice (because it's just text) but perhaps awkward (because there's so much structure wrapped around the data).


If you were to post some examples of your text (anonymised where necessary) surrounded by [output][/output] tags, we should be able to tell you ways to extract what you need.
If all the data you require is already in an Excel file(s) and you only need to input minimal additional data, then you can directly access the Excel file data from within C++.

What data is required? Where can this be obtained - from existing files, entered by the user, internally obtained (such as today's date)? When you have this info and know how to produce the required output from this data, then you are in a good position to start to design the program.

You need to first understand the required input (from which source), the required output and the process to generate the output from the input. Once you have this documented, you can then start designing the program based upon this. The first being to design the data structure(s) to be used, then the container(s) to hold this data. Once you have these then the next is to populate them from the input source(s), display the data to ensure that the population works, perform required calculations etc and then finally to output the required results.

The more detail you can provide re this then the more guidance we can provide.


you do not sound like you need a file at all so far*.
it sounds like you can make your own file (or, this changes very slowly, you can probably just put the list into the code at first) of hospitals** and their codes, and internally, a lookup table of what a code means eg code 'D' could mean 'today + 5 days'.
c++ has date and time functions, you can in a line or two get today's date *** and the code and return the date+5 days to the user.


* a file is a better design, so you can add more hospitals or change them over a long lifespan. But really, how often does a new one pop up or the name change every decade? Its not that common even in giant cities much less everywhere else.

** the hospital names etc are irrelevant, if the code is sufficient to make the date adjustment.

*** this assumes the computer knows today's date correctly. It will usually, modern PC check the web and keep that up to date (haha) via the internet, but an isolated (no network) machine can still have it all wrong or the wrong time zone set. You can't fix this easily (you can ask the web, but if its connected to the web, the date is likely OK -- leaving you to maybe check the web and if you can't get to it, warn the user to check the date manually or put a warning in all the time that the software requires the date to be set correctly at the OS level).

if you hard code the hospitals for now, you can dump your table to a file later and read it back in as an improvement. I do this frequently to muddle through a problem. It delays committing to a format before you know all the bits you may want in it.
Last edited on
Registered users can post here. Sign in or register to post.