Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c++ Assignment 3 Problem Travel Expenses using functions: Write a program tha

ID: 3775840 • Letter: I

Question

In c++

Assignment 3

Problem Travel Expenses using functions:

Write a program that calculates and displays the total travel expenses of a businessperson on a trip. The program should declare all variables in the main function and then call the functions to ask for and return the following:

The total number of days spent on the trip

The time of departure on the first day of the trip, and the time of arrival back home on the last day of the trip

The amount of any round-trip airfare

The amount of any car rentals

Miles drive, if a private vehicle was used. Calculate the vehicle expense as $0.50 per km driven.

Parking fees (The company allows up to $10 per day. Anything in excess of this must be paid by the employee.)

Taxi fees, if a taxi was used anytime during the trip (The company allows up to $20 per day, for each day a taxi was used. Anything in excess of this must be paid by the employee.)

Conference or seminar registration fees

Hotel expenses (The company allows up to $90 per night for lodging. Anything in excess of this must be paid by the employee.)

The amount of each meal eaten. On the first day of the trip, breakfast is allowed as an expense if the time of departure is before 7am. Lunch is allowed if the time of departure is before 12 noon. Dinner is allowed on the first day if the time of departure is before 6pm. On the last day of the trip, breakfast is allowed if the time of arrival is after 8am. Lunch is allowed if the time of arrival is after 1pm. Dinner is allowed on the last day if the time of arrival is after 7pm. The program should only ask for the amounts of allowable meals. (The company allows up to $9 for breakfast, $12 for lunch, and $16 for dinner. Anything in excess of this must be paid by the employee.)

The program should calculate and display the total expenses incurred by the businessperson, the total allowable expenses for the trip, the excess that must be reimbursed by the businessperson, if any, and the amount saved by the businessperson if the expenses were under the total allowed.

Input Validation: Do not accept negative numbers for any dollar amount or for miles driven in a private vehicle. Do not accept numbers less than 1 for the number of days. Only accept valid times for the time of departure and the time of arrival.

What to hand in:

Copy your source code into your Word document

Several runs to show your program works with valid and invalid data

A User Guide for the “businessperson”

A hierarchy chart to show the relationship of your functions.

Prototypes may look like the following:

// Function prototypes

int   daysSpent();

void times(double &, double &);

bool isValidTime(double);

double airFare();

double carRental();

double vehicle();

double parking(int);

double taxi(int);

double registration();

double hotel(int);

double meals(int, double, double);

double getBreakfast();

double getLunch();

double getDinner();

// Global variable to hold total expenses of employee

double totalExpenses = 0;

?

CA. C: WINDOWSsystem32Acmd.exe How many days were spent on the trip? 3 Enter the departure time CHH.MM 11.30 Enter the return time KHH.MM 6.30 Enter the amount of airfare 300.50 Enter the amount of car rental fees 400.40 Enter the miles driven by a private vehicle Enter the amount of parking fees 45 Enter the amount of taxi fees 72 Enter the amount of registration fees 456 Enter the nightly hotel rate 300.50 Day 1: Enter the amount spent for lunch: 15 Day 2 Enter the amount spent for breakfast 20 Enter the amount spent for lunch: 15 Enter the amount spent for dinner: 22 ay 3 o meals allowed due to return before 8:00 a.m. Total expenses: $1944.90 llowable expenses: $1433.90 mount to be reimbursed $511.00 Press any key to continue

Explanation / Answer

Answer:-

Travel Expenses Program :

#include <iostream>
#include <iomanip>

using namespace std;

int getDays(int);
void getTime (double&, double&);
double getAirfareAmount(double);
double getCarRentalAmount (double);
double getPrivateVechileExpense(double);
void getParkingAmount(double&,double&);
void getTaxiAmount(double&,double&);
double getRegistrationFee(double);
void getHotelAmount(double&,double&);
void getMealAmount (double&,double&);


//The main function which will call other functions for the travel expenses
//For the sake of calculations the depart and arrival time will use military
//time for depart and arrival time.
int main()
{

int days;
double arrivalTime;
double departureTime;
double airfareFee;
double carRentalFee;
double privateCarFee;
double vechileExpense;
double privateCarMilage = .38;
double parkingFee;
double taxiFee;
double registrationFee;
double spentTotal;//Overall total cost
double allowedTotal;
double companyTotal;
double mealTotal;
double total;
double allowedParking;
double allowedTaxiFee;
double hotelFee;
double nightlyRate;
double allowedHotelFee;
double hotelFeeTotal;
double allowedBreaksfastFee;
double allowedLunchFee;
double allowedDinnerFee;
double breaksfastFee;
double lunchFee;
double dinnerFee;
double allowedMealTotal;
string employeeName;
int d;
double parkingSpent;
double taxiSpent;
double spentMealTotal;
  
cout<<setw(20)<<"Employee Expense Report"<<endl;
cout<<setw(20)<<"________________________"<<endl<<endl;
  
cout<<"Employee Name: ";
cin >>employeeName;
cout<<endl;
  
days = getDays(days);
d = static_cast<int>(days);
cout<<endl;
  
getTime (departureTime,arrivalTime);
cout<<endl;
  
cout <<"TRAVEL "<<endl;
cout <<"--------"<<endl;
airfareFee = getAirfareAmount(airfareFee);
carRentalFee = getCarRentalAmount(carRentalFee);
getPrivateVechileExpense(privateCarFee);
allowedParking = 6 * days;
getParkingAmount(parkingSpent, allowedParking);
allowedTaxiFee = 10 * days;
getTaxiAmount (taxiSpent,allowedTaxiFee);
cout <<endl;
  
cout <<"FEE"<<endl;
cout <<"---"<<endl;
registrationFee= getRegistrationFee(registrationFee);
hotelFeeTotal = days * nightlyRate;
allowedHotelFee = 90 * days;
getHotelAmount (hotelFeeTotal,allowedHotelFee);
cout<< endl;
  
cout <<"MEAL"<<endl;
cout <<"----"<<endl;
allowedBreaksfastFee = 9.00 * days;
allowedLunchFee = 12.00 * days;
allowedDinnerFee = 16.00 * days;
allowedMealTotal = allowedBreaksfastFee+allowedLunchFee+allowedDinnerFee;
mealTotal= breaksfastFee +lunchFee +dinnerFee;
getMealAmount (allowedMealTotal,spentMealTotal);
cout<<endl;

//calc total
spentTotal=airfareFee+carRentalFee+vechileExpense+parkingFee+taxiFee+registrationFee+hotelFee+privateCarMilage+mealTotal;
allowedTotal= airfareFee+privateCarMilage+carRentalFee+allowedParking+allowedTaxiFee+allowedMealTotal+allowedHotelFee;

//Display totals for the traveler
cout <<"Employee Expense Report for "<<employeeName<<endl<<endl;
cout << "Total Days of trip: "<<days<<endl;
cout << fixed << setprecision(2);
cout << "Departure time: "<< departureTime<<setw(20)<<"Arrival time: " <<arrivalTime<<endl;
cout <<setw(8)<<setprecision(2)<<showpoint<<fixed;
cout<<endl;
cout << setw(29)<<"Spent"<<setw(20)<< "Allowed"<<endl;
cout << setw(30)<<"_________"<<setw(20)<<"_________"<<endl;
cout <<"Airfare"<<setw(20)<<airfareFee<<setw(20)<<airfareFee<<endl;
cout <<"Car Rental"<<setw(17)<<carRentalFee<<setw(20)<<carRentalFee<<endl;
cout <<"Milage"<<setw(21)<<privateCarMilage<<setw(20)<<privateCarMilage<<endl;
cout <<"Parking"<<setw(20)<<parkingFee<<setw(20)<<allowedParking<<endl;
cout <<"Taxi"<<setw(23)<<taxiFee<<setw(20)<<allowedTaxiFee<<endl;
cout <<"Registration"<<setw(15)<<registrationFee<<setw(20)<<registrationFee<<endl;
cout <<"Hotel"<<setw(22)<<hotelFeeTotal<<setw(20)<<allowedHotelFee<<endl;
cout <<"Meal"<<setw(23)<<spentMealTotal<<setw(20)<<allowedMealTotal<<endl;
cout << setw(30)<<"_________"<<setw(20)<<"_________"<<endl;
cout <<"TOTALS"<<setw(21)<<spentTotal<<setw(20)<<allowedTotal<<endl;
cout <<endl<<endl;

system ("pause");
return 0;
}

//Function that asks the user how many days were spent on the trip
int getDays(int days)
{
cout << "How many days were spent on the trip?" << endl;
cin >> days;
  
while (days < 1)
{
cout << "Please enter a number greater than 1" << endl;
cin >> days;
}
  
return days;
}

//Function that is used to ask the user the departure time for the trip
void getTime (double &departureTime, double &arrivalTime)
{
cout << "At what time did you depart for the trip? (00.00 format)" ;
cin >> departureTime;
cout <<endl;

while ( departureTime <0 || departureTime > 23.59)
{
cout << "Error: Please enter a number between 00.00 and 23.59";
cin >> departureTime;
}
  
cout << "At what time did you arrive for the trip? (00.00 format)" ;
cin >> arrivalTime;

while ( arrivalTime <0 || arrivalTime > 23.59)
{
cout << "Error: Please enter a number between 00.00 and 23.59";
cin >> arrivalTime;
}
}

//Function thats used for airplane travel expenses
double getAirfareAmount (double airfareFee)
{
cout << "What was the total cost of the air fare?" << endl;
cin >> airfareFee;
// Input validation for the aiplane travel
while (airfareFee < 0)
{
cout << "Error: Please enter a number greater than 0. Try again!" << endl;
cin >> airfareFee;
}

return airfareFee;
}
//Function for car rental
double getCarRentalAmount (double carRentalFee)
{
cout << "What was the total cost of any car rentals?" << endl;
cin >> carRentalFee;
//Input validation for the car rental amount
while (carRentalFee < 0)
{
cout << "Error:Please enter a number greater than 0. Try Again!" << endl;
cin >> carRentalFee;
}

return carRentalFee;
}

//Function for private vehicle usage
double getPrivateVechileExpense (double privateCarFee)
{
const double RATE = 0.38;
double miles;

cout << "Were any miles driven in a private vehicle?" << endl;
cin >> miles;
//validation for private vehichle usage
while (miles < 0)
{
cout << "Error:Please enter a value greater than 0. Try again!" << endl;
cin >> miles;
}

privateCarFee = miles * RATE;

return privateCarFee;
}

//Function for parking fee totals
void getParkingAmount(double &parkingSpent, double &allowedParking)
{
int days;
double parkingFee;
  
cout << "How much was spent on parking?" << endl;
cin >> parkingFee;

//input validation for parking fee totals
while (parkingFee < 0)
{
cout << "Error:Please enter a positive number. Try again!" << endl;
cin >> parkingFee;
}

parkingSpent = days * parkingFee;
allowedParking = days * 6;
}
  
//Function for total taxi fees
void getTaxiAmount (double &taxiSpent, double &allowedTaxiFee)
{
double taxiFee;
int days;
cout << "How much was spent on taxi fare?" << endl;
cin >> taxiFee;
//Input validation
while (taxiFee < 0)
{
cout << "Error: Enter a positive number. Try again!" << endl;
cin >> taxiFee;
}

taxiSpent = days * taxiFee;
allowedTaxiFee = 6 * days;
}

//Function for conference fees for the traveler.
double getRegistrationFee (double registrationFee)
{
cout << "How much was spent on conference fees?" << endl;
cin >> registrationFee;

while (registrationFee < 0)
{
cout << "Error: Enter a positive number. Try again!" << endl;
cin >> registrationFee;
}

return registrationFee;
}   
  
//Function for total hotel cost
void getHotelAmount (double &allowedHotelFee, double &hotelFeeTotal)
{
int days;
double hotelFee;
cout << "How much was spent on hotel rooms?" << endl;
cin >> hotelFee;

while (hotelFee < 0)
{
cout << "Error:Enter a positive number. Try again!" << endl;
cin >> hotelFee;
}
allowedHotelFee = 90 * days;
hotelFeeTotal= hotelFee * days;
}

//Function for meal totals
void getMealAmount(double &allowedMealTotal,double &spentMealTotal)
{
int days;
int numDays;
double breakfast;
double lunch;
double dinner;
double firstDay;
double lastDay;
double departureTime;
double arrivalTime;
double allowedBreaksfastFee;
double allowedLunchFee;
double allowedDinnerFee;
double breakfastFee;
double lunchFee;
double dinnerFee;
  
for(int days = 1; days <= numDays; days++)
{   
cout << "Day:" << days << endl;
  
if (days < 2 && departureTime > 00.00 && departureTime <= 7.00)
{
cout << "Enter the cost of breakfast: ";
cin >> breakfastFee;
cout << "Enter the cost of lunch: ";
cin >> lunchFee;
cout << "Enter the cost of dinner: ";
cin >> dinnerFee;
}
  
if (days < 2 && departureTime > 7.01 && departureTime <=12.00)
{
cout << "Enter the cost of lunch: ";
cin >> lunchFee;
cout << "Enter the cost of dinner: ";
cin >> dinnerFee;
}
  
if (days < 2 && departureTime > 12.01 && departureTime <=18.00)
{
cout << "Enter the cost of dinner: ";
cin >> dinnerFee;
}
if (days > 1 && days < numDays )
{
cout << "Enter the cost of breakfast: ";
cin >> breakfastFee;
cout << "Enter the cost of lunch: ";
cin >> lunchFee;
cout << "Enter the cost of dinner: ";
cin >> dinnerFee;
}
  
if (days == numDays && arrivalTime > 8.00 && arrivalTime <= 13.00)
{
cout << "Enter the cost of breakfast: ";
cin >> breakfastFee;
  
}
  
if (days == numDays && arrivalTime > 13.01 && arrivalTime <= 19.00)
{
cout << "Enter the cost of breakfast: ";
cin >> breakfastFee;
cout << "Enter the cost of lunch: ";
cin >> lunchFee;
}
  
if (days == numDays && arrivalTime > 19.01)
{
cout << "Enter the cost of breakfast: ";
cin >> breakfastFee;
cout << "Enter the cost of lunch: ";
cin >> lunchFee;
cout << "Enter the cost of dinner: ";
cin >> dinnerFee;
}
cout <<endl;
}
allowedBreaksfastFee = 9.00 * days;
allowedLunchFee = 12.00 * days;
allowedDinnerFee = 16.00 * days;
allowedMealTotal = allowedBreaksfastFee+allowedLunchFee+allowedDinnerFee;
spentMealTotal= breakfastFee +lunchFee +dinnerFee;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote