954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

major help

I have to develop a C++ program that reads the data records from the input file and stores them in a dynamic array of structs, which should be sized just enough for the problem. (TIP: Your program should first scan the input file to determine the number of records to be processed.) After loading the data into the array, the program then processes the array and write appropriate output to two files (named assign06a.out and assign06b.out, say).

i was trying to compile it and keep coming up with major errors can anyone tell me what im doing wrong to make it read from a file. oh and we have to us implematation file client file and aplication file. here are my implematation and client file.


#ifndefSTRUCT_INVENTORY_H
#defineSTRUCT_INVENTORY_H

#include
#include
#include
#include


struct inventory
{

int id;
char description[41];
double wholesalePrice;
double retailPrice;
double avgWeeklySales;
double quantityInStock;
};

int numofRecords();

void getdata(ifstream fin);

#endif

implemntation file here:


#include
#include
#include
#include"assignment9.h"
using namespace std;

const int MAX_LEN = 30;


int numofRecords()
{

int numRecords;

cout <<"number of courses to process: ";
cin >> numRecords;

cin.ignore(999, '\n');

return numRecords;
}

int getdata(ifstream fin, ofstream fout)
{

char inputfilename[MAX_LEN + 1];

cout << "Input filename(up to"<> ws

while(!fin.eof())
{
fin >> records.id;
if(fin.eof())

{
cerr<<"Input file contains an incomplete record"<>ws

fin.get(record.description, MAX_LEN +1,'\n');
if(fin.eof())
{

cerr<<"inputfile contains an incomplete record"<>ws

fin >>records.wholesalePrice;

if(fin.eof())
{
cerr<<"inputfile contains an incomplete record"<> ws
fin >>records.retailPrice;
if(fin.eof())
{
cerr << "inputfile contains an incomplete record"<> ws
fin>>record.avgWeeklySales;
if(fin.eof())
{
cerr << "inputfile contains an incomplete record"<> ws
fin >>records.quantityInStock;

numofRecods ++;

fin.seekg(0);
fin.clear();

return numofRecords;

}

cout << records.id<< endl;
cout << records.description;
cout << records.wholesalePrice<< endl;
cout << records.retailPrice<< endl;
cout << records.avgWeeklySales<< endl;
cout << records.quantityInStock << endl;
cout << endl;
cout << "# of courses scanned: " << numOfCourses << endl;
cout << endl;

bucsoldier03
Newbie Poster
8 posts since Oct 2005
Reputation Points: 10
Solved Threads: 0
 

The declaration

void getdata(ifstream fin);

and its definition

int getdata(ifstream fin, ofstream fout)
{
...
}

does not match. You will get a link error.
Also I think I see a mismatch in the {} braces. This also should give you an EOF not found error. Use properly indented code, and you will catch most of these braces errors.


Those are some errors I see and there maybe more.
The other time you want us to find us the compiler errors, please post the error messages too. That is easy for us than copying and pasting your code and compiling it ourselves.

Use the[code][ /code]tags too. It makes the code more readable.

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

Use [code][/code] tags around your code.

Note: this code

cout<<"Error opening input file"<< inputfilename;
cout<<"press enter or return to continue...."<<endl;

if executed, would look like this:

Error opening input fileinput.txtpress enter or return to continue....
dwks
Posting Whiz in Training
269 posts since Nov 2005
Reputation Points: 185
Solved Threads: 28
 
fin >> ws

Don't forget your semicolons. :)

dwks
Posting Whiz in Training
269 posts since Nov 2005
Reputation Points: 185
Solved Threads: 28
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You