Вы находитесь на странице: 1из 3

const int MAX_STRING_LEN = 100;

const int monthDays[12] = {31, 28, 31, 30, 31, 30,


31, 31, 30, 31, 30, 31};
class Date {
public:
void getDate();
void showDate();
private:
int month, day, year;
};

void Date:: getDate() {


cout << "Please enter the date as per instructions" << endl;
cout << "Please enter the day(dd format)" << endl;
cout << "Please enter the month(mm format)" <<endl;
cout << "Please enter the year(yyyy format)" << endl;
cin >> day >> month >> year;

void Date:: showDate() {


cout << "The date format is dd-mm-yyyy" << endl;
cout << day << "-" << month << "-" << year;
}

class ProductComplaintDetails {
public:
void getProductDetails();
void showProductDetails();
ProductComplaintDetails* next;
private:
char prodName[MAX_STRING_LEN];
double prodID;
double prodPrice;
char customerName[MAX_STRING_LEN];
int customerDissatisfactionRating;
Date dateToday;
Date complaintFiling;
int daysSinceActionDue;
int urgencyOfAction;
int calcDifference(Date dt1, Date dt2);
int countLeapYears(Date dt);
};

void ProductComplaintDetails::getProductDetails() {
cout << "Please follow the given instructions to enter product complaint
details" << endl;
cout << "Enter customer name" << endl;
gets(customerName);
cout << "Enter product name" << endl;
gets(prodName);
cout << "Enter product ID" << endl;
cin >> prodID;
cout << "Enter product price" << endl;
cin >> prodPrice;
cout << "Please rate customer's dissatisfaction with the product on a scale of
1-10" << endl;
cin >> customerDissatisfactionRating;
cout << "Enter the date when customer file the complaint" << endl;
complaintFiling.getDate();
cout << "Enter today's date" << endl;
dateToday.getDate();
daysSinceActionDue = calcDifference(complaintFiling, dateToday);
urgencyOfAction = daysSinceActionDue + customerDissatisfactionRating;
}

void ProductComplaintDetails::showProductDetails() {
cout << "Customer name: ";
puts(customerName);
cout << endl;
cout << "Product name: ";
puts(prodName);
cout << endl;
cout << "Product ID: " << prodID << endl;
cout << "Product Price: " << prodPrice << endl;
cout << "Customer dissatisfaction rating: " << customerDissatisfactionRating <<
endl;
cout << "Urgency of action: " << urgencyOfAction << endl;
cout << "Date of complaint filing by customer: " << endl;
complaintFiling.showDate();
cout << "Date of complaint updation in database: " << endl;
dateToday.showDate();
}

int ProductComplaintDetails::calcDifference(Date dt1, Date dt2){


// COUNT TOTAL NUMBER OF DAYS BEFORE FIRST DATE 'dt1'

// initialize count using years and day


long int numberOfDaysBeforeDate1 = dt1.year*365 + dt1.day;

// Add days for months in given date


for (int i = 0; i < dt1.month - 1; ++i) {
numberOfDaysBeforeDate1 += monthDays[i];
}

// Since every leap year is of 366 days,


// Add a day for every leap year
numberOfDaysBeforeDate1 += countLeapYears(dt1);

// SIMILARLY, COUNT TOTAL NUMBER OF DAYS BEFORE 'dt2'

long int numberOfDaysBeforeDate2 = dt2.year*365 + dt2.day;


for (int i = 0; i < dt2.month - 1; ++i) {
numberOfDaysBeforeDate2 += monthDays[i];
}

numberOfDaysBeforeDate2 += countLeapYears(dt2);

// return difference between two counts


return (numberOfDaysBeforeDate1 - numberOfDaysBeforeDate2);

int ProductComplaintDetails::countLeapYears(Date dt) {


int years = dt.year;

// Check if the current year needs to be considered


// for the count of leap years or not
if (dt.month <= 2)
years--;

// An year is a leap year if it is a multiple of 4,


// multiple of 400 and not a multiple of 100.
return (years / 4 - years / 100 + years / 400);
}

class complaintFileDatabase {
public:
complaintFileDatabase();
~complaintFileDatabase();
void writeToFile();
void showFile();
void searchUsingId();
void searchhUsingProdName();

private:
fstream fin, fout;
}

Вам также может понравиться