Urgent Help..Array of Structures

I have an assignment and I am stuck on it and need help. Im not very good with coding so I appreciate any feedback.

The assignment:
Summary:

Write a C++ console application that reads line after line of job opening data from a text file, asks the user to enter the desirability (1= low to 5 = high) of each opening, and then interactively allows the user to repeatedly print the entire list or search by salary range and/or desirability range.

Further Details:

The user should be prompted to enter the name of the text file, which should be in the current working directory when this program is run. Each line of data must consist of company name, job title, salary (assumed to be an integer), location (the 2-letter abbreviation for the state), phone, email, and web site -- separated by commas. Thus a typical line of data might look like this:

Raytheon,programmer,65000,PA,412-122-4560,careers@raytheon.com,www.raytheon.com

Notice that there are no spaces, only commas, separating the data items. The file should normally contain 24 or fewer lines of data. If there are more, the program should print a warning and only process the first 24 lines.

The output when printing the entire list of jobs or the results of a search should be nicely formatted and include all of the data on each job that is being reported, including the desirability number.

The Design:

Use an array of 24 structures to hold the data that is read in from the file. You will also have to store the count of how many lines of data were read in, so that you know how many of the 24 structures hold legitimate data. All of the fields in your structure type should be string class objects except for the salary and the desirability rating, both of which should be integers.

Set up a type (that is, use a typedef) for any array of 24 such structures. That will make it easier to pass an array of this type as a parameter to a function.

As always, immediately after trying to open the file, check to see if the open failed. If it did fail, take the following actions: Print a message telling the use that the file (identify it by name) could not be opened and that the program will thus terminate. Pause the screen so that the user can read the message. Then use exit(1) to exit the program. Note that a good way to pause the screen is as follows:

getline(cin, junk, '\n'); // junk should be a variable of type string

As long as you do not have a newline already sitting in the input buffer, the above will pause the screen, waiting for the user to press Enter. You should generally strive to keep the input buffer clear of data so that you can correctly pause the screen with the above command. If, for example, the user enters a number that is read in as an int, float, double, etc., the newline generated by pressing Enter after typing the number will be left in the input buffer. That newline (and any preceding junk such as spaces) can be cleared out with the same command as above, since it reads in everything up to and including the newline:

getline(cin, junk, '\n'); // junk should be a variable of type string

You must divide your program so that you write at least 3 helping functions. In fact, you might want more such as:

a function to read the data from the file and place it into the array of structures
a function that asks the user for the desirability number for each job, placing it into the correct structure
a function that allows the user to repeatedly choose to print all the job info or search for jobs
a function that prints all the job info
a function that carries out the search (based on salary range and/or desirability range)

You might want to write other helping functions such as these:
a function that asks the user for the salary range and desirability range to use in a search
a function that prints one structure of job info in a nicely-formatted manner

The main function should probably be where to prompt for the name of the text file and to open and close the file. It will also need to call some of your helping functions.

Make sure that your program works reasonably if the data file is present but is empty. Similarly, check to see that it works when the file holds 25 lines of data, in which case it should only process the first 24 lines and print a warning to the user that not all of the data would fit.

Reading the Data:

The function that reads the data from the text file and places it into the array of structures is complicated by the fact that we have a mixture of strings and numbers on each line. However, the commas used as separators help a lot. Since the reading is a bit complex, here is an outline of what you must do:

Start some index variable at zero.
We read the first line of data ahead of the loop as follows:
Read the company name into a temporary variable using getline with ',' as the marker for end of string.
Read the job title into a temporary variable using getline in a similar fashion.
Read the salary number into a temporary int variable using >>, as getline is only for strings.
Use getline to read up to and including the comma (the one following the salary and before location)
putting the stuff read into some junk variable. This is to discard the comma before the next read.
Read the location (state) into a temporary variable using getline with ',' as the marker for end of string.
Read the phone number into a temporary string variable in the same manner.
Read the email address into a temporary variable in the same way.
Read the website into a temporary variable using getline, but with the newline '\n' as the end marker.

while (the read did not fail) and (the index < the maximum number of structures in the array)
{
Use assignment to copy each of the values from the temporary variables and place them into the
fields of the structure at the correct index in the array.
Increment your index variable.
Read the next line of data into the same temporary variables using the same code as above.
}

If the data did not all fit
Print a message warning the user of this.



Sample Output:

There may be too much data for a job to display it all on one line. You might want to instead display it in a block like the following and then pause the screen before going on to display the next set of data.

Job Title: programmer
Company name: Raytheon
Salary: 65000
Desirability: 1
Location: PA
Phone number: 412-122-4560
Email address: careers@raytheon.com
Web site: www.raytheon.com

My coding which is incomplete
#include <iostream>
#include <string>
#include <fstream>
using namespace std;




struct CompanyInfo
{
string TempCompanyName, TempJobTitle, TempLocation, TempEmail, TempWebsite, TempPhone;
int TempSalary, Desirability
};

CompanyInfo lines[24];

void InfoRead (ifstream, CompanyInfo[])
{
int i = 0;
while (!InFile.fail()) && (i < 24)

cout << i << endl;
i++;
}
getline(InFile, TempCompanyName, ','); // Read the company name, ending at the comma.
getline(InFile, TempJobTitle, ',');
InFile >> TempSalary;
getline(InFile, Junk, ','); // Read the comma before the start of the location.
getline(InFile, TempLocation, ',');
getline(InFile, TempPhone, ',');
getline(InFile, TempEmail, ',');
getline(InFile, TempWebsite, '\n'); // Website should be the last thing on the line

int main()
{
ifstream InFile;

InFile.open("jobs24.txt", ios::in)

if (InFile.fail())
{
cout << "Could not open jobs24.txt" << endl;
exit(1);
}
InfoRead(ifstream, CompanyInfo[]);
closed account (48T7M4Gy)
So what are you stuck on?
Like what more should i add to make the coding complete?
closed account (48T7M4Gy)
Like what more should i add to make the coding complete?
1
2
return 0;
}
at the end would be a good move in finishing of the code you wrote.
Does what i have satisfy what is needed
Topic archived. No new replies allowed.