Thread: fatal error C1083: Cannot open include file-Using Classes

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    16

    fatal error C1083: Cannot open include file-Using Classes

    Hi! I'm currently taking OOD for C++ and had to write a program using classes, but for some reason, I keep getting the "fatal error C1083: Cannot open include file: 'student': No such file or directory" when compiling. I followed the book's instructions and still have no solution. If anyone could help, it would be greatly appreciated. Thanks!

    allPeople.h
    Code:
    #ifndef H_AllPeople
    #define H_AllPeople
    
    #include <iostream>
    #include <string>
    #include <iomanip>
    using namespace std;
    
    class allPeople
    {
    public:
    	//Function to set person's first name, last name, and
            //id number.
    	void setNameInfo (string first, string last, int idNumber);
    	
    	//Function to print name and idNumber.
    	void print () const;
    
    	//Constructor
    	allPeople (string first="", string last="", int idNumber=0);
    
    protected:
    	string fName;    //variable stores first name
    	string lName;    //variable stores last name
    	int personID; //variable stores ID number
    };
    
    void allPeople::print () const
    {
    	cout << "The person's name is " << fName << " " << lName << endl;
    	cout << "and their ID number is " << personID << "." << endl;
    }
    	//Function to output the first name, last name and ID number.
    	//Postcondition: Outputs
    	//The person's name is fName lName
    	//and their ID number is personID.
    
    
    void allPeople::setNameInfo (string first, string last, int idNumber)
    {
    	fName = first;
    	lName = last;
    	personID = idNumber;
    }
    	//Function to set the first name, last name, and ID number
    	//according to the parameters.
    	//Postcondition: fName=first; lName=last; personID=idNumber
    
    allPeople::allPeople (string first, string last, int idNumber)
    {
    	fName=first;
    	lName=last;
    	personID=idNumber;
    }
    
    #endif
    student.h
    Code:
    #ifndef H_Student
    #define H_Student
    
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include "allPeople"
    using namespace std;
    
    class student: public allPeople
    {
    public:
    
    	//Function to set the student information.
    	void setStudentInfo (string first, string last,
    		int idNumber, string stuStatus);
    
    	//Function to print the name, ID number and status.
    	void print () const;
    
    	//Constructor
    	student(string first="", string last="", int idNumber=0,
    		string="");
    
    private:
    	static string peopleClass;
    	string studentStatus;
    };
    
    string student::peopleClass = "Student";
    
    void student::setStudentInfo (string first, string last, int idNumber,
    r				string stuStatus)
    {
    	//use allPeople class to set the first, last, and idNumber
    	allPeople::setNameInfo(first, last, idNumber);
    
    	studentStatus = stuStatus;
    }
    
    void student::print () const
    {
    	allPeople::print ();  //uses allPeople class to print name and ID
    	cout << "The classification of this person is " << peopleClass << "."
     <<endl;
    	cout << "The status of this person is " << studentStatus << "." <<
     endl;
    }
    
    student::student (string first, string last, int idNumber, string
     stuStatus)
    
    	: allPeople (first, last, idNumber)
    {
    	studentStatus = stuStatus;
    }
    
    #endif
    faculty.h
    Code:
    #ifndef H_Faculty
    #define H_Faculty
    
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include "allPeople"
    using namespace std;
    
    class faculty: public allPeople
    {
    public:
    
    	//Function to set the faculty information.
    	void setFacultyInfo (string first, string last,
    		int idNumber, double salary);
    
    	//Function to print the name, ID number and salary.
    	void print () const;
    
    	//Constructor
    	faculty(string first="", string last="", int idNumber=0,
    		double salary=0);
    
    private:
    	static string peopleClass;
    	double facultySalary
    };
    
    string faculty::peopleClass = "Faculty";
    
    void faculty::setFacultyInfo (string first, string last, int idNumber,
    				double salary)
    {
    	//use allPeople class to set the first, last, and idNumber
    	allPeople::setNameInfo(first, last, idNumber);
    
    	personSalary = salary;
    }
    
    void faculty::print () const
    {
    	allPeople::print ();  //uses allPeople class to print name and ID
    	cout << "The classification of this person is " << peopleClass << "."
     <<endl;
    	cout << "The salary of this person is " << personSalary << "." <<
     endl;
    }
    
    faculty::faculty (string first, string last, int idNumber, double
     salary)
    
    	: allPeople (first, last, idNumber)
    {
    	personSalary = salary;
    }
    
    #endif
    staff.h
    Code:
    #ifndef H_Staff
    #define H_Staff
    
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include "allPeople"
    using namespace std;
    
    class staff: public allPeople
    {
    public:
    
    	//Function to set the staff information.
    	void setStaffInfo (string first, string last,
    		int idNumber, string empStatus);
    
    	//Function to print the name, ID number and status.
    	void print () const;
    
    	//Constructor
    	staff(string first="", string last="", int idNumber=0,
    		string="");
    
    private:
    	static string peopleClass;
    	string employmentStatus;
    };
    
    string staff::peopleClass = "Staff";
    
    void staff::setStaffInfo (string first, string last, int idNumber,
    						  string empStatus)
    {
    	//use allPeople class to set the first, last, and idNumber
    	allPeople::setNameInfo(first, last, idNumber);
    
    	employmentStatus = empStatus;
    }
    
    void staff::print () const
    {
    	allPeople::print ();  //uses allPeople class to print name and ID
    	cout << "The classification of this person is " << peopleClass << "."
     <<endl;
    	cout << "The status of this person is " << employeeStatus << "." <<
     endl;
    }
    
    staff::staff (string first, string last, int idNumber, string
     empStatus)
    
    	: allPeople (first, last, idNumber)
    {
    	employeeStatus = empStatus;
    }
    
    #endif
    test.cpp
    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    #include "student"
    #include "faculty"
    #include "staff"
    using namespace std;
    
    int main()
    {
    	//Program to test University Program.
    	cout << "This is a test for the University Program." << endl;
    	
    	//Testing for correct output based on test data.
    	cout << "Now testing for correct output based on test data." << endl;
    
    	cout << "Test for student data" << endl;
    	student studentTest ("Joan", "Doe", 1020202, "Full Time");
    	studentTest.print();
    	cout << endl;
    	
    	cout << "Test for staff data" << endl;
    	staff staffTest ("John", "Smith", 1000000, "Part Time");
    	staffTest.print();
    	cout << endl;
    
    	cout << "Test for faculty data" << endl;
    	faculty facultyTest ("Bob", "Jones", 3333333, 100000.00);
    	faculty.print();
    	cout << endl << endl << endl;
    
    	system ("pause");
    	return 0;
    }	//end main program

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    #include "student.h"
    Code:
    using namespace std; //don't do this in header files, it ruins it for the source files.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Same here:
    Code:
    #include "faculty.h"
    #include "staff.h"

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Only standard C++ headers are without the extension. If you save a file with an extension ".h", you need to mention it in the include directive.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Header file include order
    By cunnus88 in forum C++ Programming
    Replies: 6
    Last Post: 05-17-2006, 03:22 PM
  2. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  3. to #include or not to #include
    By krygen in forum C++ Programming
    Replies: 9
    Last Post: 12-25-2004, 12:06 AM
  4. Ghost in the CD Drive
    By Natase in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 10-12-2001, 05:38 PM