I have an assignment to submit tomorrow.
It gives me compiling errors. About 62 in VC++ 2008 and 42 in VC++ 6. I have written this code in one single file and it works fine there. One error that I can think of is with the declaration of class variable and n, flag values outside the main function. Because now I don't know to which file should I attach them. I mean.. In which file should I write them? The implementation file or the Client or is it the header file? The problem is that our Professor told us to write the code in three different files and then link them. One header file and two CPP files. So, It's like this..

//Header File-- MyAssignment.h

class StudentData
{
private:
    int regId, age;
    char name[30];
    char department[15];
    char degProg[10];

public:
    void createDatabase();
    void displayDatabase();
    int searchDatabase(int);
    void Exit();

};

//Implementation File-- MyAssignment.cpp

#include "MyAssignment.h"
#include <iostream>
const int size = 10;

//Functions Definitions

//Defining Create Database Function

void StudentData::createDatabase()
{
    cout<<"Enter Student Registration Number: ";
    cin.ignore(10,'\n');
    cin<<regId;
    cout<<"Enter Student's Name: ";
    cin.ignore(10, '\n');
    cin.get(name, 30, '\n');
    cout<<"Enter Student's age: ";
    cin.ignore(10,'\n');
    cin>>age;
    cout<<"Enter Department Name";
    cin.ignore(10,'\n');
    cin.get(department, 15, '\n');
    cout<<"Enter Degree Program";
    cin.get(degProg,10, '\n');
    cout<<endl;
}

//Definig Display Database Function

void StudentData::displayDatabase()
{
    cout<<"Reg #"<<setw(10)<<"Student Name"<<setw(30)<<"Age"<<setw(3)<<"Department Name"<<setw(15)<<"Program Degree"<<setw(10)<<endl;
    for (int i=10; i<=10; i++)
        cout<<student[i].regId<<setw(10)<<student[i].name<<setw(30)<<student[i].age<<setw(3)<<student[i].department<<setw(15)<<student[i].degProg<<setw(10)<<endl;
}

//Defining Search Function

int StudentData::searchDatabase(int studentNo)
{
    if (studentNo == regId)
    {
        cout<<"Student Registration Number is "<<regId<<endl;
        cout<<"Student Name is "<<name<<endl;
        cout<<"Student Age is "<<age<<endl;
        cout<<"Student Department is "<<department<<endl;
        cout<<"Student Degree Program is "<<degProg<<endl;
    }
    else 
    {
        cout<<"Data not Found!"<<endl;
    }
    return 0;
    cout<<endl;
}

//Defining Exit Function

void StudentData::Exit()
{
    exit(1);
}

//Client File -- Test.cpp

#include <iostream>
#include "MyAssignment.h"
#include <iomanip>
using namespace std;
const int size=10;

StudentData student[size];
int n=0;

int main()
{



    int option, studentNo;
    char choice;

    do 
    {
        cout<<"Select option below"<<endl;
        cout<<"1.Create Database"<<"\n2.Display Database"<<"\n3.Search Database"<<"\n4.Exit"<<endl;
        cout<<"Give your choice: ";
        cin>>option;
        cout<<"Enter Required Information"<<endl;
        switch(option)
        {
        case 1:
            cout<<"Enter number of students in class: ";
            cin>>n;
            for(int i=0; i<n; i++)
                student[i].createDatabase();
            break;
        case 2:
            student[size].displayDatabase();
            break;
        case 3:
            cout<<"Enter Student Registration ID to search data."<<endl;
            cin>>studentNo;
            for(int i=0; i<n; i++)
                student[i].searchDatabase(studentNo);
            break;
        case 4:
            student[size].Exit();
            break;
        default:
            cout<<"You've entered wrong choice."<<endl;
        }
        cout<<"Do you want to Continue?"<<endl;
        cout<<"Press Y for Yes and N for No"<<endl;
        cin>>choice;
    }while (choice=='Y'||'y');
    return 0;
}


//Any help shall be appreciated! Thank you in advance!

You need to do 2 things

1> Post the exact error messages here
2> Use code tags for re-posting your code so that it can be easily read.

I made few changes to the code and then the errors reduced to 56. The changes were addition of "#ifndef, #define and #endif" to the header file.

------ Build started: Project: MyAssignment, Configuration: Debug Win32 ------
Compiling...
MyAssignment.cpp
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(9) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(10) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(10) : error C2228: left of '.ignore' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(11) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(12) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(13) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(13) : error C2228: left of '.ignore' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(14) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(14) : error C2228: left of '.get' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(15) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(16) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(16) : error C2228: left of '.ignore' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(17) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(18) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(19) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(19) : error C2228: left of '.ignore' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(20) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(20) : error C2228: left of '.get' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(21) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(22) : error C2065: 'cin' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(22) : error C2228: left of '.get' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(23) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(23) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(30) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(30) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(30) : error C3861: 'setw': identifier not found
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(30) : error C3861: 'setw': identifier not found
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(30) : error C3861: 'setw': identifier not found
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(30) : error C3861: 'setw': identifier not found
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(30) : error C3861: 'setw': identifier not found
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(32) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(32) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(32) : error C3861: 'setw': identifier not found
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(32) : error C3861: 'setw': identifier not found
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(32) : error C3861: 'setw': identifier not found
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(32) : error C3861: 'setw': identifier not found
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(32) : error C3861: 'setw': identifier not found
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(41) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(41) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(42) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(42) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(43) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(43) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(44) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(44) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(45) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(45) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(49) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(49) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(52) : error C2065: 'cout' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(52) : error C2065: 'endl' : undeclared identifier
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.cpp(59) : error C3861: 'exit': identifier not found
Test.cpp
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\test.cpp(6) : error C2370: 'size' : redefinition; different storage class
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.h(17) : see declaration of 'size'
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\test.cpp(7) : error C2369: 'student' : redefinition; different subscripts
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.h(18) : see declaration of 'student'
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\test.cpp(8) : error C2374: 'n' : redefinition; multiple initialization
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\myassignment.h(19) : see declaration of 'n'
c:\documents and settings\xcruiser\my documents\visual studio 2008\projects\myassignment\myassignment\test.cpp(26) : error C2088: '>>' : illegal for class
Generating Code...
Build log was saved at "file://c:\Documents and Settings\xCruiser\My Documents\Visual Studio 2008\Projects\MyAssignment\MyAssignment\Debug\BuildLog.htm"
MyAssignment - 56 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Your implementation file needs the 'using namespace std' declaration.

That didn't work fine. Made errors 57. Can you please tell me how to declare the global variables. I mean in which file should I type them? They seem to be the problem to me.

Global variables are defined in a header file (so that various cpp files that include it can see it). Setw is defined in iomanip so this must be included where needed. Also, you are trying to use an array of your class in the implementation (student) without declaring it or defining it.
Declaration so that a file can 'see' the variable (such as student[]), as well as simple definition goes in a header file. The code to set up the student[] array with meaningful information goes in a cpp file.
At one point you have a genuine case of a simple mistake, using the << operator with cin (MyAssignment.cpp file).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.