Write a program to assist travelers in completing their travel expense claim. Wh
ID: 3822820 • Letter: W
Question
Write a program to assist travelers in completing their travel expense claim. When you travel for business your company will reimburse you for your travel expenses. To be reimbursed, you must submit a claim that specifies the expenses incurred on each day of travel in various categories. For this program, we will have 6 categories: Airfare, Hotel, Breakfast, Lunch, Dinner, and Taxi. You can create a 2-D array to define these categories: char category[6][10] = {"Airfare", "Hotel", "Breakfast", "Lunch", "Dinner", "Taxi"}; We will assume that you can travel up to 30 days. You should create a two-dimensional array to store the expenses per day in each category. Program Requirement: Prompt the user for the actual number of days traveled. For each day, prompt the user for the expenses in each category and store the expenses in your 2-D array. Compute the total expenses per day and store that in another array variable. Compute the total expenses per category and store that in another array variable. Check to see if the sum of the total expenses per day is equal to the sum of the total expenses per category. If not, it should display: "Internal error: total daily sum does not match total category sum." This is an internal error because if you implement your program properly, the sums should be equal. These sums equal the expense claim total. Note, since you should be using float to store your costs, you cannot directly compare the two sums as there may be round-off errors when summing floating point numbers. Thus, you need to check that the two sums differ by less than some epsilon. Since we are dealing with money, a reasonable epsilon would be 0.009. Prompt the user to view various aspects of the expense claim including: expense claim total, category totals, daily totals, and expense claim details (actual expenses per day in each category). It should also offer the option to exit. Here are some sample screen shots of the program running (assuming a person is traveling for 2 days with one hotel stay). You can use your own style for the interface but the functionality should be the same.Explanation / Answer
Hi,
Please find below the c++ code for the above given problem-
C++ Code-
#include <iostream>
using namespace std;
int main()
{
char category[6][10]={"Airfare","Hotel","Breakfast","Lunch","dinner","Taxi"};
int i,j,n,arr[10][6],s=0,s1=0,rowsum=0,colsum=0;
cout << "Enter the number of days travelled" << endl;
cin>>n;
cout<<"Enter the Expenses"<<endl;
for(i=0;i<n;i++){
cout<<"Day: "<<i<<endl;
for(j=0;j<6;j++) {
cout<<"Expense type :"<<category[j]<<endl;
cin>>arr[i][j];
}
}
cout<<"The elements you entered are:"<<endl;
for(i=0;i<n;i++){
for(j=0;j<6;j++) {
cout<<arr[i][j]<<endl;
}
//This is to sum each row
for(i=0;i<n;i++)
{for(j=0;j<6;j++)
s=s+arr[i][j];
cout<<"sum of "<<i+1<<" Row is"<<s;
rowsum+=s;
s=0;
cout<<endl;
}
cout<<endl;
//This is to sum each column
for(i=0;i<6;i++)
{for(j=0;j<n;j++)
s1=s1+arr[j][i];
cout<<"sum of "<<i+1<<" Column is"<<s1;
colsum+=s1;
s1=0;
cout<<endl;
}
cout<<" The overall Row sum of all rows is : "<<rowsum<<endl;
cout<<" The overall Column sum of all columns is : "<<colsum<<endl;
if(rowsum==colsum)
{
cout<<"Your total expenses have matched"<<endl;
}
else {
cout<<"Internal Error :total daily sum does not match with total category sum";
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.