Confused Why I am getting C1010 error?

Posted by bluepixel on Stack Overflow See other posts from Stack Overflow or by bluepixel
Published on 2010-05-12T23:07:26Z Indexed on 2010/05/12 23:14 UTC
Read the original article Hit count: 259

Filed under:

I have three files: Main, slist.h and slist.cpp can be seen at http://forums.devarticles.com/c-c-help-52/confused-why-i-am-getting-c2143-and-c1010-error-259574.html

I'm trying to make a program where main reads the list of student names from a file (roster.txt) and inserts all the names in a list in ascending order. This is the full class roster list (notCheckedIN). From here I will read all students who have come to write the exams, each checkin will transfer their name to another list (in ascending order) called present.

The final product is notCheckedIN will contain a list of all those students that did not write the exam and present will contain the list of all students who wrote the exam

Main File:

// Exam.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include "iostream"
#include "iomanip"
#include "fstream"
#include "string"
#include "slist.h"

using namespace std;

void OpenFile(ifstream&);
void GetClassRoster(SortList&, ifstream&);
void InputStuName(SortList&, SortList&);
void UpdateList(SortList&, SortList&, string);
void Print(SortList&, SortList&);
const string END_DATA = "EndData";

int main()
{

ifstream roster;
SortList notCheckedIn; //students present
SortList present; //student absent

OpenFile(roster);
if(!roster) //Make sure file is opened
return 1;
GetClassRoster(notCheckedIn, roster); //insert the roster list into the notCheckedIn list
InputStuName(present, notCheckedIn);
Print(present, notCheckedIn);
return 0;
}

void OpenFile(ifstream& roster)
//Precondition: roster is pointing to file containing student anmes
//Postcondition:IF file does not exist -> exit
{
string fileName = "roster.txt";
roster.open(fileName.c_str());

if(!roster)
cout << "***ERROR CANNOT OPEN FILE :"<< fileName << "***" << endl;
}
void GetClassRoster(SortList& notCheckedIN, ifstream& roster)
//Precondition:roster points to file containing list of student last name
// && notCheckedIN is empty
//Postcondition:notCheckedIN is filled with the names taken from roster.txt in ascending order
{
string name;
roster >> name;
while(roster)
{
notCheckedIN.Insert(name);
roster >> name;
}
}
void InputStuName(SortList& present, SortList& notCheckedIN)
//Precondition: present list is empty initially and notCheckedIN list is full
//Postcondition: repeated prompting to enter stuName
// && notCheckedIN will delete all names found in present
// && present will contain names present
// && names not found in notCheckedIN will report Error
{
string stuName;

cout << "Enter last name (Enter EndData if none to Enter): ";
cin >> stuName;
while(stuName!=END_DATA)
{
UpdateList(present, notCheckedIN, stuName);
}
}
void UpdateList(SortList& present, SortList& notCheckedIN, string stuName)
//Precondition:stuName is assigned
//Postcondition:IF stuName is present, stuName is inserted in present list
// && stuName is removed from the notCheckedIN list
// ELSE stuName does not exist
{
if(notCheckedIN.isPresent(stuName))
{
present.Insert(stuName);
notCheckedIN.Delete(stuName);
}
else
cout << "NAME IS NOT PRESENT" << endl;
}
void Print(SortList& present, SortList& notCheckedIN)
//Precondition: present and notCheckedIN contains a list of student Names present/not present
//Postcondition: content of present and notCheckedIN is printed
{
cout << "Candidates Present" << endl;
present.Print();

cout << "Candidates Absent" << endl;
notCheckedIN.Print();
}

Header File:

//Specification File: slist.h
//This file gives the specifications of a list abstract data type
//List items inserted will be in order
//Class SortList, structured type used to represent an ADT
using namespace std;
const int MAX_LENGTH = 200;
typedef string ItemType;
//Class Object (class instance) SortList. Variable of class type.
class SortList
{
//Class Member - components of a class, can be either data or functions
public:
//Constructor
//Post-condition: Empty list is created
SortList();

//Const member function. Compiler error occurs if any statement within tries to modify a private data
bool isEmpty() const;
//Post-condition: == true if list is empty
// == false if list is not empty

bool isFull() const;
//Post-condition: == true if list is full
// == false if list is full

int Length() const;
//Post-condition: size of list

void Insert(ItemType item);
//Precondition: NOT isFull() && item is assigned
//Postcondition: item is in list && Length() = Length()@entry + 1

void Delete(ItemType item);
//Precondition: NOT isEmpty() && item is assigned
//Postcondition:
// IF items is in list at entry
// first occurance of item in list is removed
// && Length() = Length()@entry -1;
// ELSE
// list is not changed

bool isPresent(ItemType item) const;
//Precondition: item is assigned
//Postcondition: == true if item is present in list
// == false if item is not present in list

void Print() const;
//Postcondition: All component of list have been output
private:
int length;
ItemType data[MAX_LENGTH];
void BinSearch(ItemType, bool&, int&) const;

};

Source File:

//Implementation File: slist.cpp
//This file gives the specifications of a list abstract data type
//List items inserted will be in order
//Class SortList, structured type used to represent an ADT
#include "iostream"
#include "slist.h"

using namespace std;
// int length;
// ItemType data[MAX_SIZE];
//Class Object (class instance) SortList. Variable of class type.
SortList::SortList()
//Constructor
//Post-condition: Empty list is created
{
length=0;
}

//Const member function. Compiler error occurs if any statement within tries to modify a private data
bool SortList::isEmpty() const
//Post-condition: == true if list is empty
// == false if list is not empty
{
return(length==0);
}

bool SortList::isFull() const
//Post-condition: == true if list is full
// == false if list is full
{
return (length==(MAX_LENGTH-1));
}

int SortList::Length() const
//Post-condition: size of list
{
return length;
}

void SortList::Insert(ItemType item)
//Precondition: NOT isFull() && item is assigned
//Postcondition: item is in list && Length() = Length()@entry + 1
// && list componenet are in ascending order of value
{
int index;
index = length -1;
while(index >=0 && item<data[index])
{
data[index+1]=data[index];
index--;
}
data[index+1]=item;
length++;
}

void SortList:elete(ItemType item)
//Precondition: NOT isEmpty() && item is assigned
//Postcondition:
// IF items is in list at entry
// first occurance of item in list is removed
// && Length() = Length()@entry -1;
// && list components are in ascending order
// ELSE data array is unchanged
{
bool found;
int position;

BinSearch(item,found,position);

if (found)
{
for(int index = position; index < length; index++)
data[index]=data[index+1];
length--;
}
}

bool SortList::isPresent(ItemType item) const
//Precondition: item is assigned && length <= MAX_LENGTH && items are in ascending order
//Postcondition: true if item is found in the list
// false if item is not found in the list
{
bool found;
int position;

BinSearch(item,found,position);
return (found);
}

void SortList::Print() const
//Postcondition: All component of list have been output
{
for(int x= 0; x<length; x++)
cout << data[x] << endl;
}

void SortList::BinSearch(ItemType item, bool found, int position) const
//Precondition: item contains item to be found
// && item in the list is an ascending order
//Postcondition: IF item is in list, position is returned
// ELSE item does not exist in the list
{
int first = 0;
int last = length -1;
int middle;

found = false;
while(!found)
{
middle = (first+last)/2;
if(data[middle]<item)
first = middle+1;
else if (data[middle] > item)
last = middle -1;
else
found = true;
}
if(found)
position = middle;
}

I cannot get rid of the C1010 error: fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

Is there a way to get rid of this error? When I included "stdafx.h" I received the following 32 errors (which does not make sense to me why because I referred back to my manual on how to use Class method - everything looks a.ok.)

Error 1 error C2871: 'std' : a namespace with this name does not exist c:\..\slist.h 6
Error 2 error C2146: syntax error : missing ';' before identifier 'ItemType' c:\..\slist.h 8
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\..\slist.h 8
Error 4 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\..\slist.h 8
Error 5 error C2061: syntax error : identifier 'ItemType' c:\..\slist.h 30
Error 6 error C2061: syntax error : identifier 'ItemType' c:\..\slist.h 34
Error 7 error C2061: syntax error : identifier 'ItemType' c:\..\slist.h 43
Error 8 error C2146: syntax error : missing ';' before identifier 'data' c:\..\slist.h 52
Error 9 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\..\slist.h 52
Error 10 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\..\slist.h 52
Error 11 error C2061: syntax error : identifier 'ItemType' c:\..\slist.h 53
Error 12 error C2146: syntax error : missing ')' before identifier 'item' c:\..\slist.cpp 41
Error 13 error C2761: 'void SortList::Insert(void)' : member function redeclaration not allowed c:\..\slist.cpp 41
Error 14 error C2059: syntax error : ')' c:\..\slist.cpp 41
Error 15 error C2143: syntax error : missing ';' before '{' c:\..\slist.cpp 45
Error 16 error C2447: '{' : missing function header (old-style formal list?) c:\..\slist.cpp 45
Error 17 error C2146: syntax error : missing ')' before identifier 'item' c:\..\slist.cpp 57
Error 18 error C2761: 'void SortList:elete(void)' : member function redeclaration not allowed c:\..\slist.cpp 57
Error 19 error C2059: syntax error : ')' c:\..\slist.cpp 57
Error 20 error C2143: syntax error : missing ';' before '{' c:\..\slist.cpp 65
Error 21 error C2447: '{' : missing function header (old-style formal list?) c:\..\slist.cpp 65
Error 22 error C2146: syntax error : missing ')' before identifier 'item' c:\..\slist.cpp 79
Error 23 error C2761: 'bool SortList::isPresent(void) const' : member function redeclaration not allowed c:\..\slist.cpp 79
Error 24 error C2059: syntax error : ')' c:\..\slist.cpp 79
Error 25 error C2143: syntax error : missing ';' before '{' c:\..\slist.cpp 83
Error 26 error C2447: '{' : missing function header (old-style formal list?) c:\..\slist.cpp 83
Error 27 error C2065: 'data' : undeclared identifier c:\..\slist.cpp 95
Error 28 error C2146: syntax error : missing ')' before identifier 'item' c:\..\slist.cpp 98
Error 29 error C2761: 'void SortList::BinSearch(void) const' : member function redeclaration not allowed c:\..\slist.cpp 98
Error 30 error C2059: syntax error : ')' c:\..\slist.cpp 98
Error 31 error C2143: syntax error : missing ';' before '{' c:\..\slist.cpp 103
Error 32 error C2447: '{' : missing function header (old-style formal list?) c:\..\slist.cpp 103

© Stack Overflow or respective owner

Related posts about c++