こんにちは、私はまだかなり新しいコーディングをしていますので、いくつかの猶予を与えていますが、基本的には構造体と関係するエラーがあります。記録。このオブジェクトをポインタにする必要があるかどうかはわかりません。なぜなら、プログラムをコンパイルするときにランタイムエラーが発生するためです。私は取得していますエラーは、「)(レコード::レコード」にポインタと継承を使用する構造体についてはわかりません
未定義の参照です
1dは
私はレコードへのポインタを使用するときに私が得るランタイムエラーを1つの終了ステータスを返しました従業員の構造は、最初の参照として発生します。
私はプログラムにはあまりコメントしていないので、私の説明です。それは基本的にクロックイン/クロックアウトプログラムです。 Dateクラスは自明です。シフトクラスはこれを実装し、従業員のクロックが入ったり出たりしたときに保持されます。 Recordsクラスは基本的に1週間分のシフトオブジェクトを保持し、この情報をスプレッドシートに書き込むために使用されます。
私が言ったように、プログラムの構造やソートの何かについてのヒントがあれば、私はそれらを聞きたいと思っています。
main.cppに
*
#include <iostream>
#include <cstdlib>
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <limits>
#include <fstream>
#include <ctime>
using namespace std;
#include "Date.h"
#include "Shift.h"
#include "Records.h"
bool AdminMenu(int id);
int EmployeeMenu(int id);
void printInfo(int id);
int findEmptySpot();
void addEmployee();
void printEmployeeList();
void generateEmployees();
void degenerateEmployees();
Date blankDate(1,1,1900,0,0);
struct employee{
string name;
bool adminStatus;
int id;
double wage;
Records r;
};
typedef struct employee Employee;
Employee data[100];
ifstream employeeList ("employeeList.txt");
int main()
{
bool x = true;
if (employeeList.is_open())
{
generateEmployees();
employeeList.close();
}
else
cout << "Unable to open file";
Sleep(1000);
while(x)
{
int input,i=0;
cout<< "Enter your 4 digit id: ";
cin>> input;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
std::system("cls");
while(data[i].id!=input)
i++;
;
if(data[i].adminStatus ==true)
x = AdminMenu(i);
else
EmployeeMenu(i);
}
employeeList.close();
degenerateEmployees();
return 0;
}
bool AdminMenu(int placeInArray)
{
while(true)
{
time_t now = time(0); // get current time
struct tm* tm = localtime(&now);
Date blankDate(1,1,1900,0,0);
Date currentDate(tm->tm_mon,tm->tm_mday,tm->tm_year,tm->tm_min,tm->tm_sec);
std::system("cls");
int input=0;
cout<<"You are in the admin menu\n1. Print My info\n2. Add Employee\n3. Edit Employee\n4. Delete Employee\n5. Print Employee List\n6. Clock In\n7. Clock Out\n8. Close Program\n9. Finish"<<endl;
cin>> input;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
if(input<1||input>9)
{
cout<< "Invalid input please try again"<<endl;
Sleep(1000);
std::system("cls");
}
else if(input==1)
{
std::system("cls");
printInfo(placeInArray);
getch();
std::system("cls");
}
else if(input ==2)
{
addEmployee();
}
else if (input ==3)
{
std::system("cls");
int placeToEdit, whatToEdit;
cout << "Please look at the list of employees below and enter the number of the employee you would like to edit";
printEmployeeList();
cin>> placeToEdit;
std::system("cls");
cout<< "What do you want to change? \n1. Name\n2. ID\n3. Admin Status\n4. Clock In/Out";
cin>> whatToEdit;
if(whatToEdit==1)
{
std::system("cls");
cout<<"Enter the employee's new name: ";
cin >> data[placeToEdit].name;
cout<< "\nEmployee's name adjusted successfully.";
Sleep(1000);
}
else if(whatToEdit==2)
{
std::system("cls");
cout<<"Enter the employee's new ID: ";
cin >> data[placeToEdit].id;
cout<< "\nEmployee's ID adjusted successfully.";
Sleep(1000);
}
else if(whatToEdit == 3)
{
std::system("cls");
cout<<"Enter the employee's new admin status: ";
cin >> data[placeToEdit].adminStatus;
cout<< "\nEmployee's Admin status adjusted successfully.";
Sleep(1000);
}
else if(whatToEdit == 4)
{
/* std::system("cls");
int status;
cout<<"Would you like to clock them in or out?(0 or 1)";
cin >> status;*/
}
else
{
std::system("cls");
cout<< "Error: invalid input. You will be returned to the admin menu";
Sleep(1000);
}
}
else if(input ==4)
{
std::system("cls");
int placeToEdit;
cout << "Please look at the list of employees below and enter the number of the employee you would like to delete";
printEmployeeList();
cin>> placeToEdit;
if(data[placeToEdit].id!= 0)
{
data[placeToEdit].name = '\0';
data[placeToEdit].id = '\0';
data[placeToEdit].adminStatus='\0';
cout<< "\nEmployee successfully deleted.";
Sleep(1000);
}
else
cout<< "Error: invalid input. You will be returned to the admin menu";
}
else if(input ==5)
{
printEmployeeList();
Sleep(1000);
}
else if (input == 6)
{
if(tm->tm_wday==1)
{
data[placeInArray].r.Monday.Shift::setBeginOFShift(blankDate);
}
else if(tm->tm_wday==2)
{
data[placeInArray].r.Tuesday.Shift::setBeginOFShift(blankDate);
}
else if(tm->tm_wday==3)
{
data[placeInArray].r.Wednesday.Shift::setBeginOFShift(blankDate);
}
else if(tm->tm_wday==4)
{
data[placeInArray].r.Thursday.Shift::setBeginOFShift(blankDate);
}
else if(tm->tm_wday==5)
{
data[placeInArray].r.Friday.Shift::setBeginOFShift(blankDate);
}
std::system("cls");
cout<< "Successfully clocked in at";
currentDate.Date::print();
}
else if (input == 7)
{
if(tm->tm_wday==1)
{
data[placeInArray].r.getMonday().setEndOFShift(currentDate);
}
else if(tm->tm_wday==2)
{
data[placeInArray].r.getTuesday().setEndOFShift(currentDate);
}
else if(tm->tm_wday==3)
{
data[placeInArray].r.getWednesday().setEndOFShift(currentDate);
}
else if(tm->tm_wday==4)
{
data[placeInArray].r.getThursday().setEndOFShift(currentDate);
}
else if(tm->tm_wday==5)
{
data[placeInArray].r.getFriday().setEndOFShift(currentDate);
}
}
else if(input ==8)
{
std::system("cls");
return false;
}
else if(input ==9)
{
std::system("cls");
return true;
}
}
}
int EmployeeMenu(int placeInArray)
{
int input;
while(true)
{
time_t now = time(0); // get current time
struct tm* tm = localtime(&now);
Date blankDate(1,1,1900,0,0);
Date currentDate(tm->tm_mon,tm->tm_mday,tm->tm_year,tm->tm_min,tm->tm_sec);
cout<< "You are in the Employee Menu\n1. Print My info\n2. Clock in\n3. Clock out\n9. Finish";
cin>> input;
std::system("cls");
if(input<1||input>9)
{
cout<< "Invalid input please try again"<<endl;
Sleep(1000);
std::system("cls");
}
else if(input==1)
printInfo(placeInArray);
else if (input == 2)
{
if(tm->tm_wday==1)
{
data[placeInArray].r.getMonday().setBeginOFShift(currentDate);
}
else if(tm->tm_wday==2)
{
data[placeInArray].r.getTuesday().setBeginOFShift(currentDate);
}
else if(tm->tm_wday==3)
{
data[placeInArray].r.getWednesday().setBeginOFShift(currentDate);
}
else if(tm->tm_wday==4)
{
data[placeInArray].r.getThursday().setBeginOFShift(currentDate);
}
else if(tm->tm_wday==5)
{
data[placeInArray].r.getFriday().setBeginOFShift(currentDate);
}
}
else if (input == 3)
{
if(tm->tm_wday==1)
{
data[placeInArray].r.getMonday().setEndOFShift(currentDate);
}
else if(tm->tm_wday==2)
{
data[placeInArray].r.getTuesday().setEndOFShift(currentDate);
}
else if(tm->tm_wday==3)
{
data[placeInArray].r.getWednesday().setEndOFShift(currentDate);
}
else if(tm->tm_wday==4)
{
data[placeInArray].r.getThursday().setEndOFShift(currentDate);
}
else if(tm->tm_wday==5)
{
data[placeInArray].r.getFriday().setEndOFShift(currentDate);
}
}
else if(input ==9)
{
std::system("cls");
return 0;
}
}
}
void printInfo(int placeInArray)
{
cout<<"Name: "<<data[placeInArray].name<<endl;
cout<<"ID: "<<data[placeInArray].id<<endl;
cout<<"Admin status: "<< data[placeInArray].adminStatus<<""<<endl;
}
int findEmptySpot()
{
int i=0;
while(data[i].id!=0)
i++;
return i;
}
void printEmployeeList()
{
int x;
for(x = 0; x<100; x++)
{
if(data[x].id!=0)
cout<<"\n"<<x<<". "<<data[x].name<<endl;
}
}
void addEmployee()
{
int newPlace = findEmptySpot();
std::system("cls");
cout<<" Enter the employee's name: ";
cin >> data[newPlace].name;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout<<" Enter the employee's ID: ";
cin >> data[newPlace].id;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout<<" Enter the employee's admin status: ";
cin >> data[newPlace].adminStatus;
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
std::system("cls");
cout<< "Your new employee profile has been created!";
printInfo(newPlace);
}
void generateEmployees()
{
string n;
bool a;
int i, j =0;
while (employeeList >>n>>i>>a)
{
data[j].name=n;
data[j].adminStatus=a;
data[j].id=i;
j++;
}
}
void degenerateEmployees()
{
ofstream employeeList("employeeList.txt",ios::trunc);
int x;
for(x = 0; x<100; ++x)
{
if(data[x].id!=0)
employeeList<< data[x].name<< " "<< data[x].id<< " "<< data[x].adminStatus<< "\n";``
}
employeeList<< "End 0 0";
employeeList.close();
}
*
Date.cpp
#include <iostream>
#include "Date.h" // include Date class definition
using namespace std;
// constructor confirms proper value for month; calls
// utility function checkDay to confirm proper value for day
//-------------------------------------------------------------
Date::Date(int mn, int dy, int yr, int hr, int minu)
{
month = mn;
year = yr;
day = dy ;
hour = hr;
minute=minu;
} // end Date constructor
Date::Date (const Date & dateToCopyFrom) // copy constructor
{
month = dateToCopyFrom.month;
day = dateToCopyFrom.day;
year = dateToCopyFrom.year;
hour = dateToCopyFrom.hour;
minute = dateToCopyFrom.minute;
}
Date & Date::operator = (const Date & other) // assignmenrt operator
{
this->month = other.month;
this->day = other.day;
this->year = other.year;
this->hour = other.hour;
this->minute= other.minute;
return *this;
}
/* setDate date from the user */
void Date::setDate()
{
bool flag = false;
int mn,dy,yr,hr,minu;
cin.clear();
do
{
cout << "(month day year hour minute):\n";
cin >> mn >> dy >> yr >> hr >> minu;
year = yr;
month = mn;
day = dy;
hour = hr;
minute=minu;
if(yr < 1900)
{
cout << "Cannot handle dates prior to 1900 AD" << endl;
cout << "Try again!" << endl;
flag = false;
}
else if(!isValidDate())
{
cout << "Invalid date" << endl;
cout << "Try again!" << endl;
flag = false;
}
else
flag = true;
}
while (!flag);
}//end date constructor
// print Date object in form month/day/year
//-------------------------------------------------------------
void Date::print() const
{
std::cout << hour<<":"<<minute<< "on"<< month << '/' << day << '/' << year;
} // end function print
// output Date object to show when its destructor is called
//-------------------------------------------------------------
Date::~Date()
{
} // end ~Date destructor
// utility function to confirm proper day value based on
// month and year; handles leap years, too
//-------------------------------------------------------------
int Date::checkDay(int testDay) const
{
static const int daysPerMonth[ monthsPerYear + 1 ] =
{ 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
// determine whether testDay is valid for specified month
if (testDay > 0 && testDay <= daysPerMonth[ month ])
return testDay;
// February 29 check for leap year
if (month == 2 && testDay == 29 && (year % 400 == 0 ||
(year % 4 == 0 && year % 100 != 0)))
return testDay;
std::cout << "Invalid day (" << testDay << ") set to 1.\n";
return 1; // leave object in consistent state if bad value
} // end function checkDay
bool Date::operator>(const Date &dateOnRight) // greater than operator
{
bool greater;
int year = dateOnRight.getYear();
if(dateOnRight.getYear() > year)
greater = false;
else if(dateOnRight.getYear() == year && dateOnRight.getMonth() > month)
greater = false;
else if(dateOnRight.getYear() == year && dateOnRight.getMonth() == month && dateOnRight.getDay() >= day)
greater = false;
else if(dateOnRight.getYear() == year && dateOnRight.getMonth() == month && dateOnRight.getDay() == day&& dateOnRight.getHour()>= hour)
greater = false;
else if(dateOnRight.getYear() == year && dateOnRight.getMonth() == month && dateOnRight.getDay() == day&& dateOnRight.getHour()== hour&& dateOnRight.getMinute()<= minute)
greater = false;
else
greater = true;
return greater;
}
// add one year to date
void Date::addYears(int nyears)
{
year = year + nyears;
//month = month;
if (day == 29 && !isLeapYear(year))
{
day = 28;
}//end if
}
/***********************************************/
bool Date::isLeapYear(int year)
{
bool leapYear = false;
if (year % 400 == 0)
{
leapYear = true;
}
else
{
if (year % 100 == 0)
{
leapYear = false;
}
else
{
if (year % 4 == 0)
leapYear = true;
else
leapYear = false;
}
}
// cout << "leapYear " << leapYear << endl;
return leapYear;
}
/************************************************/
bool Date::isValidDate()
{
bool validDate;
int monthDays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(month < 1 || month > 12
|| day < 0 || !((isLeapYear(year) && month == 2 && day <= 29)
|| (day <= monthDays[month - 1])))
validDate = false;
else
validDate = true;
// cout << "validDate " << validDate << endl;
return validDate;
}
Date.h
#ifndef DATE_H
#define DATE_H
class Date
{
public:
static const int monthsPerYear = 12; // number of months in a year
Date (int mn=1, int dy=1, int yr=1900, int hr=0, int minu =0); // constructors
Date (const Date& dateToCopyFrom); // copy constructor
Date & operator = (const Date & other); // assignmenrt operator
void setDate();
int getYear() const {return(year);};
int getMonth() const {return (month);};
int getDay() const {return (day);};
int getHour() const {return (hour);};
int getMinute() const {return (minute);};
void print() const; // print date in month/day/year format
bool operator>(const Date &dateOnRight);
void addYears(int nyears);
~Date(); // destructor provided to confirm destruction order
private:
int month; // 1-12 (January-December)
int day; // 1-31 based on month
int year; // any year
int hour;
int minute;
// utility function to check if day is proper for month and year
int checkDay(int testDay) const;
bool isLeapYear(int year);
bool isValidDate();
};
#endif
Shift.cpp
#ifndef DATE_H
#define DATE_H
class Date
{
public:
static const int monthsPerYear = 12; // number of months in a year
Date (int mn=1, int dy=1, int yr=1900, int hr=0, int minu =0); // constructors
Date (const Date& dateToCopyFrom); // copy constructor
Date & operator = (const Date & other); // assignmenrt operator
void setDate();
int getYear() const {return(year);};
int getMonth() const {return (month);};
int getDay() const {return (day);};
int getHour() const {return (hour);};
int getMinute() const {return (minute);};
void print() const; // print date in month/day/year format
bool operator>(const Date &dateOnRight);
void addYears(int nyears);
~Date(); // destructor provided to confirm destruction order
private:
int month; // 1-12 (January-December)
int day; // 1-31 based on month
int year; // any year
int hour;
int minute;
// utility function to check if day is proper for month and year
int checkDay(int testDay) const;
bool isLeapYear(int year);
bool isValidDate();
};
#endif
Shift.h
#include "Date.h"
#ifndef SHIFT_H
#define SHIFT_H
using namespace std;
class Shift: public Date
{
public:
//Constructor
Shift();//blankDate,blankDate,(9999),blankDate);
Shift(Date in, Date out, int identity){beginOfShift=in; endOfShift=out; ident = identity;};
void setBeginOFShift(Date x);
void setEndOFShift(Date x);
Date getBeginOfShift() const{return (beginOfShift);};
Date getEndOfShift() const{return (endOfShift);};
Date getLength();
int getID() const{return (ident);};
~Shift();
private:
Date beginOfShift;
Date endOfShift;
Date Length;
int ident;
};
#endif // SHIFT_H
Records.cpp
#include<iostream>
using namespace std;
#include "Records.h"
#include "Shift.h"
extern Date blankDate;
void Records::setBeginningOfWeek(Date x)
{
getBeginningOfWeek()=x;
}
void Records::setMonday(Shift x)
{
getMonday()=x;
}
void Records::setTuesday(Shift x)
{
getTuesday()=x;
}
void Records::setWednesday(Shift x)
{
getWednesday()=x;
}
void Records::setThursday(Shift x)
{
getThursday()=x;
}
void Records::setFriday(Shift x)
{
getFriday()=x;
}
Records::~Records()
{
}
Records.h
#include "Shift.h"
#ifndef RECORDS_H
#define RECORDS_H
using namespace std;
class Records: public Shift
{
public:
Records(Date x){beginningOfWeek=x;};
Records();
void setBeginningOfWeek(Date x);
void setMonday(Shift x);
void setTuesday(Shift x);
void setWednesday(Shift x);
void setThursday(Shift x);
void setFriday(Shift x);
Date getBeginningOfWeek() const{return(beginningOfWeek);};
Shift getMonday() const{return(Monday);};
Shift getTuesday() const{return(Tuesday);};
Shift getWednesday() const{return(Wednesday);};
Shift getThursday() const{return(Thursday);};
Shift getFriday() const{return(Friday);};
~Records();
Date beginningOfWeek;
Shift Monday;
Shift Tuesday;
Shift Wednesday;
Shift Thursday;
Shift Friday;
};
#endif // RECORDS_H
[最小、完全、および検証可能な例](http://stackoverflow.com/help/mcve)を入力してください。 –
エラーは実行時エラーではなくリンカーエラーです。リンカは 'Records'のコンストラクタを見つけることができません。おそらくあなたの.cppファイルにはありません。 –
あなたがしたことを見ていないと、間違いを推測するのは難しいです。あなたは同じエラーを生成する最小のコード例を提供できますか? – Galik