Please I need help a sample code is provided below of the output
// File Name: expense.h
#ifndef EXPENSE_H
#define EXPENSE_H
#include <string>
#define MAX 100
using namespace std;
// Defines a class Expense
class Expense
{
// Data member to store data
string description;
double amount;
// Record counter
static int index;
public:
// Prototype of member functions
Expense();
Expense(string, double);
void setDescription(string);
void setAmount(double);
void setIndex();
string getDescription();
double getAmount();
int getIndex();
void contain(Expense *[], string);
bool target(string, string);
string toString();
friend ostream& operator<< (ostream& , Expense
&);
};// End of function
// Static data member initializes to 0 (record counter)
int Expense::index = 0;
#endif // EXPENSE_H
----------------------------------------------------------------------------------------------------------------
// File Name: expense.cpp
#include "expense.h"
#include <iostream>
#include <sstream>
#include <string>
#include<bits/stdc++.h>
using namespace std;
// Default construct to initialize data members to default value
Expense::Expense()
{
description = "";
amount = 0.0;
}// End of Default construct
// Parameterized construct to assign parameter values to data member
Expense::Expense(string des, double amt)
{
description = des;
amount = amt;
}// End of Parameterized construct
// Function to set description
void Expense::setDescription(string des)
{
description = des;
}// End of function
// Function to set amount
void Expense::setAmount(double amt)
{
amount = amt;
}// End of function
// Function to return description
string Expense::getDescription()
{
return description;
}// End of function
// Function to return amount
double Expense::getAmount()
{
return amount;
}// End of function
// Function to set index
void Expense::setIndex()
{
// Increase the record counter by one
index++;
}// End of function
// Function to return index
int Expense::getIndex()
{
return index;
}// End of function
// Function to return expense information
string Expense::toString()
{
string result = "";
std::ostringstream strs;
strs << amount;
std::string str = strs.str();
result = result + "\n AMOUNT:(" + str + ") DESC(" + description + ")";
return result;
}// End of function
// Overloads << operator
ostream& operator<< (ostream& out, Expense &ex)
{
return out << ex.toString();
}// End of function
// Function to search parameter description in expense list
// Displays information if found
void Expense::contain(Expense *exp[], string des)
{
// Converts the parameter description to upper case
transform(des.begin(), des.end(), des.begin(), ::toupper);
// Loops till number of records
for(int x = 0; x < index; x++)
{
// Call the target function to check parameter description
// found in current expense record description
if(target(exp[x]->getDescription(), des))
// If found then display the information
cout<<exp[x]->toString();
}// End of for loop
}// End of function
// Function to return if the searchStr found in desStr then return true
// Otherwise return false
bool Expense::target(string desStr, string searchStr)
{
// Adds a space at the end of desStr
desStr += " ";
// To store the found space position
int pos;
// Loops till end of the string desStr
for(int y = 0; y < desStr.length(); )
{
// To store the word extracted
string word = "";
// Loops till space character in desStr
for(pos = y; desStr.at(pos) != ' '; pos++)
// Concatenates the character to form word
word = word + desStr.at(pos);
// Sets the y value to next to space position
y = pos + 1;
// Converts the word to upper case
transform(word.begin(), word.end(), word.begin(), ::toupper);
// Checks if searchStr is equals to extracted word
// then return true
if(word.compare(searchStr) == 0)
return true;
// Otherwise extract next word
}// End of for loop
// At the end of the for loop return false for not found
return false;
}// End of function
----------------------------------------------------------------------------------------------------------------
// File Name: expenseMain.cpp
#include "expense.cpp"
#include <string>
using namespace std;
// Function to display menu, accept user choice and returns user
choice
int menu()
{
// To store user choice
int ch;
// Displays menu
cout<<"\n\n Expenses Tracking Menu: ";
cout<<"\n 1. Show all.";
cout<<"\n 2. Spend.";
cout<<"\n 3. Search expenses containing this string.";
cout<<"\n 4. Search expenses with greater than or equals to
this amount.";
cout<<"\n 5. Exit.";
// Accepts user choice
cout<<"\n Enter your option: ";
cin>>ch;
// Returns user choice
return ch;
}// End of function
// main function definition
int main()
{
// Declares an array of pointer object of size MAX
Expense *exp[MAX];
// To store the description and amount entered by the user
string desc;
double amt;
// Loops till user choice is not 5
do
{
// Calls the function to accept user choice and calls
// appropriate function based on user choice
switch(menu())
{
case 1:
// Checks if index counter is equals to 0 then no record
available
if(exp[0]->getIndex() == 0)
cout<<"\n There is no expenses entry available.";
// Otherwise display records
else
{
// Loops till number of records
// calls the toString() function to display each record
information
for(int x = 0; x < exp[0]->getIndex(); x++)
cout<<exp[x]->toString();
}// End of else
break;
case 2:
// Clears console input device
fflush(stdin);
// Accepts the description and amount from the user
cout<<"\n Please enter the description for the expense:
";
getline(cin, desc);
cout<<"\n Please enter the amount: ";
cin>>amt;
// Creates an object using parameterized constructor
// and assigns it at current record counter index position
exp[exp[0]->getIndex()] = new Expense(desc, amt);
// Calls the toString() function to display each record
information
cout<<exp[exp[0]->getIndex()]->toString();
// Calls the function to increase the record counter index by
one
exp[0]->setIndex();
break;
case 3:
// Accepts the description from the user
cout<<"\n Please enter the search string: ";
cin>>desc;
// Calls the function to search the word description
// in the expense list
exp[0]->contain(exp, desc);
break;
case 4:
// Accepts the amount from the user
cout<<"\n Please enter the amount: ";
cin>>amt;
// Loop till number of records
for(int x = 0; x < exp[x]->getIndex(); x++)
// Checks if current record amount is greater than or
equals
// to the amount entered by the user
if(exp[x]->getAmount() >= amt)
// Calls the toString() function to display the information
cout<<exp[x]->toString();
break;
case 5:
exit(0);
default:
cout<<"\n Invalid Option!!";
}// End of switch case
}while(1);// End of do - while loop
return 0;
}// End of main function
Sample Output:
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals to this
amount.
5. Exit.
Enter your option: 1
There is no expenses entry available.
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals 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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals 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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals 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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals 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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals 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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals 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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals to this
amount.
5. Exit.
Enter your option: 1
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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals 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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals 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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals 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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals 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)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals to this
amount.
5. Exit.
Enter your option: 4
Please enter the amount: 1000
AMOUNT:(1200) DESC(Rent)
Expenses Tracking Menu:
1. Show all.
2. Spend.
3. Search expenses containing this string.
4. Search expenses with greater than or equals to this
amount.
5. Exit.
Enter your option: 5
Description This project is an enhancement of your previous project using OOP concepts. You'lI de...
I need help writing this code in C++ and I’m using xcode for mac 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....
All commands must be in the command line. The expense data file is separate. Programming Project #2: Manage Spending Using Commands Objectives: • Understand how to create and manipulate list of objects using array or vector class • Handle input errors and invalid values • Design and create a well-structure program using C++ basic programming constructs and classes. Description: Each “expense” contains 2 values: the spending amount (double) and its description (string) Here is an example of the “expense” data...
Goal: design and implement a dictionary. implement your dictionary using AVL tree . Problem: Each entry in the dictionary is a pair: (word, meaning). Word is a one-word string, meaning can be a string of one or more words (it’s your choice of implementation, you can restrict the meaning to one-word strings). The dictionary is case-insensitive. It means “Book”, “BOOK”, “book” are all the same . Your dictionary application must provide its operations through the following menu (make sure that...
Microsoft Visual Studios 2017 Write a C++ program that computes a student’s grade for an assignment as a percentage given the student’s score and total points. The final score must be rounded up to the nearest whole value using the ceil function in the <cmath> header file. You must also display the floating-point result up to 5 decimal places. The input to the program must come from a file containing a single line with the score and total separated by...
23.4 Project 4: Using Pandas for data analysis and practice with error handling Python Please! 23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same...
DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...
23.4 PROJECT 4: Using Pandas for data analysis and practice with error handling Overview In this project, you will use the Pandas module to analyze some data about some 20th century car models, country of origin, miles per gallon, model year, etc. Provided Input Files An input file with nearly 200 rows of data about automobiles. The input file has the following format (the same as what you had for your chapter 13 labs). The following is an example of...
Using an object-oriented approach, write a program to read a file containing movie data (Tile, Director, Genre, Year Released, Running Time) into a vector of structures and perform the following operations: Search for a specific title Search for movies by a specific director Search for movies by a specific genre Search for movies released in a certain time period Search for movies within a range for running time Display the movies on the screen in a nice, easy to read...
Files given in this assignment (right-click on the file to download) Assignment7.cpp (need to complete) Student.h (Given. Just use it, don't change it!) Student.cpp (Partially filled, need to complete) 1. Assignment description In this assignment, you will write a simple class roster management system for ASU CSE100. Step #1: First, you will need to finish the design of class Student. See the following UML diagram for Student class, the relevant header file (class declaration) is given to you as Student.h,...
Use c-strings for the following project: Write a C++ program that declares an array containing up to a maximum of 20 sentences, each sentence of maximum 81 characters long, using c-strings. Continue reading sentences from the user and store them in the array of sentences, until the user enters a NULL string for the sentence or 20 sentences have been entered. Then, one by one, display each sentence entered by the user and present the following menu of operations on...