Question

In: Computer Science

Please fulfill the requirements. Thank you Objectives: Perform C++ string object manipulation Understand how to manipulate...

Please fulfill the requirements. Thank you

Objectives:

  • Perform C++ string object manipulation
  • Understand how to manipulate data using arrays
  • Handle input errors and invalid values
  • Design and create a well-structured program using C++ basic programming constructs

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

It allows the user to select a menu option to display all expenses, add new entry, search for a substring and find the list of entries greater a given amount.

Requirements:

  1. The program must produce similar output as example below. 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.
  4. 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
  5. You should not use data file to save or read from. All operations should be done through the use of arrays and array indices.
  6. You must write at least 2 functions.
  7. Do not use namespace std

Required error handling:

The program MUST perform the following checks:

  1. Check for invalid amount (negative or 0 number)
  2. Description cannot be empty.
  3. Search is case-insensitive (ignore case, but the user may type in any case).

Sample run:

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 greater than or equal to this amount

5. exit

Enter your option: 2

Please enter the description for the expense: Monthly electric, water and gas

Please enter the amount: 200.20

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: 2

Please enter the description for the expense: Rent

Please enter the amount: 1200

AMOUNT(1200) DESC(Rent)

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: Netflix membership

Please enter the amount: 12.90

AMOUNT(12.9) DESC(Netflix 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: 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 amount

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)

AMOUNT(1200) DESC(Rent)

AMOUNT(12.9) DESC(Netflix membership)

AMOUNT(99) DESC(Amazon membership)

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 amount

5. exit

Enter your option: 3

Please enter the search string: membership

AMOUNT(12.9) DESC(Netflix membership)

AMOUNT(99) DESC(Amazon membership)

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 amount

5. exit

Enter your option: 3

Please enter the search string: MEMBERSHIP

AMOUNT(12.9) DESC(Netflix membership)

AMOUNT(99) DESC(Amazon membership)

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 amount

5. exit

Enter your option: 4

Please enter the amount: 50

AMOUNT(200.2) DESC(Monthly electric, water and gas)

AMOUNT(1200) DESC(Rent)

AMOUNT(99) DESC(Amazon membership)

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 amount

5. exit

Enter your option: 4

Please enter the amount: 200

AMOUNT(200.2) DESC(Monthly electric, water and gas)

AMOUNT(1200) DESC(Rent)

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: 1000

AMOUNT(1200) DESC(Rent)

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: Home repair and improvement

Please enter the amount: -1

Invalid amount. Amount cannot be negative or string. Please try it again.

Please enter the amount: -100

Invalid amount. Amount cannot be negative or string. Please try it again.

Please enter the amount: -1000

Invalid amount. Amount cannot be negative or string. Please try it again.

Please enter the amount: 175.75

AMOUNT(175.75) DESC(Home repair and improvement)

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

Expenses:

AMOUNT(45.25) DESC(Monthly telephone and Internet services)

AMOUNT(200.2) DESC(Monthly electric, water and gas)

AMOUNT(1200) DESC(Rent)

AMOUNT(12.9) DESC(Netflix membership)

AMOUNT(99) DESC(Amazon membership)

AMOUNT(50) DESC(Monthly gym membership)

AMOUNT(175.75) DESC(Home repair and improvement)

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: 5

D:\>

Solutions

Expert Solution

#include<bits/stdc++.h>
using namespace std;

struct data{
double amount;
vector<string> desc;
};

void printDesc(vector<string> &desc)
{
int i,n=desc.size();
for(i=0;i<n;i++)
{
cout<<desc[i]<<" ";
}
}

void showAll(vector<data> &arr)
{
int i,j,k,n=arr.size();
if(n==0)
{
cout<<"There is no expense entry available\n";
return;
}
for(i=0;i<n;i++)
{
  
cout<<"AMOUNT("<<arr[i].amount<<") DESC(";
printDesc(arr[i].desc);
cout<<")\n";
}
}

void split_string(string& des,vector<string>& desc_arr)
{
int i=0,n=des.length();
while(i<n)
{
string temp="";
while(i<n && des[i]!=' ')
{
temp+=des[i];
i++;
}
desc_arr.push_back(temp);
i++;
}
}

void spend(vector<data> &arr)
{
string des;
double amt;
cout<<"Please enter the description for the expense:";
cin.ignore();
getline(cin,des);
while(des=="")
{
cout<<"Please enter the description for the expense:";
   getline(cin,des);
   }
vector<string> desc_arr;
split_string(des,desc_arr);
cout<<"Please enter the amount:";
cin>>amt;
while(amt<=0.0)
{
cout<<"Invaid amountAmount cannot be negative or string. Please try it again.\n";
cout<<"Please enter the amount:";
       cin>>amt;
}
cout<<"AMOUNT("<<amt<<") DESC("<<des<<")\n";
data newData {amt,desc_arr};
arr.push_back(newData);
}

void searchAmount(vector<data> &arr)
{
int i,j,n=arr.size();
double amt;
cout<<"Enter Amount: "
cin>>amt;
for(i=0;i<n;i++)
{
if(amt<=arr[i].amount)
{
cout<<"AMOUNT("<<arr[i].amount<<") DESC(";
printDesc(arr[i].desc);
cout<<")\n";
}
}
}


bool search(string& str,vector<string>& des)
{
int i,n=des.size();
for(i=0;i<n;i++)
{
string temp = des[i];
transform(temp.begin(),temp.end(),temp.begin(),::tolower);
if(temp==str)
return true;   
}
return false;
}

void searchString(vector<data> &arr){
cout<<"Please Enter the String Search\n";
string str;
cin>>str;
transform(str.begin(),str.end(),str.begin(),::tolower);
int i,n=arr.size();
for(i=0;i<n;i++)
{
bool found = search(str,arr[i].desc);
if(found){
cout<<"AMOUNT("<<arr[i].amount<<") DESC(";
printDesc(arr[i].desc);
cout<<")\n";
}
}
  
}


int main()
{
vector<data> arr;
while(1)
{
int opt;
cout<<"1.show all\n";
cout<<"2.spend\n";
cout<<"3.search expenses containing this string\n";
cout<<"4. search expenses with greater than or equal to this amount\n";
cout<<"5.exit\n";
cout<<"Enter your option: ";
cin>>opt;
if(opt==1)
{
showAll(arr);
}else if(opt==2)
{
spend(arr);
}else if(opt==3)
{
searchString(arr);
}else if(opt==4)
{
searchAmount(arr);
}else if(opt==5){
break;
}else{
cout<<"Invalid input\n";
}
  
}
}


Related Solutions

Please Please fulfill the requirements and error handling and make this in basic C++ construct Thank...
Please Please fulfill the requirements and error handling and make this in basic C++ construct Thank you!! Objectives: Perform C++ string object manipulation Understand how to manipulate data using arrays Handle input errors and invalid values Design and create a well-structure program using C++ basic programming constructs Description: Write a menu-driven program that provides the following options: Show All Spend Search expenses containing this string Search expenses with greater than or equal to this amount Exit It allows the user...
(Please do not attempt to solve if you can not fulfill all the requirements!!!!) THE ENERGY...
(Please do not attempt to solve if you can not fulfill all the requirements!!!!) THE ENERGY BAR INDUSTRY In 1986, PowerBar, a firm in Berkeley, California, single-handedly created the energy bar category. Positioned as an athletic energy food, it was distributed at bike shops and events that usually involved running or biking. The target segment was the athlete who needed an efficient, effective energy source. Six years later, seeking to provide an alternative to the sticky, dry nature of the...
Feasibility Report (Please do not attempt to solve if you can not fulfill all the requirements)...
Feasibility Report (Please do not attempt to solve if you can not fulfill all the requirements) After reviewing my cover page, table of contents, introduction, purpose and overview report please complete the BODY part. Purpose        Feasibility reports are a yardstick to measure solutions which lead to a recommended course of action. These through investigations, to determine the viability and practicality of the proposal, are necessary to minimize organizational risk and minimize risks. When proposing a product, service, strategy, initiative, program,...
Note: Please do not attempt to solve this assignment if you cannot fulfill all the requirements,...
Note: Please do not attempt to solve this assignment if you cannot fulfill all the requirements, review the "sample" journal and create the new one using the same format!!! Write journal entry on a topic of your choice from any optional reading you may have done. You may write on any concept or insight that stands out to you that is relevant and useful to your life and work. You will write a journal entry of about one page describing...
(Please show work so I can understand how you got to the answer - Thank you...
(Please show work so I can understand how you got to the answer - Thank you very much ) Via Gelato is a popular neighborhood gelato shop. The company has provided the following data concerning its operations: Fixed Element per Month Variable Element per Liter Actual Total for June Revenue $ 13.00 $ 72,540 Raw materials $ 4.75 $ 30,330 Wages $ 5,700 $ 1.50 $ 14,560 Utilities $ 1,730 $ 0.30 $ 3,800 Rent $ 2,700 $ 2,700 Insurance...
I need to update this program to follow the these requirements please and thank you :...
I need to update this program to follow the these requirements please and thank you : Do not use packages Every class but the main routine class must have a toString method . The toString method for Quadrilateral should display its fields: 4 Points. All instance variables should be declared explicitly private . Area incorrect : enter points no: 1 1 3 enter points no: 2 6 3 enter points no: 3 0 0 enter points no: 4 5 0...
Can someone please explain these problems, I don't understand, please and thank you!! The patients in...
Can someone please explain these problems, I don't understand, please and thank you!! The patients in the Digoxin trial dataset can be considered a population of people suffering from heart failure. These patients were examined before the drug trial began, and their heart rate and blood pressure were recorded. The mean and standard deviation of the variables are listed below. Each variable follows a normal distribution. Heart rate (beats/min)                          μ = 78.8            σ = 12.66 Systolic blood pressure (mmHg)             μ...
Could you give me an answer as fast as you can? Please..! Thank You! Learning Objectives:...
Could you give me an answer as fast as you can? Please..! Thank You! Learning Objectives: Appendix E Analyze and report investments in held-to-maturity debt securities Analyze and report investments in available-for-sale securities Analyze and report investments in affiliated companies using the equity method Analyze and report controlling interests in other corporations using consolidated financial statements Report investing activities on the statement of cash flows Explain the impact of the time value of money on certain types of investments EXAMPLE...
Could you give me an answer as fast as you can. Please..! Thank You! Learning Objectives:...
Could you give me an answer as fast as you can. Please..! Thank You! Learning Objectives: CHAPTER 7 Measure and account for the cost of plant assets Distinguish a capital expenditure from an immediate expense Measure and record depreciation on plant assets Analyze the effect of a plant asset disposal Apply GAAP for natural resources and intangible assets Explain the effect of an asset impairment on the financial statements Analyze rate of return on assets Analyze the cash flow impact...
Could you give me an answer as fast as you can? Please..! Thank You! Learning Objectives:...
Could you give me an answer as fast as you can? Please..! Thank You! Learning Objectives: CHAPTER 7 Measure and account for the cost of plant assets Distinguish a capital expenditure from an immediate expense Measure and record depreciation on plant assets Analyze the effect of a plant asset disposal Apply GAAP for natural resources and intangible assets Explain the effect of an asset impairment on the financial statements Analyze rate of return on assets Analyze the cash flow impact...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT