Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Track Expenses Using Pointers Objectives: Using array or vector of pointers Design C + + class Build an application that has multiple files. Understand how

Track Expenses Using Pointers
Objectives:
Using array or vector of pointers
Design C++ class
Build an application that has multiple files.
Understand how to call methods defined in C++ class
Handle input errors and invalid values
Description:
This is another version of Project #2. All the features are the same. However, the internal
implementation is different.
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. New requirements:
a. Use an array or vector of pointers to keep track of Expense objects.
b. Write a new function in main-expense.cpp to create a new Expense object
using new operator to allocate the object on the heap. This function takes the
expense description (pointer to character array) and amount. It returns the
address of the newly created Expense. The prototype should look like:
Expense *createExpense(char[] description, float amount)
Or
Expense *createExpense(char *description, float amount)
c. The description must be an array of characters. You are not allowed to use
string for description.
d. You can not change the original expense description. You may need to use a
temporary variable for searching purpose. Hint: The easiest method to do case-
insensitive search is to convert both source and search string to either upper
case or lower case. Then, use strstr() to search.
e. You must delete all expense objects before your program terminates.
2. Create multiple C++ files (put them in the same directory/folder):
a. Create a header file called expense.h. This header file contains your
Expense class data definitions and method prototypes. (Hint: Look at
BankAccount.h in week 6 examples). All data members must be declared as
private and provide getter/setter methods to access them.
b. Create a new CCP file called expense.cpp to implement methods defined
your header file.
c. Create a main program called main-expense.cpp that displays the menu and
utilize your Expense (Expense must implement these methods) class to:
i. Display description and amount
ii. Determine if a substring is part of the description and return true or false
3. The program must produce the same output as provided. The output should be
formatted nicely as given.
4. The program must not use global variables. In another words, it must use local variables
and pass-by-value or pass-by-reference parameters.
5. 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 can also
utilize vector class to keep track of your expense addresses.
6. You should use data file to save or read from. At the beginning of your program, it reads
data from a data file named expenses.txt and initialize your object 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.
7. You must write at least 3 functions in main-expense.cpp.
8. You need to submit all header files, CPP files and data file expenses.txt
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)
Expe

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

NCC West Consolidation - Future Process lew steps: Yellow

Answered: 1 week ago

Question

Identify the job expectancy rights of employees.

Answered: 1 week ago