Question
I need help writing this code in C++ and I’m using xcode for mac
bjectives: . Perform C++ string object manipulation Understand how to manipulate data using arrays of structs Handle input er

D:>TrackExpensesUsingArray.exe Welcome to my expense tracker. Expense Tracking Menu: 1. show all 2. spend 3. search expenses

el thah or eg Enter your opeion: 2 Please enter the description for the expense: Monshly eleat and gas Please enter the amoun

SlILp) Expense Tracking Menu: 1. show all 2. spend 3. search expenses containing this string 4. search expenses with greater

media%2F086%2F086b0fde-fff6-4db2-a724-4b


Expense Tracking Menu: 1. show all 2. spend 3. search expenses containing this string 4. search expenses with greater than or

media%2F1b0%2F1b08406c-9913-4448-beef-03

media%2Fb44%2Fb44f0898-b42f-4f35-934e-e2

the objective is in the first picture and the rest is a sample output of the code thaf needs to be similar
bjectives: . Perform C++ string object manipulation Understand how to manipulate data using arrays of structs Handle input errors and invalid values Design and create a wel-structure program using C++ basic programming constru Description: Write a menu-driven program that provides the following options 1. Show All 2. Spend 3. Search expenses containing this string 4 Search expenses with greater than or equal to this amount 5. Exit substring and find the list of entries greater a given amount. Requirements: t allows the user to select a menu option to display all expenses, add new entry, search for a 1. The program must produce the same output as provided. The output should be formatted nicely as given. 2. The program must use array of structs 3. The program must not use global variables. In another words, it must use local variables and pass-by-value or pass-by-reference parameters The program must define the maximum number of entries such as 100 and keeps track of the actual count of the current number of expenses entered by the user You should use data file to save or read from. At the beginning of your program, it reads 4. 5. data from a data file named "expenses.txt" and initialize your array with this data. Your program must check to see if the file exists or has data to read. Before your program exits, it must save all expenses amount and descriptions into the data file. You must write at least 2 functions. You need to submit both your program and data file "expensos.txt" 6. 7. Required error handling: The program MUST perform the following checks: ria 1. Check for invalid amount (negative or O number) 2. Description cannot be empty 3. Search is case-insensitive uiremen nd block c
D:>TrackExpensesUsingArray.exe Welcome to my expense tracker. Expense Tracking Menu: 1. show all 2. spend 3. search expenses containing this string 4. search expenses with greater than or equal to this amount 5. exit Enter your option: 1 There is no expense entry available. Expense Tracking Menu: 1. show all 2. spend 3. search expenses containing this string 4. search expenses with greater than or equal to this amount 5. exit Enter your option: 2 Please enter the description for the expense: Monthly telephone and Internet services Please enter the amount: 45.25 AMOUNT (45.25) DESc (Monthly telephone and Internet services) Expense Tracking Menu: 1. show all 2. spend 3. search expenses containing this string 4. search expenses with greaten than or equal to this anount 5. exit Enter your option: 2
el thah or eg Enter your opeion: 2 Please enter the description for the expense: Monshly eleat and gas Please enter the amount: 200.20 AMOUNT (200.2) DESC (Monthly electric, water and gas) Expense Tracking Menu: 1. show all 2. spencd 3. search expenses containing this string 4 search expenses with greater than or equal to this amount 5. exit Enter your option: 2 Please enter the amount: 1200 MOUNT (1200) DESC (Rent) Expense Tracking Menu: 1, show all 21 spend 3. search expenses containing this string 4. search expenses with greater than or equal to this anount 5. exit Enter your option: 2 Please enter the description for the expense: Netflix menbershi Please enter the amount: 12.90 DESC (Netflix membership) EXwEL12.9) Expense Tracking Menu: 1. show all 걱.
SlILp) Expense Tracking Menu: 1. show all 2. spend 3. search expenses containing this string 4. search expenses with greater than or equal to this amount 5. exit Enter your option: 2 Please enter the description for the expense: Amazon membership Please enter the amount: 99 AMOUNT (99) DESC (Amazon membership) Expense Tracking Menu: 1. show all 2. spend 3. search expenses containing this string 4. search expenses with greater than or equal to this amount 5. exit Enter your option: 2 Please enter the description for the expense: Monthly gym membership Please enter the amount: 50 AMOUNT (50) DESC (Monthly gym membership) Expense Tracking Menu: 1. show all 2. spend 3. search expenses containing this string 4. search expenses with greater than or equal to this amo 5. exit Enter your option: 1 Expenses: AMOUNT (45.25) DESC (Monthly telephone and Internet services) AMOUNT (200.2) DESC (Monthly electric, water and gas)

Expense Tracking Menu: 1. show all 2. spend 3. search expenses containing this string 4. search expenses with greater than or equal to this amount 5. exit Enter your option: Please enter the amount: 50 AMOUNT (200.2) DESC (Monthly electric, water and gas) AMOUNT (1200) DESC (Rent) MOUNT (99) DESC (Amazon membership) MOUNT (50) DESC (Monthly gym membership) Expense Tracking Menu: 1. show all 2. spend 3. search expenses containing this string 4. search expenses with greater than or equal to this amount 5. exit Enter your option: 4 Please enter the amount: 200 AMOUNT (200.2) DESC (Monthly electric, water and gas) MOUNT (1200) DESsc (Rent) EsPSnRS.Txaskina.Menu... . show all 2. spend 3. search expenses containing this string 4. search expenses with greater than or equal to this amount 5. exit Enter your option: 4 Please enter the amount: 1000 1200) DESC (Rent)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <cstdlib>
using namespace std;
struct expenses
{
string desc;
double amount;
};
void show_all(expenses *exp, int n)
{
int i = 0;
if (n == 0)
cout << "\nThere is no expense entry available\n"
<< endl;
else
{
cout << "Expenses: " << endl;
while (i < n)
{
cout << "AMOUNT(" << exp[i].amount << ") DESC(" << exp[i].desc << ")" << endl;
i++;
}
}
}
void spend(expenses *exp, int n)
{
double amount;
string desc;
getline(cin, exp[n].desc);
while (1)
{
cout << "Please enter the description for the expense: ";
getline(cin, exp[n].desc);
if (exp[n].desc != "")
break;
cout << "Invalid Description. Description cannot be empty" << endl;
}
char am[100];
while (1)
{
cout << "Please enter the amount: ";
cin >> am;
exp[n].amount = atof(am);
if (exp[n].amount > 0)
break;
cout << "Invalid amount. Amount cannot be negative or string. Please try it again." << endl;
}
cout << "AMOUNT(" << exp[n].amount << ") DESC(" << exp[n].desc << ")" << endl;
}
void search_amount(expenses *exp, int n)
{
int i = 0, search;
cout << "Please enter the amount:";
cin >> search;
while (i < n)
{
if (exp[i].amount >= search)
{
cout << "AMOUNT(" << exp[i].amount << ") DESC(" << exp[i].desc << ")" << endl;
}
i++;
}

}
void search_desc(expenses *exp, int n)
{
string search;
cout << "Please enter the search string: ";
cin >> search;
int i = 0, j, k;
j = 0;
while (j < search.length())
{
search[j] = tolower(search[j]);
j++;
}
while (i < n)
{
string d_str = exp[i].desc;
j = 0;
while (j < exp[i].desc.length())
{
d_str[j] = tolower(d_str[j]);
j++;
}
if (exp[i].desc.find(search) != string::npos)
{
cout << "AMOUNT(" << exp[i].amount << ") DESC(" << exp[i].desc << ")" << endl;
}
i++;
}
}
int main()
{
int option, n = 0;
expenses exp[100];
cout<<"Welcome to my expense tracker.\n"<<endl;
do
{
cout << "\nExpense Tacking Menu:" << endl;
cout << "\t1. show all\n\t2. spend\n\t3. search expenses containing this string\n\t4. search expenses with greater than or equal to this amount\n\t5. exit" << endl;
cout << "Enter your option: ";
cin >> option;
switch (option)
{
case 1:
show_all(exp, n);
break;
case 2:
spend(exp, n);
n++;
break;
case 3:
search_desc(exp, n);
break;
case 4:
search_amount(exp, n);
break;
case 5:
exit(0);
break;
default:
cout << "Invalid choice" << endl;
}
} while (option != 5);
}

screenshot:

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
I need help writing this code in C++ and I’m using xcode for mac the objective...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
Share Your Knowledge

Post an Article +5 Coins

Post an Answer +5 Coins

Post a Question with Answer +5 Coins

ADVERTISEMENT