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!