Created
September 20, 2017 22:00
-
-
Save hckim16/e2d76da56840c4bb4d7708bb8ac66395 to your computer and use it in GitHub Desktop.
Code written to tabulate travel expense account, written by group listed in comments with myself as project team leader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //courseID:CIS265-002HY | |
| //name: Jack Kim, Kayla Guirao, Winielson Miranda, Fatima Idrissa | |
| //Prof. Wang | |
| //Group Project#1 | |
| //Due by 2/27/2012 | |
| #include <iostream> | |
| #include <cstdlib> | |
| using namespace std; | |
| //INPUT | |
| //prototypes | |
| int numDays (); | |
| int getDepartTime(); | |
| int getArrivalTime(); | |
| double numAirfare(); | |
| double numCarRental(); | |
| double povCost(); | |
| double parkingCost(); | |
| double taxiFees(); | |
| double conferenceFees(); | |
| double getHotelFees(int hotelDays); | |
| double getHotelDebt(int hotelDays, double hotelCost); | |
| double getMealCost(int** meal, int days); | |
| double getMealCov(int** meal, int days); | |
| double getMealDebt(double mealCost, double allowedMeals); | |
| //Processing | |
| //function 10a holds meal array | |
| //Done by: Winelson | |
| int** getMeal(int days, int columns, double departureTime, double arrivalTime) | |
| { | |
| int** meal = new int*[days]; | |
| for (int n = 0; n < days; n++) | |
| { | |
| meal[n] = new int[columns]; | |
| cout << "DAY " << n + 1 << endl; | |
| if ((n == 0 && departureTime <= 7.00) || //if first day and departure Time between 0.00 and 7.00, then breakfast will be accounted for | |
| (n == days-1 && arrivalTime > 8.00) || //if last day and arrival time between 8 and 13.00, then breakfast will be accounted for | |
| (n>0 && n<days-1)) //day other than first and last days all account for breakfast | |
| { | |
| cout << " Cost of breakfast : $ "; | |
| cin >> meal[n][0]; | |
| } | |
| else | |
| meal[n][0] = 0; | |
| if ((n == 0 && departureTime <= 12.00) || //if first day and departure Time between 0.00 and 12.00, then lunch will be accounted for | |
| (n == days-1 && arrivalTime >= 13.00) || //if last day and arrival time between 13.00 and 19.00, then lunch will be accounted for | |
| (n>0 && n<days-1)) //day other than first and last days all account for lunch | |
| { | |
| cout << " Cost of lunch : $ "; | |
| cin >> meal[n][1]; | |
| } | |
| else | |
| meal[n][1] = 0; | |
| if ((n == 0 && departureTime <= 18.00) || //if first day and departure Time between 0.00 and 18.00, then dinner will be accounted for | |
| (n == days-1 && arrivalTime >= 19.00) || //if last day and arrival time between 19.00 and 23.59, then dinner will be accounted for | |
| (n>0 && n<days-1)) //day other than first and last days all account for dinner | |
| { | |
| cout << " Cost of dinner : $ "; | |
| cin >> meal[n][2]; | |
| } | |
| else | |
| meal[n][2] = 0; | |
| if ((n == 0 && departureTime > 18) || //if first day departure time is between 18.00 and 23.59, then no meals covered that day | |
| (n == days-1 && arrivalTime < 8)) //if last day arrival time is between 0.00 and 8.00, then no meals covered that day | |
| { //OUTPUT | |
| cout << " This day's meal expenses will not be covered by the company." << endl; | |
| } | |
| } | |
| return meal; | |
| } | |
| //Clears meal after program ends | |
| //Done by: Winelson | |
| void clearMeal(int** meal, int days) | |
| { //processing | |
| if(meal) | |
| { | |
| for(int i = 0; i < days; i++) | |
| { | |
| meal[i][0]=0; | |
| meal[i][1]=0; | |
| meal[i][2]=0; | |
| //output | |
| delete[] meal[i]; | |
| } | |
| delete[] meal; | |
| } | |
| } | |
| //function #1 for days spent on the trip | |
| //Done by: Fatima | |
| int numDays() | |
| { //processing | |
| int days = 0; | |
| cout << "How many days were you on the trip?: "; | |
| cin >> days; | |
| cout << endl; | |
| while (days < 1) //input validation | |
| { //output | |
| cout << "The number must be greater than 0, try again: "; | |
| cin >> days; | |
| cout << endl; | |
| } | |
| return days; | |
| } | |
| //function #2a Departure time | |
| //Done by: Winelson | |
| //processing | |
| int getDepartTime() | |
| { | |
| double departureTime; | |
| cout << "At what time did you depart for the trip? (00.00 format-militray time): "; | |
| cin >> departureTime; | |
| cout <<endl; | |
| while ( departureTime <0 || departureTime > 23.59) | |
| { //output | |
| cout << "Please enter a number between 00.00 and 23.59: "; | |
| cin >> departureTime; | |
| } | |
| return departureTime; | |
| } | |
| //function #2B arrival time | |
| //Done by: Winelson | |
| //processing | |
| int getArrivalTime() | |
| { | |
| double arrivalTime; | |
| cout << "At what time did you arrive for the trip? (00.00 format-militray time): " ; | |
| cin >> arrivalTime; | |
| cout <<endl; | |
| //output | |
| while ( arrivalTime <0 || arrivalTime > 23.59) | |
| { | |
| cout << "Please enter a number between 00.00 and 23.59: "; | |
| cin >> arrivalTime; | |
| } | |
| return arrivalTime; | |
| } | |
| //function #3 for airplane expenses | |
| //Done by: Fatima | |
| //processing | |
| double numAirfare () | |
| { | |
| double airfare; | |
| cout << "What was the total cost of air fare?: $"; | |
| cin >> airfare; | |
| cout << endl; | |
| //input validation | |
| //output | |
| while (airfare < 0) | |
| { | |
| cout << "The number must be greater than 0, try again: $"; | |
| cin >> airfare; | |
| cout << endl; | |
| } | |
| return airfare; | |
| } | |
| //function #4 for car rental costs | |
| //Done by: Fatima | |
| //processing | |
| double numCarRental () | |
| { | |
| double carRental; | |
| cout << "What was the total cost of car rentals?: $"; | |
| cin >> carRental; | |
| cout << endl; | |
| //input validation | |
| //output | |
| while (carRental < 0) | |
| { | |
| cout << "The number must be greater than 0, try again: $"; | |
| cin >> carRental; | |
| cout << endl; | |
| } | |
| return carRental; | |
| } | |
| //calculates miles driven if privately owned vehicle was used | |
| //Done By: Fatima | |
| //processing | |
| double povCost() | |
| { | |
| double miles; | |
| char answer; | |
| cout<<"Did you travel via privately owned vehicle? Y or N "; | |
| cin>>answer; | |
| //in case user inputs are not Y or N | |
| if | |
| (answer!= 'Y'&&answer!='y'&&answer!='n'&&answer!='N') | |
| { | |
| cout<<"Type Y for yes, or N for no.\n"; | |
| cin>> answer; | |
| } | |
| //switch statement to calculate or return 0 according to the user input. | |
| switch(answer) | |
| { | |
| case 'y':case 'Y': | |
| cout<<"How many miles did you travel? "; | |
| cin>>miles; | |
| cout<<endl; | |
| //if statement in case the user enters negative value | |
| if(miles<=0) | |
| { | |
| cout<<"Please enter the miles traveled. "; | |
| cin>>miles; | |
| } | |
| //output | |
| return miles; | |
| break; | |
| default: | |
| miles = 0; | |
| cout << endl; | |
| return miles; | |
| break; | |
| } | |
| } | |
| //function 6 calculates parking fee | |
| //Done by: Fatima | |
| //processing | |
| double parkingCost() | |
| { | |
| double park; | |
| cout << "How much did parking cost? $"; | |
| cin >> park; | |
| while (park<0) | |
| { | |
| { | |
| cout<<"Please enter a positive value\n"; | |
| cin>>park; | |
| } | |
| } | |
| //output | |
| cout << endl; | |
| return park; | |
| } | |
| //#7 calculate taxi fees | |
| //Done by: Fatima | |
| //processing | |
| double taxiFees() | |
| { | |
| double taxiFee; | |
| cout << "How much was spent on taxi fees? $"; | |
| cin >> taxiFee; | |
| cout << endl; | |
| while (taxiFee<0) | |
| { | |
| cout << "Please enter a positive value. "; | |
| cin >> taxiFee; | |
| } | |
| //output | |
| return taxiFee; | |
| } | |
| //#8 calculate conference and seminar fees | |
| //Done by: Fatima | |
| //processing | |
| double conferenceFees() | |
| { | |
| double confFee; | |
| cout << "How much was spent on conference/seminar fees? $"; | |
| cin >> confFee; | |
| cout << endl; | |
| while (confFee<0) | |
| { | |
| cout << "Please enter a positive value. "; | |
| cin >> confFee; | |
| } | |
| //output | |
| return confFee; | |
| } | |
| //#9a Get hotel days | |
| //Done by: Winelson | |
| //processing | |
| double getHotelDays() | |
| { | |
| int hotelD; //holds amount for days lodged at hotel | |
| cout << "How many days did you lodge at your hotel? "; | |
| cin >> hotelD; | |
| while (hotelD < 0) | |
| { | |
| cout << "Please enter a valid input: "; | |
| cin >> hotelD; | |
| } | |
| if (hotelD == 0) | |
| { | |
| cout << endl; | |
| return 0; | |
| } | |
| //output | |
| return hotelD; | |
| } | |
| //#9b Get hotelCost (total cost for hotel) | |
| //Done by: Winelson | |
| //processing | |
| double getHotelFees(int hotelDays) | |
| { | |
| double hotelCost = 0, | |
| totalHotelCost = 0; | |
| if (hotelDays == 0) //If input from getHotelDays() = 0 then this function will not continue | |
| { | |
| cout << endl; | |
| return 0; | |
| } | |
| cout << "How much was the daily lodging expense? $"; | |
| cin >> hotelCost; | |
| while (hotelCost < 0) | |
| { | |
| cout << "Please enter a valid input: "; | |
| cin >> hotelCost; | |
| } | |
| //output | |
| totalHotelCost = hotelCost * hotelDays; | |
| cout << endl; | |
| return totalHotelCost; | |
| } | |
| //#9b Calculates amount of hotel cost to be reimbursed | |
| //Done by: Winelson | |
| //processing | |
| double getHotelDebt(int hotelDays, double hotelCost) | |
| { | |
| int hotelDbt; //hotel debt | |
| if((hotelCost / hotelDays) <= 90) //If the daily lodging expense is less then or equal to $90, then the company will cover all the expenses | |
| { | |
| hotelDbt = 0; | |
| } | |
| //output | |
| else if((hotelCost / hotelDays) > 90) //If the daily lodging expense is greater then $90, then the company will cover only cover $90 a day | |
| { | |
| hotelDbt = ((hotelCost / hotelDays) - 90) * hotelDays; | |
| } | |
| return hotelDbt; | |
| } | |
| //#10b Adds all inputs of meal costs | |
| //Done by: Winelson | |
| //processing | |
| double getMealCost(int** meal, int days) | |
| { | |
| double totalMealCost = 0; | |
| //output | |
| for (int n = 0; n < days; n++) | |
| { | |
| totalMealCost = totalMealCost + meal[n][0] + meal[n][1] + meal[n][2]; //Adds all meals | |
| } | |
| return totalMealCost; | |
| } | |
| //#10c Calculates amount covered by company | |
| //Done by: Winelson | |
| //processing | |
| double getMealCov(int** meal, int days) | |
| { | |
| int n; | |
| double allowedMeals = 0; | |
| //output | |
| for (n = 0; n < days; n++) | |
| { | |
| if (meal[n][0]>18) //If breakfast cost is more than $18, then the remainder will be not be covered by company | |
| allowedMeals = allowedMeals + 18; | |
| else | |
| allowedMeals = allowedMeals + meal[n][0]; | |
| if (meal[n][1]>12) //If lunch cost is more than $12, then the remainder will be not be covered by company | |
| allowedMeals = allowedMeals + 12; | |
| else | |
| allowedMeals = allowedMeals + meal[n][1]; | |
| if (meal[n][2]>20) //If dinner cost is more than $18, then the remainder will be not be covered by company | |
| allowedMeals = allowedMeals + 20; | |
| else | |
| allowedMeals = allowedMeals + meal[n][2]; | |
| } | |
| return allowedMeals; | |
| } | |
| //#10d Calculates amount of meal to be reimbursed | |
| //Done by: Winelson | |
| //processing | |
| double getMealDebt(double mealCost, double allowedMeals) | |
| { | |
| double mealDbt; //mealDebt | |
| //output | |
| mealDbt = mealCost - allowedMeals; | |
| return mealDbt; | |
| } | |
| int main(int argc, char** argv) | |
| { | |
| //variables, actual amount | |
| int days = 0; | |
| int hotelDays = 0; | |
| double departTime = 0; | |
| double arriveTime = 0; | |
| double airfare = 0; | |
| double miles = 0; | |
| double carRental = 0; | |
| double parking = 0; | |
| double taxi = 0; | |
| double confCost = 0; | |
| double vehicleExpense = 0; | |
| double totalExp = 0; | |
| double reimburse = 0; | |
| double amountSaved = 0; | |
| double hotelCost = 0; | |
| double hotelDebt = 0; | |
| double mealCost = 0; | |
| double mealDebt = 0; | |
| //variables, allowed expenses | |
| double allowedParking; | |
| double allowedTaxi; | |
| double allowedHotel; | |
| double allowedMeals; | |
| double totalAllowedExp; | |
| double userFees; //amount spends in total on parking, taxi, hotel and meal | |
| //runs function prototypes | |
| days = numDays(); | |
| departTime = getDepartTime(); | |
| arriveTime = getArrivalTime(); | |
| airfare = numAirfare(); | |
| miles = povCost(); | |
| vehicleExpense = miles * .27; | |
| carRental = numCarRental(); | |
| parking = parkingCost(); | |
| taxi = taxiFees(); | |
| confCost = conferenceFees(); | |
| hotelDays = getHotelDays(); | |
| hotelCost = getHotelFees(hotelDays); | |
| hotelDebt = getHotelDebt(hotelDays, hotelCost); | |
| int** meal = getMeal(days, 3, departTime, arriveTime); //gets all imput for cost of meals | |
| mealCost = getMealCost(meal, days); | |
| allowedMeals = getMealCov(meal, days); | |
| mealDebt = getMealDebt(mealCost, allowedMeals); | |
| //allowed expenses | |
| allowedParking = days * 6; | |
| allowedTaxi = days * 10; | |
| allowedHotel = hotelDays * 90; | |
| //total expenses | |
| totalExp = airfare + vehicleExpense + carRental + parking + taxi + | |
| confCost + hotelCost + mealCost + hotelCost; | |
| //total amount covered by company | |
| totalAllowedExp = allowedParking + allowedTaxi + allowedHotel + allowedMeals; | |
| //total debt | |
| userFees = parking + taxi + hotelDebt + mealDebt; | |
| //calculate total must reimburse to company or amount saved | |
| if (totalAllowedExp > userFees) | |
| { | |
| amountSaved = totalAllowedExp - userFees; | |
| } | |
| else | |
| { | |
| reimburse = userFees - amountSaved; | |
| } | |
| //display individual totals | |
| cout << "\nAirfare expense: $" << airfare << endl; | |
| cout << "Car rental expense: $" << carRental << endl; | |
| cout << "Private vehicle gas expense: $" << vehicleExpense << endl; | |
| cout << "Parking expense: $" << parking << endl; | |
| cout << "Taxi expense: $" << taxi << endl; | |
| cout << "Conference expense: $" << confCost << endl; | |
| cout << "Hotel expense: $" << hotelCost << endl; | |
| cout << "Meal expense: $" << mealCost << endl; | |
| cout << "----------------------------------\n"; | |
| //display totals | |
| cout << "Total expenses incurred: $" << totalExp << endl; | |
| cout << "Total allowable expenses: $" << totalAllowedExp << endl; | |
| cout << "Amount to be reimbursed: $" << reimburse << endl; | |
| clearMeal(meal, days); //meal array clean up | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment