Linking files

carmel937
carmel937 used Ask the Experts™
on
I'm working with multiple files. I linked the files together, but some of my declarations are not being recognized.  I'm receiving the following errors.

Compiling...
brenda.cpp
c:\windows\desktop\brenda.h(20) : error C2061: syntax error : identifier 'ifstream'
c:\windows\desktop\brenda.h(31) : error C2079: 'data' uses undefined struct 'ItemType'
c:\windows\desktop\brenda.cpp(7) : fatal error C1083: Cannot open include file: 'bwalkerAssign7Structure.h': No such file or directory
Error executing cl.exe.

brenda.obj - 3 error(s), 0 warning(s)


// CLIENT FILE

#include <iostream>
#include <fstream>
#include <string>
#include "Brenda.h"
#include "bwalkerAssign7Structure.h"

using namespace std;


int main()
{

ifstream infile;
Strong temp;                        // class type variable
string fileName;                    // name of file
int pos, ItemType item;
bool valid;


      cout << "Enter the input file name ";  // Prompt user to enter file name
      cin >> fileName;                       // File name received from user

      infile.open(fileName.c_str());         // Opens the file
      

         if(!infile)                           // test for error in opening file
      {
            cout << "Can't open the input file.";
            return 1;
      }

      
      cout << "No. of readings:  " << temp.Length() << endl << endl;
      cout << "Original list"  << endl;

            temp.getData(infile, item);
      
            while (infile && !temp.IsFull())
            {
            temp.Component(pos, item, valid);
            temp.SelSort();
            temp.Print();
            temp.Percent();
            temp.getData(infile, item);
            }

      return 0;
      }

// IMPLEMENTATION FILE


#include <iostream>
#include <fstream>
#include "Brenda.h"
#include "bwalkerAssign7Structure.h"

using namespace std;

Strong::Strong()              // constructor
{
length = 0;
}


bool Strong::IsEmpty() const
{
      return (length == 0);
}


bool Strong::IsFull() const
{
      return (length == MAX_LENGTH);
}


int Strong::Length()
{
      return length;
}



bool Strong::IsPresent(ItemType item)
{
      int index = 0;
      data[length].SName = item;
      while (item != data[index].SName)
      index++;
      return (index < length);
}


void Strong::getData(ifstream& infile, ItemType& item)
{      
      int count;
      for(count = 0; count < MAX_LENGTH < count++)
      {
      infile >> data[count].SName;
      infile >> data[count].Sales;
      infile >> data[count].Expenses;
      }
}


void Strong::Component(int pos, ItemType& item, bool& valid)
{

valid = (pos >= 0 && pos < length);
      if (valid)
      item = data[pos].SName;      
      
}



void Strong::Insert(ItemType item)
{
            data[length].SName = item;
            length++
}


void Strong::Delete(ItemType item)
{
            int index = 0;
            
            while (index < length && item != sale[index].SName)
                  index++;
                  
                  if (index < length)
                  {
                        data[index].SName = data[length-1].SName;
                        length--;
                  }
            
            [length] = item;
            length++
}


void Strong::SelSort()
{
      ItemType temp;
      int passCount;
      int searchIndx;
      int minIndx;

      for (passCount = 0; passCount < length - 1; passCount++)
      {
            minIndx = passCount;

            for (searchIndx = passCount + 1; searchIndx < length; searchIndx++)

                  if(data[searchIndx] < data[minIndx])
                        minIndx = searchIndx;

                  temp = data[minIndx].SName;
                  data[minIndx].SName = data[passCount].SName;
                  data[passCount].SName = temp;
      }

}


void Strong::Print()
{

      for(int count = 0; count < MAX_LENGTH; count++)

      cout << "Name" << '\t' << "Sales" << '\t' << "Expenses" << endl;
      cout <<  data[count].SName << '\t' << data[count].Sales;
      cout << '\t' << data[count].Expenses;
}



void Strong::Percent()
{
      int counter;
      int TotalSales = 0;
      int PercentSales;
      float TotalExpenses = 0;
      float PercentExpenses;

            for(counter = 0; counter < MAX_LENGTH; counter++)
            {
            TotalSales = TotalSales + data[counter].Sales;
            }

            for(counter = 0; counter < MAX_LENGTH; counter++)
            {
            TotalExpenses = TotalExpenses + data[counter].Expenses;
            }


            PercentSales = data.Sales / TotalSales;
            PercentExpenses = data.Expenses / TotalExpenses;

            cout << "Sales Analysis " << endl << endl;
            cout << "% Name" << '\t' << "% Expenses" << endl;

            for(counter = 0; counter < MAX_LENGTH; counter++)
            {
            cout data[counter].SName << '\t' << PercentSales[counter] << '\t' << PercentExpenses[counter] << endl;
            }
}


// SPECIFICATION FILE         bwalkerAssign7Spec.h

#include <iostream>
#include <fstream>

const int MAX_LENGTH = 50;

struct ItemType;

class Strong
{
public:

      bool IsEmpty() const;
      bool IsFull() const;
      int Length() const;
      bool IsPresent(ItemType item);
      void Component(int pos, ItemType& item, bool& valid);
      void getData(ifstream& infile, ItemType& item);
      void Insert(ItemType item);
      void Delete(ItemType item);
      void SelSort() const;
      void Print() const;
      void Percent();
      List();                // constructor

private:

      int length;
      ItemType data[MAX_LENGTH];

      };


      #include <iostream>


// STRUCTURE LIST



struct ItemType
{
char string SName[MAX_LENGTH];
int Sales;
float Expenses;
};


Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Is it possible to post the contents and name of each file as seperate comments. Makes it easier for me to recreate it and fix the errors.
Commented:
A few general remarks:

- every statement must end with a ';'
- in the header (.h) file, include all the necessary libraries -- in the implementation file (.cpp), only include the corresponding header file
- check that the signature for class members is the same for definition and implementation
- non-void functions must return a value

Commented:
- only variables of the same type can be declared in the same statement
make sure that the header files (mainly ifstream) is not corrupted or modified in any way.

even if a single ";" is missing from the file, it will create a lot of errors in your actual program
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Recommendation: Accept Comment from cuynen

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
DominicCronin
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial