Struct Report strings I/O

So Im having trouble writing this piece of code.

This is the story:

The Department of Information Technology needs a means of assessing current system usage. It is your job to write a C++ program that will produce a report at the end of each month that shows the status of each user’s account.
Input the computer usage records (in ascending order of uids) for the month of January from a text file (prompt the user of the program for the filename). Each record will contain 4 fields: a user name, id number, resource limit amount and amount of resources used to date. The records should be read into an array of structures.

Sample records:

Doe,John 100001 500 270.89
Brady,Laura 100002 650 598.84

Each element in the array ( a struct) should contain the following data members:
User name (a string in the form lastname,firstname)
Userid (a 6 digit integer)
Resource limit (integer)

Flag field (character data that will hold an asterisk (*) if 90% or more of available resources have been used)

For each record read, your program must calculate and store the percent of resources used and store an asterisk in the flag field if 90% or more of resources have been used to date.

Modify the code in your text for a Selection Sort to sort the records in descending order of “Percent of Resources Used”. Print the sorted records to an output file in the form of a table. Title the report appropriately and include the month name. Label and align each column.

Note: Arrays are, by default, passed CALL BY REFERENCE. A structure is passed CALL BY VALUE. Implement the Selection Sort with a separate swap function as n your text.


And heres my code so far:
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
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>
#include <fstream>
#include<iomanip>
using namespace std;
char Datareader(string);
int main ()
{
ifstream indata;
ofstream outdata;
string infile;
string outfile;
cout<< "What is the name of the file you are looking for?";
cin>>infile;
 
 Datareader(infile);
//system("Pause");
indata.close();
  
return 0;
}
char Datareader()
{
ifstream indata;
ofstream outdata;
string infile;
string outfile;
 
indata.open (infile.c_str());  //opens the input file
 
    if (!indata)                                    
    {
        cout << "Cannot open the input file."
             << endl;
        return 1;
    }
 else
  return(indata);
}


My first problem is that I want to return indata but i cant store this in a void and if I try anything else I get errors. My second Problem is I need to put the whole thing in a struct of some kind. Hell I might need help with the whole thing.


Anyways Im supposed to Flag the guys in trouble(with memory) at the top so in descending order.
Last edited on
Topic archived. No new replies allowed.