08 - Algorithms & Problem Solving Level 4
08 - Algorithms & Problem Solving Level 4
int main() {
long long Number = ReadNumber();
cout << NumberToText(Number);
system("pause>0");
return 0; }
Problem #02
الحل
#include<iostream>
using namespace std;
short ReadYear() {
short Year;
cout << "\nPlease enter a year to check? ";
cin >> Year;
return Year; }
int main() {
short Year = ReadYear();
if (IsLeapYear(Year))
cout << "\nYes, Year [" << Year << "] is a leap year.\n";
else
cout << "\nNo, Year [" << Year << "] is NOT a leap year.\n";
system("pause>0"); return 0; }
Problem #03
الحل
#include<iostream>
using namespace std;
short ReadYear() {
short Year;
cout << "\nPlease enter a year to check? ";
cin >> Year;
return Year; }
int main() {
short Year = ReadYear();
if (isLeapYear(Year))
cout << "\nYes, Year [" << Year << "] is a leap year.\n";
else
cout << "\nNo, Year [" << Year << "] is NOT a leap year.\n";
system("pause>0"); return 0; }
Problem #04
لوحدهاfunction اعمل كل سطر في
الحل
#include<iostream>
using namespace std;
int main() {
short Year = ReadYear();
cout << "\nNumber of Days in Year [" << Year << "] is "
<< NumberOfDaysInAYear(Year);
cout << "\nNumber of Hours in Year [" << Year << "] is "
<< NumberOfHoursInAYear(Year);
cout << "\nNumber of Minutes in Year [" << Year << "] is "
<< NumberOfMinutesInAYear(Year);
cout << "\nNumber of Seconds in Year [" << Year << "] is "
<< NumberOfSecondsInAYear(Year);
system("pause>0"); return 0; }
Problem #05
الحل
#include<iostream>
using namespace std;
short ReadMonth() {
short Month;
cout << "\nPlease enter a Month to check? ";
cin >> Month;
return Month; }
short ReadYear() {
short Year;
cout << "\nPlease enter a year to check? ";
cin >> Year;
return Year; }
int main() {
short Year = ReadYear();
short Month = ReadMonth();
cout << "\nNumber of Days in Month [" << Month << "] is " << NumberOfDaysInAMonth(Month, Year);
cout << "\nNumber of Hours in Month [" << Month << "] is " << NumberOfHoursInAMonth(Month, Year);
cout << "\nNumber of Minutes in Month [" << Month << "] is " << NumberOfMinutesInAMonth(Month, Year);
cout << "\nNumber of Seconds in Month [" << Month << "] is " << NumberOfSecondsInAMonth(Month, Year);
system("pause>0"); return 0; }
Problem #06
الحل
#include<iostream>
using namespace std;
short ReadMonth() {
short Month;
cout << "\nPlease enter a Month to check? ";
cin >> Month;
return Month; }
short ReadYear() {
short Year;
cout << "\nPlease enter a year to check? ";
cin >> Year;
return Year; }
int main() {
short Year = ReadYear();
short Month = ReadMonth();
cout << "\nNumber of Days in Month [" << Month << "] is " << NumberOfDaysInAMonth(Month, Year);
system("pause>0");
return 0; }
Problem #07
الحل
#include<iostream>
using namespace std;
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "\nPlease enter a Month? ";
cin >> Month;
return Month; }
short ReadYear() {
short Year;
cout << "\nPlease enter a year? ";
cin >> Year;
return Year; }
int main() {
short Year = ReadYear();
short Month = ReadMonth();
short Day = ReadDay();
cout << "\nDate :" << Day << "/" << Month << "/" << Year;
cout << "\nDay Order : " << DayOfWeekOrder(Day, Month, Year);
cout << "\nDay Name : " << DayShortName(DayOfWeekOrder(Day, Month, Year));
system("pause>0");
return 0; }
Problem #08
الحل
#include<iostream>
using namespace std;
if (++i == 7){
i = 0;
printf("\n");}}
printf("\n _________________________________\n");
}
short ReadMonth() {
short Month;
cout << "\nPlease enter a Month? ";
cin >> Month;
return Month; }
short ReadYear() {
short Year;
cout << "\nPlease enter a year? ";
cin >> Year;
return Year; }
int main() {
short Year = ReadYear();
short Month = ReadMonth();
PrintMonthCalendar(Month, Year);
system("pause>0"); return 0; }
if (i>=StartingDay+1&&Counter<=NumberOfDays-1) {
Counter++;
cout << " " <<setw(3)<< Counter;
}
else { cout << " "; }
if (i % 7 == 0) { cout << endl; }
}
cout << "\n _________________________________\n\n";
}
Problem #09
الحل
#include<iostream>
using namespace std;
// Gregorian:
//0:sun, 1:Mon, 2:Tue...etc
return (Day + y + (y / 4) - (y / 100) + (y / 400) + ((31 * m) / 12)) % 7; }
short ReadYear() {
short Year;
cout << "\nPlease enter a year? ";
cin >> Year;
return Year; }
int main() {
PrintYearCalendar(ReadYear());
system("pause>0"); return 0; }
Problem #10
الحل
#include<iostream>
using namespace std;
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day; }
short ReadMonth() {
short Month;
cout << "\nPlease enter a Month? ";
cin >> Month;
return Month; }
short ReadYear() {
short Year;
cout << "\nPlease enter a Year? ";
cin >> Year;
return Year; }
int main() {
short Day = ReadDay();
short Month = ReadMonth();
short Year = ReadYear();
cout << "\nNumber of Days from the begining of the year is "
<< NumberOfDaysFromTheBeginingOfTheYear(Day, Month, Year);
system("pause>0"); return 0; }
Problem #11
الحل
#include<iostream>
using namespace std;
while (true) {
MonthDays = NumberOfDaysInAMonth(Date.Month, Year);
if (RemainingDays > MonthDays) {
RemainingDays -= MonthDays;
Date.Month++; }
else {
Date.Day = RemainingDays;
break; } }
return Date; }
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day; }
short ReadMonth() {
short Month;
cout << "\nPlease enter a Month? ";
cin >> Month;
return Month; }
short ReadYear() {
short Year;
cout << "\nPlease enter a Year? ";
cin >> Year;
return Year; }
int main() {
short Day = ReadDay();
short Month = ReadMonth();
short Year = ReadYear();
short DaysOrderInYear = NumberOfDaysFromTheBeginingOfTheYear(Day, Month, Year);
cout << "\nNumber of Days from the begining of the year is " << DaysOrderInYear << "\n\n";
sDate Date;
Date = GetDateFromDayOrderInYear(DaysOrderInYear, Year);
cout << "Date for [" << DaysOrderInYear << "] is: ";
cout << Date.Day << "/" << Date.Month << "/" << Date.Year;
system("pause>0"); return 0; }
Problem #12
الحل
#include<iostream>
using namespace std;
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "\nPlease enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "\nPlease enter a Year? ";
cin >> Year;
return Year;
}
sDate ReadFullDate() {
sDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
short ReadDaysToAdd() {
short Days;
cout << "\nHow many days to add? ";
cin >> Days;
return Days;
}
int main() {
sDate Date = ReadFullDate();
short Days = ReadDaysToAdd();
Date = DateAddDays(Days, Date);
cout << "\nDate after adding [" << Days << "] days is: ";
cout << Date.Day << "/" << Date.Month << "/" << Date.Year;
system("pause>0");
return 0;
}
Problem #13
الحل
#include<iostream>
using namespace std;
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
int main() {
stDate Date1 = ReadFullDate();
stDate Date2 = ReadFullDate();
if (IsDate1BeforeDate2(Date1, Date2))
cout << "\nYes, Date1 is Less than Date2.";
else
cout << "\nNo, Date1 is NOT Less than Date2.";
system("pause>0"); return 0;
}
Problem #14
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
bool IsDate1EqualDate2(stDate Date1, stDate Date2) {
return (Date1.Year == Date2.Year) ? ((Date1.Month == Date2.Month) ? ((Date1.Day == Date2.Day) ? true : false) : false)
: false;
} short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
} short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
} short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
} int main() {
stDate Date1 = ReadFullDate();
stDate Date2 = ReadFullDate();
if (IsDate1EqualDate2(Date1, Date2))
cout << "\nYes, Date1 is Equal To Date2.";
else
cout << "\nNo, Date1 is NOT Equal To Date2.";
system("pause>0");
return 0;
}
Problem #15
الحل
#include<iostream>
using namespace std;
struct stDate {
short Year;
short Month;
short Day;
};
bool isLeapYear(short Year) {
return (Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0);
} short NumberOfDaysInAMonth(short Month, short Year) {
if (Month < 1 || Month>12) return 0;
int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
return (Month == 2) ? (isLeapYear(Year) ? 29 : 28) : days[Month - 1];
} bool IsLastDayInMonth(stDate Date) {
return (Date.Day == NumberOfDaysInAMonth(Date.Month, Date.Year));
} bool IsLastMonthInYear(short Month) {
return (Month == 12);
} short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
int main() {
stDate Date1 = ReadFullDate();
if (IsLastDayInMonth(Date1))
cout << "\nYes, Day is Last Day in Month.";
else
cout << "\nNo, Day is Not Last Day in Month.";
if (IsLastMonthInYear(Date1.Month))
cout << "\nYes, Month is Last Month in Year.";
else
cout << "\nNo, Month is Not Last Month in Year.";
system("pause>0");
return 0;
}
Problem #16
} short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
} short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
} short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
int main() {
stDate Date1 = ReadFullDate();
Date1 = IncreaseDateByOneDay(Date1);
cout << "\nDate after adding one day is:" << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
system("pause>0");
return 0;
}
Problem #17
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
int main() {
stDate Date1 = ReadFullDate();
stDate Date2 = ReadFullDate();
cout << "\nDiffrence is: " << GetDifferenceInDays(Date1, Date2) << " Day(s).";
cout << "\nDiffrence (Including End Day) is: " << GetDifferenceInDays(Date1, Date2, true) << " Day(s).";
system("pause>0");
return 0;
}
حلي باختصار انه الفرق هيكون مجموع عدد االيام بكل سنه بداية من سنه التاريخ االول الي سنة التاريخ الثاني وبعدين نطرح منهم عدد االيام من
بدايه السنه بتاعت التاريخ الثاني وعدد االيام بداية من التاريخ االول لحد ااخر سنة التاريخ االول انا فكرت في نفس حله بس قولت افرض اليوزر
مره365000 سنه كده هيفضل يلف اكتر من1000 عاوز يجيب الفرق من
if (IsDate1BeforeDate2(Date1, Date2)) {
return DifferenceInDays;
}
Problem #18
الحل
#pragma warning(disable : 4996)
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
bool isLeapYear(short Year) {
return (Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0);
}
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
stDate GetSystemDate() {
stDate Date;
time_t t = time(0);
tm* now = localtime(&t);
Date.Year = now->tm_year + 1900;
Date.Month = now->tm_mon + 1;
Date.Day = now->tm_mday;
return Date;
}
int main() {
cout << "\nPlease Enter Your Date of Birth:\n";
stDate Date1 = ReadFullDate();
stDate Date2 = GetSystemDate();
cout << "\nYour Age is : " << GetDifferenceInDays(Date1, Date2, true) << " Day(s).";
system("pause>0");
return 0;
}
Problem #19
بيقولك عاوز لما اليوزر يدخل التاريخ التاني اقل من التاريخ األول يطلع الفرق بالسالب
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
bool isLeapYear(short Year) {
return (Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0);
}
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
} int main() {
stDate Date1 = ReadFullDate();
stDate Date2 = ReadFullDate();
cout << "\nDiffrence is: " << GetDifferenceInDays(Date1, Date2) << " Day(s).";
cout << "\nDiffrence (Including End Day) is: " << GetDifferenceInDays(Date1, Date2, true) << " Day(s).";
system("pause>0");
return 0;
}
recursion الحل بتاعي عن طريق ال
int DifferenceBetween2Dates(stDate Date1, stDate Date2, bool IncludeEndDay = false) {
int DifferenceInDays = 0;
short NumberOfDaysRemaningOfTheYearOfDate2 = NumberOfDaysInAYear(Date2.Year) -
NumberOfDaysFromBeginningOfTheYear(Date2.Day, Date2.Month, Date2.Year);
if (IsDate1BeforeDate2(Date1, Date2)) {
return (IncludeEndDay)?++DifferenceInDays:DifferenceInDays;
}
Problem #20:32
بتعمل داله بتضيف يوم او أسبوع واحد وبعدين بتستخدمها عشان تضيف ال xاللي جاي من اليوزر
يعني تعمل داله تضيف يوم واحد وداله تانيه تشغلها بال for loopيعني رقم اتنين في الحل بيستخدم رقم واحد
for loop هوا مش عايزfasterلما توصل لل
الحل
#include<iostream>
using namespace std;
struct stDate{ short Year;
short Month;
short Day;
};
bool isLeapYear(short Year) {
return (Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0);
}
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
int main() {
stDate Date1 = ReadFullDate();
cout << "\nDate After: \n";
Date1 = IncreaseDateByOneDay(Date1);
cout << "\n01-Adding one day is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByXDays(10, Date1);
cout << "\n02-Adding 10 days is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByOneWeek(Date1);
cout << "\n03-Adding one week is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByXWeeks(10, Date1);
cout << "\n04-Adding 10 weeks is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByOneMonth(Date1);
cout << "\n05-Adding one month is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByXMonths(5, Date1);
cout << "\n06-Adding 5 months is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByOneYear(Date1);
cout << "\n07-Adding one year is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByXYears(10, Date1);
cout << "\n08-Adding 10 Years is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByXYearsFaster(10, Date1);
cout << "\n09-Adding 10 Years (faster) is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByOneDecade(Date1);
cout << "\n10-Adding one Decade is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByXDecades(10, Date1);
cout << "\n11-Adding 10 Decades is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByXDecadesFaster(10, Date1);
cout << "\n12-Adding 10 Decade (faster) is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByOneCentury(Date1);
cout << "\n13-Adding One Century is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
Date1 = IncreaseDateByOneMillennium(Date1);
cout << "\n14-Adding One Millennium is: " << Date1.Day << "/" << Date1.Month << "/" << Date1.Year;
system("pause>0");
return 0;
}
Problem #33:46
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
Problem #74:53
اللي احناstructure اعمل نفس الداله بس المرادي بتاخد ال: احنا كنا عاملين داله بتاخد يوم وشهر وسنه عشان تجيبلنا ترتيب اليوم في األسبوع
عاملينه
الحل
#pragma warning(disable : 4996)
#include<iostream>
using namespace std; struct stDate{ short Year;
short Month;
short Day;
};
bool isLeapYear(short Year) {
return (Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0);
}
bool IsDate1BeforeDate2(stDate Date1, stDate Date2) {
return (Date1.Year < Date2.Year) ? true : ((Date1.Year == Date2.Year) ? (Date1.Month < Date2.Month ? true :
(Date1.Month == Date2.Month ? Date1.Day < Date2.Day : false)) : false);
}
short NumberOfDaysInAMonth(short Month, short Year) {
if (Month < 1 || Month>12) return 0;
int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };
return (Month == 2) ? (isLeapYear(Year) ? 29 : 28) : days[Month - 1];
}
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
stDate GetSystemDate() {
stDate Date;
time_t t = time(0);
tm* now = localtime(&t);
Date.Year = now->tm_year + 1900;
Date.Month = now->tm_mon + 1;
Date.Day = now->tm_mday;
return Date;
}
int main() {
stDate Date1 = GetSystemDate();
cout << "\nToday is " << DayShortName(DayOfWeekOrder(Date1)) << " , " << Date1.Day << "/" << Date1.Month <<
"/" << Date1.Year << endl;
//--------------------- cout << "\nIs it End of Week?\n";
if (IsEndOfWeek(Date1)) cout << "Yes it is Saturday, it's of Week.";
else cout << "No it's Not end of week.";
//--------------------- cout << "\n\nIs it Weekend?\n";
if (IsWeekEnd(Date1)) cout << "Yes it is a week end.";
else cout << "No today is " << DayShortName(DayOfWeekOrder(Date1)) << ", Not a weekend.";
//--------------------- cout << "\n\nIs it Business Day?\n";
if (IsBusinessDay(Date1)) cout << "Yes it is a business day.";
else cout << "No it is NOT a business day.";
//--------------------- cout << "\n\nDays until end of week : " << DaysUntilTheEndOfWeek(Date1) << " Day(s).";
//--------------------- cout << "\nDays until end of month : "<< DaysUntilTheEndOfMonth(Date1) << " Day(s).";
//--------------------- cout << "\nDays until end of year : " << DaysUntilTheEndOfYear(Date1) << " Day(s).";
system("pause>0");
return 0;
}
Problem #54
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
short CalculateVacationDays(stDate DateFrom, stDate DateTo) {
short DaysCount = 0;
while (IsDate1BeforeDate2(DateFrom, DateTo)) {
if (IsBusinessDay(DateFrom)) DaysCount++;
DateFrom = IncreaseDateByOneDay(DateFrom);
}
return DaysCount;
}
int main() {
cout << "\nVacation Starts: ";
stDate DateFrom = ReadFullDate();
cout << "\nVacation Ends: ";
stDate DateTo = ReadFullDate();
cout << "\nVaction From: " << DayShortName(DayOfWeekOrder(DateFrom)) << " , " << DateFrom.Day << "/" <<
DateFrom.Month << "/" << DateFrom.Year << endl;
cout << "Vaction To: " << DayShortName(DayOfWeekOrder(DateTo)) << " , " << DateTo.Day << "/" << DateTo.Month
<< "/" << DateTo.Year << endl;
cout << "\n\nActucal Vacation Days is: " << CalculateVacationDays(DateFrom, DateTo);
system("pause>0");
return 0;
}
Problem #55
الحل
#include <iostream>
using namespace std;
struct stDate
{
short Year;
short Month;
short Day;
};
return Date;
}
return arrDayNames[DayOfWeekOrder];
/*
short DayIndex = DayOfWeekOrder(Date.Day, Date.Month, Date.Year);
return (DayIndex >= 5 && DayIndex <= 4);
*/
//shorter method is to invert the IsWeekEnd: this will save updating code.
return !IsWeekEnd(Date);
short ReadDay()
{
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth()
{
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear()
{
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate()
{
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
short WeekEndCounter = 0;
//in case the data is weekend keep adding one day util you reach business day
//we get rid of all weekends before the first business day
while (IsWeekEnd(DateFrom))
{
DateFrom = IncreaseDateByOneDay(DateFrom);
}
DateFrom = IncreaseDateByOneDay(DateFrom);
}
//in case the return date is week end keep adding one day util you reach business day
while (IsWeekEnd(DateFrom))
{
DateFrom = IncreaseDateByOneDay(DateFrom);
}
return DateFrom;
}
short ReadVacationDays()
{
short Days;
cout << "\nPlease enter vacation days? ";
cin >> Days;
return Days;
}
int main()
{
cout << "\nVacation Starts: ";
stDate DateFrom = ReadFullDate();
cout << "\n\nReturn Date: " << DayShortName(DayOfWeekOrder(ReturnDate)) << " , "
<< ReturnDate.Day << "/" << ReturnDate.Month << "/" << ReturnDate.Year << endl;
system("pause>0");
return 0;
}
Problem #56
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
}
;
bool IsDate1BeforeDate2(stDate Date1, stDate Date2) {
return (Date1.Year < Date2.Year) ? true : ((Date1.Year == Date2.Year) ? (Date1.Month < Date2.Month ? true :
(Date1.Month == Date2.Month ? Date1.Day < Date2.Day : false)) : false);
}
bool IsDate1EqualDate2(stDate Date1, stDate Date2) {
return (Date1.Year == Date2.Year) ? ((Date1.Month == Date2.Month) ? ((Date1.Day == Date2.Day) ? true : false) : false)
: false;
}
bool IsDate1AfterDate2(stDate Date1, stDate Date2) {
return (!IsDate1BeforeDate2(Date1, Date2) && !IsDate1EqualDate2(Date1, Date2));
}
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
int main() {
cout << "\nEnter Date1:";
stDate Date1 = ReadFullDate();
cout << "\nEnter Date2:";
stDate Date2 = ReadFullDate();
if (IsDate1AfterDate2(Date1, Date2)) cout << "\nYes, Date1 is After Date2.";
else cout << "\nNo, Date1 is NOT After Date2.";
system("pause>0");
return 0;
}
Problem #57
الحل
#include<iostream>
using namespace std;
struct stDate{ short Year;
short Month;
short Day;
}
;
bool IsDate1BeforeDate2(stDate Date1, stDate Date2) {
return (Date1.Year < Date2.Year) ? true : ((Date1.Year == Date2.Year) ? (Date1.Month < Date2.Month ? true :
(Date1.Month == Date2.Month ? Date1.Day < Date2.Day : false)) : false);
}
bool IsDate1EqualDate2(stDate Date1, stDate Date2) {
return (Date1.Year == Date2.Year) ? ((Date1.Month == Date2.Month) ? ((Date1.Day == Date2.Day) ? true : false) : false)
: false;
}
bool IsDate1AfterDate2(stDate Date1, stDate Date2) {
return (!IsDate1BeforeDate2(Date1, Date2) && !IsDate1EqualDate2(Date1, Date2));
}
enum enDateCompare{ Before = -1, Equal = 0, After = 1 }
;
enDateCompare CompareDates(stDate Date1, stDate Date2) {
if (IsDate1BeforeDate2(Date1, Date2)) return enDateCompare::Before;
if (IsDate1EqualDate2(Date1, Date2)) return enDateCompare::Equal;
/* if (IsDate1AfterDate2(Date1,Date2)) return enDateCompare::After;
*///this is faster
return enDateCompare::After;
}
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
int main() {
cout << "\nEnter Date1:";
stDate Date1 = ReadFullDate();
cout << "\nEnter Date2:";
stDate Date2 = ReadFullDate();
cout << "\nCompare Result = " << CompareDates(Date1, Date2);
system("pause>0");
return 0;
}
Problem #58
دول الحالتين اللي بيحصل فيه عدم تقاطع للفترتين ان تاريخ نهاية الفتره الثانيه يكون قبل تاريخ بداية الفتره االولي
او تاريخ بداية الثانيه يكون بعد تاريخ نهاية االولي
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;};
struct stPeriod{
stDate StartDate;
stDate EndDate;};
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
stPeriod ReadPeriod() {
stPeriod Period;
cout << "\nEnter Start Date:\n";
Period.StartDate = ReadFullDate();
cout << "\nEnter End Date:\n";
Period.EndDate = ReadFullDate();
return Period;
}
int main() {
cout << "\nEnter Period 1:";
stPeriod Period1 = ReadPeriod();
cout << "\nEnter Period 2:";
stPeriod Period2 = ReadPeriod();
if (IsOverlapPeriods(Period1, Period2)) cout << "\nYes, Periods Overlap\n";
else cout << "\nNo, Periods do not Overlap\n";
system("pause>0");
return 0;
}
Problem #59
period اعمل زي مابيقولك واستخدم اللي بتحسب الفرق بين تاريخين بس خليها تاخد
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
struct stPeriod{
stDate StartDate;
stDate EndDate;
};
Problem #60
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
struct stPeriod{
stDate StartDate;
stDate EndDate;
};
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
stPeriod ReadPeriod() {
stPeriod Period;
cout << "\nEnter Start Date:\n";
Period.StartDate = ReadFullDate();
cout << "\nEnter End Date:\n";
Period.EndDate = ReadFullDate();
return Period;
}
int main() {
cout << "\nEnter Period :";
stPeriod Period = ReadPeriod();
cout << "\nEnter Date to check:\n";
stDate Date = ReadFullDate();
if (isDateInPeriod(Date, Period)) cout << "\nYes, Date is within period\n";
else cout << "\nNo, Date is NOT within period\n";
system("pause>0");
return 0;
}
Problem #61
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
struct stPeriod{
stDate StartDate;
stDate EndDate;
};
bool IsDate1BeforeDate2(stDate Date1, stDate Date2) {
return (Date1.Year < Date2.Year) ? true : ((Date1.Year == Date2.Year) ? (Date1.Month < Date2.Month ? true :
(Date1.Month == Date2.Month ? Date1.Day < Date2.Day : false)) : false);
}
bool IsDate1EqualDate2(stDate Date1, stDate Date2) {
return (Date1.Year == Date2.Year) ? ((Date1.Month == Date2.Month) ? ((Date1.Day == Date2.Day) ? true : false) : false)
: false;
}
bool IsDate1AfterDate2(stDate Date1, stDate Date2) {
return (!IsDate1BeforeDate2(Date1, Date2) && !IsDate1EqualDate2(Date1, Date2));
}
bool isLeapYear(short Year) {
return (Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0);
}
short ReadDay() {
short Day;
cout << "\nPlease enter a Day? ";
cin >> Day;
return Day;
}
short ReadMonth() {
short Month;
cout << "Please enter a Month? ";
cin >> Month;
return Month;
}
short ReadYear() {
short Year;
cout << "Please enter a Year? ";
cin >> Year;
return Year;
}
stDate ReadFullDate() {
stDate Date;
Date.Day = ReadDay();
Date.Month = ReadMonth();
Date.Year = ReadYear();
return Date;
}
stPeriod ReadPeriod() {
stPeriod Period;
cout << "\nEnter Start Date:\n";
Period.StartDate = ReadFullDate();
cout << "\nEnter End Date:\n";
Period.EndDate = ReadFullDate();
return Period;
}
int main() {
cout << "\nEnter Period 1 :";
stPeriod Period1 = ReadPeriod();
cout << "\nEnter Period 2 :";
stPeriod Period2 = ReadPeriod();
cout << "\nOverlap Days Count Is: " << CountOverlapDays(Period1, Period2);
system("pause>0");
return 0;
}
Problem #62
الحل
#include<iostream>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
bool isLeapYear(short Year) {
return (Year % 4 == 0 && Year % 100 != 0) || (Year % 400 == 0);
}
short NumberOfDaysInAMonth(short Month, short Year) {
if (Month < 1 || Month>12) return 0;
int days[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }
;
return (Month == 2) ? (isLeapYear(Year) ? 29 : 28) : days[Month - 1];
}
Problem #63:64
الحل
#include<iostream>
#include<string>
#include<vector>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
vector<string> SplitString(string S1, string Delim) {
vector<string> vString;
short pos = 0;
string sWord;
// define a string variable
//use find() function to get the position of the delimiters
while ((pos = S1.find(Delim)) != std::string::npos){
sWord =S1.substr(0, pos);
// store the word
if (sWord !=""){
vString.push_back(sWord);}
if (S1 != "") {
vString.push_back(S1);
// it adds last word of the string.
}
return vString;
}
Problem #65
الحل
#include<iostream>
#include<string>
#include<vector>
using namespace std;
struct stDate{
short Year;
short Month;
short Day;
};
vector<string> SplitString(string S1, string Delim) {
vector<string> vString;
short pos = 0;
string sWord;
// define a string variable
// // use find() function to get the position of the delimiters
while ((pos = S1.find(Delim)) != std::string::npos){
sWord =S1.substr(0, pos);
// store the word
if (sWord !=""){
vString.push_back(sWord);}
S1.erase(0, pos + Delim.length());
/* erase() until positon and move to next word. */ }
if (S1 != "") {
vString.push_back(S1);
// it adds last word of the string.
}
return vString;
}
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <iomanip>
struct stUser
{
string UserName;
string Password;
int Permissions;
bool MarkForDelete = false;
};
enum enManageUsersMenueOptions {
eListUsers = 1, eAddNewUser = 2, eDeleteUser = 3,
eUpdateUser = 4, eFindUser = 5, eMainMenue = 6
};
enum enMainMenueOptions {
eListClients = 1, eAddNewClient = 2, eDeleteClient = 3,
eUpdateClient = 4, eFindClient = 5, eShowTransactionsMenue = 6,
eManageUsers = 7, eExit = 8
};
enum enMainMenuePermissions {
eAll = -1, pListClients = 1, pAddNewClient = 2, pDeleteClient = 4,
pUpdateClients = 8, pFindClient = 16, pTranactions = 32, pManageUsers = 64
};
stUser CurrentUser;
void ShowMainMenue();
void ShowTransactionsMenue();
void ShowManageUsersMenue();
bool CheckAccessPermission(enMainMenuePermissions Permission);
void Login();
struct sClient
{
string AccountNumber;
string PinCode;
string Name;
string Phone;
double AccountBalance;
bool MarkForDelete = false;
};
vector<string> vString;
short pos = 0;
string sWord; // define a string variable
S1.erase(0, pos + Delim.length()); /* erase() until positon and move to next word. */
}
if (S1 != "")
{
vString.push_back(S1); // it adds last word of the string.
}
return vString;
stUser User;
vector<string> vUserData;
User.UserName = vUserData[0];
User.Password = vUserData[1];
User.Permissions = stoi(vUserData[2]);
return User;
sClient Client;
vector<string> vClientData;
Client.AccountNumber = vClientData[0];
Client.PinCode = vClientData[1];
Client.Name = vClientData[2];
Client.Phone = vClientData[3];
Client.AccountBalance = stod(vClientData[4]);//cast string to double
return Client;
User.UserName = vUserData[0];
User.Password = vUserData[1];
User.Permissions = stoi(vUserData[2]);
return User;
return stClientRecord;
return stClientRecord;
fstream MyFile;
MyFile.open(FileName, ios::in);//read Mode
if (MyFile.is_open())
{
string Line;
sClient Client;
Client = ConvertLinetoRecord(Line);
if (Client.AccountNumber == AccountNumber)
{
MyFile.close();
return true;
}
vClients.push_back(Client);
}
MyFile.close();
return false;
fstream MyFile;
MyFile.open(FileName, ios::in);//read Mode
if (MyFile.is_open())
{
string Line;
stUser User;
User = ConvertUserLinetoRecord(Line);
if (User.UserName == Username)
{
MyFile.close();
return true;
}
MyFile.close();
return false;
sClient ReadNewClient()
{
sClient Client;
return Client;
int ReadPermissionsToSet()
{
int Permissions = 0;
char Answer = 'n';
cout << "\nDo you want to give full access? y/n? ";
cin >> Answer;
if (Answer == 'y' || Answer == 'Y')
{
return -1;
}
Permissions += enMainMenuePermissions::pListClients;
}
return Permissions;
stUser ReadNewUser()
{
stUser User;
User.Permissions = ReadPermissionsToSet();
return User;
if (MyFile.is_open())
{
string Line;
stUser User;
User = ConvertUserLinetoRecord(Line);
vUsers.push_back(User);
}
MyFile.close();
return vUsers;
fstream MyFile;
MyFile.open(FileName, ios::in);//read Mode
if (MyFile.is_open())
{
string Line;
sClient Client;
Client = ConvertLinetoRecord(Line);
vClients.push_back(Client);
}
MyFile.close();
return vClients;
cout << "| " << setw(15) << left << Client.AccountNumber;
cout << "| " << setw(10) << left << Client.PinCode;
cout << "| " << setw(40) << left << Client.Name;
cout << "| " << setw(12) << left << Client.Phone;
cout << "| " << setw(12) << left << Client.AccountBalance;
cout << "| " << setw(15) << left << User.UserName;
cout << "| " << setw(10) << left << User.Password;
cout << "| " << setw(40) << left << User.Permissions;
}
cout << "| " << setw(15) << left << Client.AccountNumber;
cout << "| " << setw(40) << left << Client.Name;
cout << "| " << setw(12) << left << Client.AccountBalance;
void ShowAccessDeniedMessage()
{
cout << "\n------------------------------------\n";
cout << "Access Denied, \nYou dont Have Permission To Do this,\nPlease Conact Your Admin.";
cout << "\n------------------------------------\n";
}
oid ShowAllClientsScreen()
{
if (!CheckAccessPermission(enMainMenuePermissions::pListClients))
{
ShowAccessDeniedMessage();
return;
}
cout << "\n\t\t\t\t\tClient List (" << vClients.size() << ") Client(s).";
cout << "\n_______________________________________________________";
cout << "_________________________________________\n" << endl;
cout << "| " << left << setw(15) << "Accout Number";
cout << "| " << left << setw(10) << "Pin Code";
cout << "| " << left << setw(40) << "Client Name";
cout << "| " << left << setw(12) << "Phone";
cout << "| " << left << setw(12) << "Balance";
cout << "\n_______________________________________________________";
cout << "_________________________________________\n" << endl;
if (vClients.size() == 0)
cout << "\t\t\t\tNo Clients Available In the System!";
else
void ShowAllUsersScreen()
{
cout << "\n\t\t\t\t\tUsers List (" << vUsers.size() << ") User(s).";
cout << "\n_______________________________________________________";
cout << "_________________________________________\n" << endl;
cout << "| " << left << setw(15) << "User Name";
cout << "| " << left << setw(10) << "Password";
cout << "| " << left << setw(40) << "Permissions";
cout << "\n_______________________________________________________";
cout << "_________________________________________\n" << endl;
if (vUsers.size() == 0)
cout << "\t\t\t\tNo Users Available In the System!";
else
PrintUserRecordLine(User);
cout << endl;
}
void ShowTotalBalances()
{
cout << "\n\t\t\t\t\tBalances List (" << vClients.size() << ") Client(s).";
cout << "\n_______________________________________________________";
cout << "_________________________________________\n" << endl;
cout << "| " << left << setw(15) << "Accout Number";
cout << "| " << left << setw(40) << "Client Name";
cout << "| " << left << setw(12) << "Balance";
cout << "\n_______________________________________________________";
cout << "_________________________________________\n" << endl;
double TotalBalances = 0;
if (vClients.size() == 0)
cout << "\t\t\t\tNo Clients Available In the System!";
else
PrintClientRecordBalanceLine(Client);
TotalBalances += Client.AccountBalance;
if (C.AccountNumber == AccountNumber)
{
Client = C;
return true;
}
}
return false;
if (U.UserName == Username)
{
User = U;
return true;
}
}
return false;
}
return false;
Client.AccountNumber = AccountNumber;
return Client;
User.Permissions = ReadPermissionsToSet();
return User;
fstream MyFile;
MyFile.open(FileName, ios::out);//overwrite
string DataLine;
if (MyFile.is_open())
{
if (C.MarkForDelete == false)
{
//we only write records that are not marked for delete.
DataLine = ConvertRecordToLine(C);
MyFile << DataLine << endl;
}
MyFile.close();
return vClients;
fstream MyFile;
MyFile.open(FileName, ios::out);//overwrite
string DataLine;
if (MyFile.is_open())
{
if (U.MarkForDelete == false)
{
//we only write records that are not marked for delete.
DataLine = ConvertUserRecordToLine(U);
MyFile << DataLine << endl;
MyFile.close();
return vUsers;
if (MyFile.is_open())
{
MyFile.close();
}
void AddNewClient()
{
sClient Client;
Client = ReadNewClient();
AddDataLineToFile(ClientsFileName, ConvertRecordToLine(Client));
}
void AddNewUser()
{
stUser User;
User = ReadNewUser();
AddDataLineToFile(UsersFileName, ConvertUserRecordToLine(User));
void AddNewClients()
{
char AddMore = 'Y';
do
{
//system("cls");
cout << "Adding New Client:\n\n";
AddNewClient();
cout << "\nClient Added Successfully, do you want to add more clients? Y/N? ";
void AddNewUsers()
{
char AddMore = 'Y';
do
{
//system("cls");
cout << "Adding New User:\n\n";
AddNewUser();
cout << "\nUser Added Successfully, do you want to add more Users? Y/N? ";
sClient Client;
char Answer = 'n';
PrintClientCard(Client);
cout << "\n\nAre you sure you want delete this client? y/n ? ";
cin >> Answer;
if (Answer == 'y' || Answer == 'Y')
{
MarkClientForDeleteByAccountNumber(AccountNumber, vClients);
SaveCleintsDataToFile(ClientsFileName, vClients);
//Refresh Clients
vClients = LoadCleintsDataFromFile(ClientsFileName);
}
else
{
cout << "\nClient with Account Number (" << AccountNumber << ") is Not Found!";
return false;
}
if (Username == "Admin")
{
cout << "\n\nYou cannot Delete This User.";
return false;
stUser User;
char Answer = 'n';
PrintUserCard(User);
cout << "\n\nAre you sure you want delete this User? y/n ? ";
cin >> Answer;
if (Answer == 'y' || Answer == 'Y')
{
MarkUserForDeleteByUsername(Username, vUsers);
SaveUsersDataToFile(UsersFileName, vUsers);
//Refresh Clients
vUsers = LoadUsersDataFromFile(UsersFileName);
}
else
{
cout << "\nUser with Username (" << Username << ") is Not Found!";
return false;
}
sClient Client;
char Answer = 'n';
PrintClientCard(Client);
cout << "\n\nAre you sure you want update this client? y/n ? ";
cin >> Answer;
if (Answer == 'y' || Answer == 'Y')
{
SaveCleintsDataToFile(ClientsFileName, vClients);
}
else
{
cout << "\nClient with Account Number (" << AccountNumber << ") is Not Found!";
return false;
}
stUser User;
char Answer = 'n';
PrintUserCard(User);
cout << "\n\nAre you sure you want update this User? y/n ? ";
cin >> Answer;
if (Answer == 'y' || Answer == 'Y')
{
for (stUser& U : vUsers)
{
if (U.UserName == Username)
{
U = ChangeUserRecord(Username);
break;
}
SaveUsersDataToFile(UsersFileName, vUsers);
}
else
{
cout << "\nUser with Account Number (" << Username << ") is Not Found!";
return false;
}
return true;
}
return false;
}
string ReadClientAccountNumber()
{
string AccountNumber = "";
string ReadUserName()
{
string Username = "";
void ShowListUsersScreen()
{
ShowAllUsersScreen();
void ShowAddNewUserScreen()
{
cout << "\n-----------------------------------\n";
cout << "\tAdd New User Screen";
cout << "\n-----------------------------------\n";
AddNewUsers();
void ShowDeleteUserScreen()
{
cout << "\n-----------------------------------\n";
cout << "\tDelete Users Screen";
cout << "\n-----------------------------------\n";
}
void ShowUpdateUserScreen()
{
cout << "\n-----------------------------------\n";
cout << "\tUpdate Users Screen";
cout << "\n-----------------------------------\n";
UpdateUserByUsername(Username, vUsers);
}
void ShowDeleteClientScreen()
{
if (!CheckAccessPermission(enMainMenuePermissions::pDeleteClient))
{
ShowAccessDeniedMessage();
return;
}
void ShowUpdateClientScreen()
{
if (!CheckAccessPermission(enMainMenuePermissions::pUpdateClients))
{
ShowAccessDeniedMessage();
return;
}
void ShowAddNewClientsScreen()
{
if (!CheckAccessPermission(enMainMenuePermissions::pUpdateClients))
{
ShowAccessDeniedMessage();
return;
}
AddNewClients();
void ShowFindClientScreen()
{
if (!CheckAccessPermission(enMainMenuePermissions::pFindClient))
{
ShowAccessDeniedMessage();
return;
}
void ShowFindUserScreen()
{
cout << "\n-----------------------------------\n";
cout << "\tFind User Screen";
cout << "\n-----------------------------------\n";
void ShowEndScreen()
{
cout << "\n-----------------------------------\n";
cout << "\tProgram Ends :-)";
cout << "\n-----------------------------------\n";
void ShowDepositScreen()
{
cout << "\n-----------------------------------\n";
cout << "\tDeposit Screen";
cout << "\n-----------------------------------\n";
sClient Client;
PrintClientCard(Client);
double Amount = 0;
cout << "\nPlease enter deposit amount? ";
cin >> Amount;
void ShowWithDrawScreen()
{
cout << "\n-----------------------------------\n";
cout << "\tWithdraw Screen";
cout << "\n-----------------------------------\n";
sClient Client;
PrintClientCard(Client);
double Amount = 0;
cout << "\nPlease enter withdraw amount? ";
cin >> Amount;
void ShowTotalBalancesScreen()
{
ShowTotalBalances();
}
bool CheckAccessPermission(enMainMenuePermissions Permission)
{
if (CurrentUser.Permissions == enMainMenuePermissions::eAll)
return true;
}
void GoBackToMainMenue()
{
cout << "\n\nPress any key to go back to Main Menue...";
system("pause>0");
ShowMainMenue();
}
void GoBackToTransactionsMenue()
{
cout << "\n\nPress any key to go back to Transactions Menue...";
system("pause>0");
ShowTransactionsMenue();
void GoBackToManageUsersMenue()
{
cout << "\n\nPress any key to go back to Transactions Menue...";
system("pause>0");
ShowManageUsersMenue();
short ReadTransactionsMenueOption()
{
cout << "Choose what do you want to do? [1 to 4]? ";
short Choice = 0;
cin >> Choice;
return Choice;
}
case enTransactionsMenueOptions::eWithdraw:
{
system("cls");
ShowWithDrawScreen();
GoBackToTransactionsMenue();
break;
}
case enTransactionsMenueOptions::eShowTotalBalance:
{
system("cls");
ShowTotalBalancesScreen();
GoBackToTransactionsMenue();
break;
}
case enTransactionsMenueOptions::eShowMainMenue:
{
ShowMainMenue();
}
}
void ShowTransactionsMenue()
{
if (!CheckAccessPermission(enMainMenuePermissions::pTranactions))
{
ShowAccessDeniedMessage();
GoBackToMainMenue();
return;
}
system("cls");
cout << "===========================================\n";
cout << "\t\tTransactions Menue Screen\n";
cout << "===========================================\n";
cout << "\t[1] Deposit.\n";
cout << "\t[2] Withdraw.\n";
cout << "\t[3] Total Balances.\n";
cout << "\t[4] Main Menue.\n";
cout << "===========================================\n";
PerfromTranactionsMenueOption((enTransactionsMenueOptions)ReadTransactionsMenueOption());
}
short ReadMainMenueOption()
{
cout << "Choose what do you want to do? [1 to 8]? ";
short Choice = 0;
cin >> Choice;
return Choice;
}
case enManageUsersMenueOptions::eAddNewUser:
{
system("cls");
ShowAddNewUserScreen();
GoBackToManageUsersMenue();
break;
}
case enManageUsersMenueOptions::eDeleteUser:
{
system("cls");
ShowDeleteUserScreen();
GoBackToManageUsersMenue();
break;
}
case enManageUsersMenueOptions::eUpdateUser:
{
system("cls");
ShowUpdateUserScreen();
GoBackToManageUsersMenue();
break;
}
case enManageUsersMenueOptions::eFindUser:
{
system("cls");
ShowFindUserScreen();
GoBackToManageUsersMenue();
break;
}
case enManageUsersMenueOptions::eMainMenue:
{
ShowMainMenue();
}
}
short ReadManageUsersMenueOption()
{
cout << "Choose what do you want to do? [1 to 6]? ";
short Choice = 0;
cin >> Choice;
return Choice;
}
void ShowManageUsersMenue()
{
if (!CheckAccessPermission(enMainMenuePermissions::pManageUsers))
{
ShowAccessDeniedMessage();
GoBackToMainMenue();
return;
}
system("cls");
cout << "===========================================\n";
cout << "\t\tManage Users Menue Screen\n";
cout << "===========================================\n";
cout << "\t[1] List Users.\n";
cout << "\t[2] Add New User.\n";
cout << "\t[3] Delete User.\n";
cout << "\t[4] Update User.\n";
cout << "\t[5] Find User.\n";
cout << "\t[6] Main Menue.\n";
cout << "===========================================\n";
PerfromManageUsersMenueOption((enManageUsersMenueOptions)ReadManageUsersMenueOption());
}
case enMainMenueOptions::eDeleteClient:
system("cls");
ShowDeleteClientScreen();
GoBackToMainMenue();
break;
case enMainMenueOptions::eUpdateClient:
system("cls");
ShowUpdateClientScreen();
GoBackToMainMenue();
break;
case enMainMenueOptions::eFindClient:
system("cls");
ShowFindClientScreen();
GoBackToMainMenue();
break;
case enMainMenueOptions::eShowTransactionsMenue:
system("cls");
ShowTransactionsMenue();
break;
case enMainMenueOptions::eManageUsers:
system("cls");
ShowManageUsersMenue();
break;
case enMainMenueOptions::eExit:
system("cls");
// ShowEndScreen();
Login();
break;
}
void ShowMainMenue()
{
system("cls");
cout << "===========================================\n";
cout << "\t\tMain Menue Screen\n";
cout << "===========================================\n";
cout << "\t[1] Show Client List.\n";
cout << "\t[2] Add New Client.\n";
cout << "\t[3] Delete Client.\n";
cout << "\t[4] Update Client Info.\n";
cout << "\t[5] Find Client.\n";
cout << "\t[6] Transactions.\n";
cout << "\t[7] Manage Users.\n";
cout << "\t[8] Logout.\n";
cout << "===========================================\n";
PerfromMainMenueOption((enMainMenueOptions)ReadMainMenueOption());
}
void Login()
{
bool LoginFaild = false;
if (LoginFaild)
{
cout << "Invlaid Username/Password!\n";
}
} while (LoginFaild);
ShowMainMenue();
int main()
{
Login();
system("pause>0");
return 0;
}
1 2 4 8 16
A B C D E
enum enMainMenuePermissions {
eAll = -1, pListClients = 1, pAddNewClient = 2, pDeleteClient = 4,
pUpdateClients = 8, pFindClient = 16, pTranactions = 32, pManageUsers = 64
};
من اليوزر ولو اليوزر وافق انه يديها صالحيهn وy او بتقراfalse وtrue مثال وهقوم عامل داله بتقراint بعدين هقوم معرف
وكل ماليوزر يديك موافقه علي حاجه هتقوم جايب قيمه المتغير وجامع عليه قيمة الصالحيه دي زي كده
int ReadPermissionsToSet()
{
int Permissions = 0;
char Answer = 'n';
cout << "\nDo you want to give full access? y/n? ";
cin >> Answer;
if (Answer == 'y' || Answer == 'Y')
{
return -1;
}
Permissions += enMainMenuePermissions::pListClients;
}
cout << "\nAdd New Client? y/n? ";
cin >> Answer;
if (Answer == 'y' || Answer == 'Y')
{
Permissions += enMainMenuePermissions::pAddNewClient;
}
return Permissions;
1 2 4 8 16
A B C D E
21
1 0 1 0 1
طيب انا دلوقتي عاوزر اعرف الصالحيه معينه متاحه مع اليوزر ده وال ال هعمل ايه؟
ببساطه هقوله هل الرقم اللي بيعبر عن الصالحيات ده (بالنسبالنا هنا )21هل من ضمنه الرقم 4مثال ؟
}
فاللي هيتم انه هيمسك الرقم 21ويمسك او bitفيه هيالقيه بيساوي 1فيحط صفر ويمسك الرقم التاني يالقيه بيساوي 2فيحط قدامه صفر ويمسك
الرقم اللي بعد يالقيه بيساوي 4ويحط قدامه 1الن ده اللي بيدور عليه وهكذا لحد مانالقي النتيجه بقت كده
1 2 4 8 16
A B C D E
21
1 0 1 0 1
0 0 1 0 0 4
0 0 1 0 0 4
وأصبحت القيمه النهائية يااما نفس الرقم اللي انت بتدور عليه او صفر
struct sClient
{
string AccountNumber;
string PinCode;
string Name;
string Phone;
double AccountBalance;
bool MarkForDelete = false;
};
enum enMainMenueOptions {
eQucikWithdraw = 1, eNormalWithDraw = 2, eDeposit = 3,
eCheckBalance = 4, eExit = 5
};
vector<string> vString;
short pos = 0;
string sWord; // define a string variable
S1.erase(0, pos + Delim.length()); /* erase() until positon and move to next word. */
}
if (S1 != "")
{
vString.push_back(S1); // it adds last word of the string.
}
return vString;
sClient Client;
vector<string> vClientData;
Client.AccountNumber = vClientData[0];
Client.PinCode = vClientData[1];
Client.Name = vClientData[2];
Client.Phone = vClientData[3];
Client.AccountBalance = stod(vClientData[4]);//cast string to double
return Client;
return stClientRecord;
fstream MyFile;
MyFile.open(FileName, ios::in);//read Mode
if (MyFile.is_open())
{
string Line;
sClient Client;
Client = ConvertLinetoRecord(Line);
vClients.push_back(Client);
}
MyFile.close();
return vClients;
}
return false;
fstream MyFile;
MyFile.open(FileName, ios::out);//overwrite
string DataLine;
if (MyFile.is_open())
{
if (C.MarkForDelete == false)
{
//we only write records that are not marked for delete.
DataLine = ConvertRecordToLine(C);
MyFile << DataLine << endl;
MyFile.close();
return vClients;
}
bool DepositBalanceToClientByAccountNumber(string AccountNumber, double Amount, vector <sClient>& vClients)
{
char Answer = 'n';
cout << "\n\nAre you sure you want perfrom this transaction? y/n ? ";
cin >> Answer;
if (Answer == 'y' || Answer == 'Y')
{
return true;
}
return false;
}
short ReadQuickWithdrawOption()
{
short Choice = 0;
while (Choice < 1 || Choice>9)
{
cout << "\nChoose what to do from [1] to [9] ? ";
cin >> Choice;
}
return Choice;
}
}
double ReadDepositAmount()
{
double Amount;
cout << "\nEnter a positive Deposit Amount? ";
void PerfromDepositOption()
{
void ShowCheckBalanceScreen()
{
system("cls");
cout << "===========================================\n";
cout << "\t\tCheck Balance Screen\n";
cout << "===========================================\n";
cout << "Your Balance is " << CurrentClient.AccountBalance << "\n";
int ReadWithDrawAmont()
{
int Amount;
cout << "\nEnter an amount multiple of 5's ? ";
while (Amount % 5 != 0)
{
cout << "\nEnter an amount multiple of 5's ? ";
cin >> Amount;
}
return Amount;
}
void PerfromNormalWithdrawOption()
{
int WithDrawBalance = ReadWithDrawAmont();
void ShowNormalWithDrawScreen()
{
system("cls");
cout << "===========================================\n";
cout << "\t\tNormal Withdraw Screen\n";
cout << "===========================================\n";
PerfromNormalWithdrawOption();
}
void ShowQuickWithdrawScreen()
{
system("cls");
cout << "===========================================\n";
cout << "\t\tQucik Withdraw\n";
cout << "===========================================\n";
cout << "\t[1] 20\t\t[2] 50\n";
cout << "\t[3] 100\t\t[4] 200\n";
cout << "\t[5] 400\t\t[6] 600\n";
cout << "\t[7] 800\t\t[8] 1000\n";
cout << "\t[9] Exit\n";
cout << "===========================================\n";
cout << "Your Balance is " << CurrentClient.AccountBalance;
PerfromQuickWithdrawOption(ReadQuickWithdrawOption());
}
void GoBackToMainMenue()
{
cout << "\n\nPress any key to go back to Main Menue...";
system("pause>0");
ShowMainMenue();
}
short ReadMainMenueOption()
{
cout << "Choose what do you want to do? [1 to 5]? ";
short Choice = 0;
cin >> Choice;
return Choice;
}
void PerfromMainMenueOption(enMainMenueOptions MainMenueOption)
{
switch (MainMenueOption)
{
case enMainMenueOptions::eQucikWithdraw:
{
system("cls");
ShowQuickWithdrawScreen();
GoBackToMainMenue();
break;
}
case enMainMenueOptions::eNormalWithDraw:
system("cls");
ShowNormalWithDrawScreen();
GoBackToMainMenue();
break;
case enMainMenueOptions::eDeposit:
system("cls");
ShowDepositScreen();
GoBackToMainMenue();
break;
case enMainMenueOptions::eCheckBalance:
system("cls");
ShowCheckBalanceScreen();
GoBackToMainMenue();
break;
case enMainMenueOptions::eExit:
system("cls");
Login();
break;
}
}
void ShowMainMenue()
{
system("cls");
cout << "===========================================\n";
cout << "\t\tATM Main Menue Screen\n";
cout << "===========================================\n";
cout << "\t[1] Quick Withdraw.\n";
cout << "\t[2] Normal Withdraw.\n";
cout << "\t[3] Deposit\n";
cout << "\t[4] Check Balance.\n";
cout << "\t[5] Logout.\n";
cout << "===========================================\n";
PerfromMainMenueOption((enMainMenueOptions)ReadMainMenueOption());
}
void Login()
{
bool LoginFaild = false;
string AccountNumber, PinCode;
do
{
system("cls");
cout << "\n---------------------------------\n";
cout << "\tLogin Screen";
cout << "\n---------------------------------\n";
if (LoginFaild)
{
cout << "Invlaid Account Number/PinCode!\n";
}
} while (LoginFaild);
ShowMainMenue();
int main()
{
Login();
system("pause>0");
return 0;
}
end