Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program needs to be written in Microsoft Visual Studio and in C++ please. T

ID: 3705472 • Letter: T

Question

This program needs to be written in Microsoft Visual Studio and in C++ please.

Thank you!!

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

The program must produce the same output as provided. The output should be formatted nicely as given.

The program must use array of structs

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 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 “expenses.txt”

Required error handling:

The program MUST perform the following checks:

Check for invalid amount (negative or 0 number)

Description cannot be empty.

Search is case-insensitive

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

Explanation / Answer

#include <iostream>

#include <string>

#include <fstream>

#include<cstdio>

using namespace std;

struct object{

string desc;

int amount;

}arr[30];

int i=0;

int convert(string s){

int i=0,x=0;

while(s[i]){

x=x*10+(s[i]-'0');

}

return x;

}

void write(struct object &obj){

ofstream OFileObject; // Create Object of Ofstream

OFileObject.open ("expenses.txt", ios::app); // Append mode

OFileObject <<obj.amount<<" " <<obj.desc<<endl; // Writing data to file

cout<<"Data has been appended to file";

OFileObject.close(); // Closing the file

}

void read(){

string linesread;

ifstream IFileObject("expenses.txt");

if (IFileObject.is_open())

{

while (getline (IFileObject, linesread) )

{

cout<<"hello";

string s=linesread.substr(0, s.find(" ")); //space is delimiter here

int k=convert(s);

s=linesread.substr(s.find(" "),s.length()-1);

arr[i].desc=s;

arr[i].amount=k;

cout << arr[i].amount<<" "<<arr[i].desc<< endl;

i++;

}

IFileObject.close();

}

else cout << "File cannot be read";

}

int main()

{

struct object ob;

cin>>ob.amount>>ob.desc;

write(ob);

read();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote