Question

In: Computer Science

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:

  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.

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 <iostream>

#include <string>

#include <algorithm>

using namespace std;

struct expense

{

string Desc;

double exp;

};

expense arr[100];

int c = 0;

void menu();

//1. show all

void showArray(){

if (c>0){

for(int i=0;i<c;i++){

cout<<"AMOUNT("<<arr[i].exp<<") DESC"<<arr[i].Desc<<")"<<endl;

}

}else{

cout<<"There is no expense entry available";

}

menu();

}

//2. spend

void addArray(){

string desc;

double exp;

cout<<"Please enter the description for the expense: ";

cin>>desc;

cout<<"Please enter the amount: ";

cin>>exp;

if(desc!="" && exp>0){

c++;

arr[c]= {desc,exp};

}else{

cout<<"Please Enter valid entries";

addArray();

}

menu();

}

//3. search expenses containing this string

void searchDesc(){

string s1;

cout<<"Please enter the search string:";

cin>>s1;

transform(s1.begin(),s1.end(),s1.begin(),::tolower);

for(int k=0;k<c;k++){

string s2 = arr[k].Desc;

transform(s2.begin(),s2.end(),s2.begin(),::tolower);

int x = s1.length();

int y = s2.length();

for(int i=0;i<=y-x;i++){

int j;

for(j=0;j<x;j++){

if(s2[i+j] != s1[j]){

break;

}

}

if(j==x){

cout<<"AMOUNT("<<arr[k].exp<<") DESC"<<arr[k].Desc<<")"<<endl;

}

}

}

menu();

}

//4. search expenses with greater than or equal to this amount

void searchExp(){

double exp1;

cout<<"Please enter the amount:";

cin>>exp1;

for(int i=0; i<c; i++){

if(exp1<=arr[i].exp){

cout<<"AMOUNT("<<arr[i].exp<<") DESC"<<arr[i].Desc<<")"<<endl;

}

}

menu();

}

//Menu

void menu()

{

cout << "Expense Tracking Menu:" << endl;

cout << "1. show all" << endl;

cout << "2. spend" << endl;

cout << "3. search expenses containing this string" << endl;

cout << "4. search expenses with greater than or equal to this amount" << endl;

cout << "5. exit" << endl;

int input;

cout << "Enter your option:";

cin >> input;

switch (input)

{

case 1:

showArray();

break;

case 2:

addArray();

break;

case 3:

searchDesc();

break;

case 4:

searchExp();

break;

case 5:

return;

default:

cout<<"Enter Vailid Option"<<endl;

menu();

}

}

int main()

{

cout<<"Welcome to my expense tracker.";

menu();

return 0;

}


Related Solutions

(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...
The Programming Language is C++ PLEASE, Make sure to read the requirements and grading criteria for...
The Programming Language is C++ PLEASE, Make sure to read the requirements and grading criteria for homework first... Thank you!!! Objective: The purpose of this project is to expose you to: One-dimensional parallel arrays, input/output, Manipulating summation, maintenance of array elements. In addition, defining an array type and passing arrays and array elements to functions. Problem Specification: Using the structured chart below, write a program to keep records and print statistical analysis for a class of students. There are three...
use repil.it intro to C-programin be sure Make code very basic and add good comments thank...
use repil.it intro to C-programin be sure Make code very basic and add good comments thank you 1-Write a program that requests 5 integers from the user and stores them in an array. You may do this with either a for loop OR by getting a string from stdin and using sscanf to store formatted input in each spot in the array. 2-Add a function to the program, called get_mean that determines the mean, which is the average of the...
PLease using C# Without using try-catch-throw for exception handling (Ch07), display an error message (using csc...
PLease using C# Without using try-catch-throw for exception handling (Ch07), display an error message (using csc or VS2017) when an input is invalid (i.e., no data, wrong format, wrong type, etc.) and fails the type conversion. Generate random integers from any of the following three non-overlapped ranges -14 ~ -7 -2 ~ 5 33 ~ 44 Numbers generated must also randomly distributed across the three ranges.
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...
Please circle the answers and please make sure that it is true answer. Thank you. A...
Please circle the answers and please make sure that it is true answer. Thank you. A particle executes linear SHM with frequency 0.11 Hz about the point x = 0. At t = 0, it has displacement x = 0.33 cm and zero velocity. For the motion, determine the (a) displacement at t = 2.2 s, and (b) velocity at t = 2.2 s.
please right make it so that it can run on jGRASP and java code please thank...
please right make it so that it can run on jGRASP and java code please thank you Debug Problem 1: As an intern for NASA, you have been instructed to debug a java program that calculates the speed that sound travels in water. Details about the formulas and correct results appear in the comments area at the top of the program Here is the code to debug: importjava.util.Scanner; /**    This program demonstrates a solution to the    The Speed of Sound...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to input 2 numbers, a starting number x and ending number y Implements a while loop that counts from x (start) to y(end). Inside the loop, print to the screen the current number Print rather the current number is even or odd If the number is even , multiply by the number by 3 and print the results to the screen. If the number is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT