Question: Each molecular formula will be kept in a struct with three fields: the namneis) for formula. Note that is a collection of names the number

 Each molecular formula will be kept in a struct with three

Each molecular formula will be kept in a struct with three fields: the namneis) for formula. Note that is a collection of names the number of carbon atoms the number of hydrogen atoms We will be storing all these structs in a vector An example Suppose this is the file: n-Butane C4H10 Propyne C3H3 1,3-Butadiyne C4H2 Hexane C6H14 Butane C4H10 iso-Butane C4H10 Pentane C5H12 Your program should store these five entries and then display: 3 Propyne C4H2 1,3-Butadiyne C4H10 n-Butane Butane iso-Butane C5H12 Pentane 614 Hexane The collection has been sorted by number of carbons and then the number of hydrogens. I assure you know from data structures how to write some simple sort algorithm, e.g. bubble sort, selection sort or insertion sort. (Yes, in general these run in quadratic time, but we don't want you spending a lot of time implementing a more effecient sort.) Write a function that will be passed your collection and modify it so that it is sorted. Notes As always, write good clean code. What does that mean? . Good use of functions to make code more readable. Good naming of everything. No long lines. What's long? Anything over 80 characters. And now that you know about function prototypes (if not covered in your lecture section look it up in the notes or ask in lab), there should first be one for each of your functions other than main, then the definition of main, and then the definitions of those functions. In the interests of encouraging good design (and saving you from having to rewrite your program if we find it poorly written) let me outline what main will do: Define variables for the stream and vector. No, don't open the stream here. Call a function to open the stream. It will ask the user for a filename. If the filename fails, repeatedly ask for a new one until you succeed. If opening the stream object fails, you will need to call the clear() method on the stream before attempting to open it again. By the time this function is done, the stream should be open. It does not need to return anything. Call a function to fill the vector from the stream. Pass in the vector and the stream. Do not return anything, Call a function to sort the vector, in place. Call a function to display the vector. In addition to the functions directly called by main, it a couple of other functions would make the overall code easier to read A function to insert the information for a name, carbon count and hydrogen count into the vector. A function to find the location of a formula object that matches the number of hydrogene and carbons for a new entry. It will have to return a suitable value if there is no such formala entry in the vector yet. This function would obviously be called by the one in the previous bullet. We want to track all of the names of the formulae. It would not be very useful if we were to build up a long string of all the names. Instead what makes sense? We want a collection of the all of the names for each formula, not a single string

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!