Ok. Im making a login program mostly as practice with various c++ things, and when i tried to compile the code, it gave me one error I can't figure out. I use MSV C++ 6 for my compiler. This is the error:
error C2512: 'Students' : no appropriate default constructor available
The error points to this line:
Code:
Students *stdnt = new Students[100];//Students not logged in
And here is the full source. It's large so be warned. I tried to comment it well to make it easy to read.
Code:
// Login Program made for MCC
// For now DOS based
//
// Future features:
//
// 1)Saves data to textfile for backup purposes and
// informational purposes
//
// 2)Windows GUI
//
// 3)Log time students logged in
// Programed by:
// Justin Allen
// 02/27/2006
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
class Students
{
private:
char firstName[26];
char lastName[26];
int idNum;
public:
Students(char[26], char[26], int);
void showData();
void newStudent();
void login();
void logout();
void setData(char[26], char[26], int = 0);
};
//Constructor
Students::Students(char firstname[26], char lastname[26], int idnum)
{
firstName[26]=firstname[26];
lastName[26]=lastname[26];
idNum=idnum;
}
//Display data by admin
void Students::showData()
{
cout << lastName << " , " << firstName;
}
//Sets data inside class
void Students::setData(char firstname[26], char lastname[26], int idnum)
{
firstName[26]=firstname[26];
lastName[26]=lastname[26];
idNum=idnum;
}
//Main Function
int main()
{
//Variable declaration
int choice, count = 0, i;
int idnum, pwd;
const int PWD = 01103657;//'secret' password
char firstname[26];
char lastname[26];
//Pointer to new data structure in class
Students *stdnt = new Students[100];//Students not logged in
//Students *stdnt2 = new Students[100];//Student logged in
do//Infinite(for now) Menu Loop
{
//Main Menu
system("cls");//Clear screen
cout << "**** MCC COMPUTER LAB LOGON ****\n";
cout << " !!!PLEASE LOGIN!!! \n\n";
cout << "Please choose:\n";
cout << "1. Login\n";
cout << "2. Logout\n";
cout << "3. New Student\n";
cout << "Pleas note that you are a New Student if\n"
<< "this is your first time here this semester!!\n\n";
cin >> choice;//Enters menu choice
switch(choice)
{
case 1://Login student(not coded yet)
//stdnt[].login();
break;
case 2://Logout student(not coded yet)
//stdnt[].logout();
break;
case 3://Create new student
cout << "Type 'exit' if you mistakenly entered new student prompt\n";
cout << "Enter first name: ";
cin >> firstname;
if((stricmp(firstname, "exit") == 0))//checks for exit
{
break;
}
else//otherwise continues entering new student info
{
cout << "Enter last name: ";
cin >> lastname;
cout << "Enter ID number WITHOUT '@': ";
cin >> idnum;
}
//Calls setData function
stdnt[count].setData(firstname, lastname, idnum);
count++;
cout << "\n\n!!!Thanks for registering, please login now!!!";
system("pause");
break;
case 8://Hidden admin display data function
cout << "Enter password: ";
cin >> pwd;
if(pwd==PWD)//checks entered password
{
cout << "Students not logged in:n";
cout << "Last name, First name\n";
if(count==0)
{
cout << "There are no student records yet";
}
else
{
for(i=0; i<count; i++)
{
stdnt[i].showData();//shows Data
}
}
system("pause");
break;
}
else
{
cout << "Wrong password!!";
break;
}
default:
//Error Handling
cout << "\n\nError!! That option does not exist!!\n"
<< "Please enter new choice!";
system("pause");
break;
}
}while(1);
return 0;
}
Thanks in advance!