#include <iostream>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <conio.h>
#include <sstream>
#include <fstream>
#include <ctime>
#include <stdlib.h>
using namespace std;
int StringToNumber(string MyString)
{
istringstream converter(MyString);
int result;
converter >> result;
return result;
}
class Student
{
public:
string FirstName;
string LastName;
string time;
char ID;
char ch;
Student(string afirstname, string alastname, string atime, char aid) :
FirstName(afirstname), LastName(alastname), time(atime),
ID(aid) {}
};
class EnterName : public Student
{
public:
enum EnterNameType {};
EnterNameType Type;
EnterName(string afirstname, string alastname, EnterNameType atype, string atime,
char aid) : Type(atype),
Student(afirstname, alastname, atime, aid) {}
};
class EnterID
{
public:
Student *GetStudentFirstName(string FirstName);
Student *GetStudentLastName(string LastName);
};
class EnterPassword : public EnterID
{
public:
EnterID *GetStudentID(char ID);
};
string EnterOnlyNumbers()
{
const char BACKSPACE = '\b';
const char RETURN = '\r';
string numAsString = "";
char ch = getch();
while (ch != RETURN)
{
if (ch >= '0' && ch <= '9')
{
cout << '*';
numAsString += ch;
}
else if (ch == BACKSPACE)
{
if (numAsString.length() != 0)
{
cout << "\b \b";
numAsString.resize(numAsString.length() - 1);
}
}
ch = getch();
}
return numAsString;
}
int main()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [80]; //The first 5 lines are what i added today to make the time work.
time ( &rawtime ); //Where is says "char buffer [80]" is where the problem is i think.
timeinfo = localtime ( &rawtime );
string FirstName;
string LastName;
char ID[7]; //I think its conflicting with "char ID[7]".
bool done = false;
do {
strftime(buffer,80,"The current date and time is %I:%M%p %A, %B %d %Y.\n",timeinfo);
puts (buffer);
cout << "Please enter your name:\n" << endl;
cin >> FirstName >> LastName;
if ((FirstName == "Ryan" && LastName == "Batson"))
{
cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
string entered = EnterOnlyNumbers();
fgets(ID, sizeof(ID), stdin);
if( ID[strlen(ID) - 1] == 7) //This is where the problem occurs. Any amount of numbers i enter is rejected.
{
cout << "\nYou have successfully clocked in.\n" << endl;
}
else if( ID[strlen(ID) - 1] != 7)
{
cout << "\nPlease enter your 6 digit ID.\n" << endl;
}
ofstream myfile;
ostringstream filename;
filename << LastName << ", " << FirstName << ".txt";
myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
{
myfile << FirstName << " " << LastName << "\n";
myfile << ctime(&rawtime) << endl;
myfile.close();
}
}
if ((FirstName == "Adrien" && LastName == "Walls"))
{
cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
string entered = EnterOnlyNumbers();
fgets(ID, sizeof(ID), stdin);
if( ID[strlen(ID) - 1] == 7)
{
cout << "\nYou have successfully clocked in.\n" << endl;
}
else if( ID[strlen(ID) != 7])
{
cout << "\nPlease enter your 6 digit ID.\n" << endl;
}
ofstream myfile;
ostringstream filename;
filename << LastName << ", " << FirstName << ".txt";
myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
{
myfile << FirstName << " " << LastName << "\n";
myfile << ctime(&rawtime) << endl;
myfile.close();
}
}
if ((FirstName == "Philip" && LastName == "Anderson"))
{
cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
string entered = EnterOnlyNumbers();
fgets(ID, sizeof(ID), stdin);
if( ID[strlen(ID) - 1] == 7)
{
cout << "\nYou have successfully clocked in.\n" << endl;
}
else if( ID[strlen(ID) != 7])
{
cout << "\nPlease enter your 6 digit ID.\n" << endl;
}
ofstream myfile;
ostringstream filename;
filename << LastName << ", " << FirstName << ".txt";
myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
{
myfile << FirstName << " " << LastName << "\n";
myfile << ctime(&rawtime) << endl;
myfile.close();
}
}
if ((FirstName == "Jordan" && LastName == "Bergeria"))
{
cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
string entered = EnterOnlyNumbers();
fgets(ID, sizeof(ID), stdin);
if( ID[strlen(ID) - 1] == 7)
{
cout << "\nYou have successfully clocked in.\n" << endl;
}
else if( ID[strlen(ID) != 7])
{
cout << "\nPlease enter your 6 digit ID.\n" << endl;
}
ofstream myfile;
ostringstream filename;
filename << LastName << ", " << FirstName << ".txt";
myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
{
myfile << FirstName << " " << LastName << "\n";
myfile << ctime(&rawtime) << endl;
myfile.close();
}
}
if ((FirstName == "Neil" && LastName == "Dawes"))
{
cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
string entered = EnterOnlyNumbers();
fgets(ID, sizeof(ID), stdin);
if( ID[strlen(ID) - 1] == 7)
{
cout << "\nYou have successfully clocked in.\n" << endl;
}
else if( ID[strlen(ID) != 7])
{
cout << "\nPlease enter your 6 digit ID.\n" << endl;
}
ofstream myfile;
ostringstream filename;
filename << LastName << ", " << FirstName << ".txt";
myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
{
myfile << FirstName << " " << LastName << "\n";
myfile << ctime(&rawtime) << endl;
myfile.close();
}
}
if ((FirstName == "Erik" && LastName == "Baumgarten"))
{
cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
string entered = EnterOnlyNumbers();
fgets(ID, sizeof(ID), stdin);
if( ID[strlen(ID) - 1] == 7)
{
cout << "\nYou have successfully clocked in.\n" << endl;
}
else if( ID[strlen(ID) != 7])
{
cout << "\nPlease enter your 6 digit ID.\n" << endl;
}
ofstream myfile;
ostringstream filename;
filename << LastName << ", " << FirstName << ".txt";
myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
{
myfile << FirstName << " " << LastName << "\n";
myfile << ctime(&rawtime) << endl;
myfile.close();
}
}
if ((FirstName == "Sean" && LastName == "Campbell"))
{
cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
string entered = EnterOnlyNumbers();
fgets(ID, sizeof(ID), stdin);
if( ID[strlen(ID) - 1] == 7)
{
cout << "\nYou have successfully clocked in.\n" << endl;
}
else if( ID[strlen(ID) != 7])
{
cout << "\nPlease enter your 6 digit ID.\n" << endl;
}
ofstream myfile;
ostringstream filename;
filename << LastName << ", " << FirstName << ".txt";
myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
{
myfile << FirstName << " " << LastName << "\n";
myfile << ctime(&rawtime) << endl;
myfile.close();
}
}
if ((FirstName == "Sean-Thomas" && LastName == "Rowe"))
{
cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
string entered = EnterOnlyNumbers();
fgets(ID, sizeof(ID), stdin);
if( ID[strlen(ID) - 1] == 7)
{
cout << "\nYou have successfully clocked in.\n" << endl;
}
else if( ID[strlen(ID) != 7])
{
cout << "\nPlease enter your 6 digit ID.\n" << endl;
}
ofstream myfile;
ostringstream filename;
filename << LastName << ", " << FirstName << ".txt";
myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
{
myfile << FirstName << " " << LastName << "\n";
myfile << ctime(&rawtime) << endl;
myfile.close();
}
}
if ((FirstName == "Cody" && LastName == "Elston"))
{
cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
string entered = EnterOnlyNumbers();
fgets(ID, sizeof(ID), stdin);
if( ID[strlen(ID) - 1] == 7)
{
cout << "\nYou have successfully clocked in.\n" << endl;
}
else if( ID[strlen(ID) != 7])
{
cout << "\nPlease enter your 6 digit ID.\n" << endl;
}
ofstream myfile;
ostringstream filename;
filename << LastName << ", " << FirstName << ".txt";
myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
{
myfile << FirstName << " " << LastName << "\n";
myfile << ctime(&rawtime) << endl;
myfile.close();
}
}
if ((FirstName == "Scotty" && LastName == "Smith"))
{
cout << "\nOkay, " << FirstName << ", please enter your ID: \n" << endl;
string entered = EnterOnlyNumbers();
fgets(ID, sizeof(ID), stdin);
if( ID[strlen(ID) - 1] == 7)
{
cout << "\nYou have successfully clocked in.\n" << endl;
}
else if( ID[strlen(ID) != 7])
{
cout << "\nPlease enter your 6 digit ID.\n" << endl;
}
ofstream myfile;
ostringstream filename;
filename << LastName << ", " << FirstName << ".txt";
myfile.open(filename.str().c_str(), ios::in | ios::app | ios::out);
{
myfile << FirstName << " " << LastName << "\n";
myfile << ctime(&rawtime) << endl;
myfile.close();
}
}
system("PAUSE");
system("cls");
} while (!done);
return 0;
}
i should note that my class is not actually a programming class and i am teaching myself this on the side, so my code should be pretty rough around the edges (probably very rough). any advice is welcome.

New Topic/Question
Reply



MultiQuote











|