Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why is my last switch giving me red lines? #include MainProgram.h #include DonationRecord.h #include #include #include #include #include using namespace std; vector readDonationsFromFile

Why is my last switch giving me red lines?
#include "MainProgram.h"
#include "DonationRecord.h"
#include
#include
#include
#include
#include
using namespace std;
vector readDonationsFromFile(const string& filename)
{
vector donations;
ifstream file(filename);
if (!file.is_open())
{
cerr << "Sorry, cannot open file." << endl;
return donations;
}
string line;
// Skip header
getline(file, line);
while (getline(file, line))
{
stringstream ss(line);
string token;
vector tokens;
while (getline(ss, token, ','))
{
tokens.push_back(token);
}
if (tokens.size()==7){
donations.emplace_back(tokens[0], tokens[1], tokens[2], tokens[3], tokens[4], tokens[5], stof(tokens[6]));
}
}
file.close();
return donations;
}
void displayHeading()
{
cout << "United Cause Relief Agency Daily Donations" << endl;
cout <<"-------------------------------------------------------------"<< endl;
cout << "Gift ID\tCompany\tPhone\tPOC\tItem Donated\tCategory\tValue"<< endl;
cout <<"================================================================"<< endl;
}
void displayMenu()
{
cout << "United Cause Relief Agency Daily Donations Reports Menu" << endl;
cout <<"======================================================"<< endl;
cout <<"1: All by Natural Order of Input File" << endl;
cout <<"2: All by Company name, Ascending" << endl;
cout <<"3: All by Company name, Descending" << endl;
cout <<"4: All by Category, Ascending" << endl;
cout <<"5: All by Gift ID, Ascending" << endl;
cout <<"6: One Donor only by Value, Descending" << endl;
cout <<"0: Exit the program" << endl;
cout << "Please select report you wish to be run from menu above (1-6): ";
}
void sortByGiftID(vector& donations)
{
sort(donations.begin(), donations.end());
}
void sortByCompanyNameAscending(vector& donations)
{
sort(donations.begin(), donations.end(),[](const DonationRecord& a, const DonationRecord& b)
{
return a.getDonorName()< b.getDonorName();
});
}
void sortByCompanyNameDescending(vector& donations)
{
sort(donations.begin(), donations.end(),[](const DonationRecord& a, const DonationRecord& b)
{
return a.getDonorName()> b.getDonorName();
});
}
void sortByCategoryAscending(vector& donations)
{
sort(donations.begin(), donations.end(),[](const DonationRecord& a, const DonationRecord& b)
{
return a.getItemCategory()< b.getItemCategory();
});
}
void generateReport(const vector& donations, int choice)
{
vector sortedDonations = donations;
switch (choice)
{
case 1:
displayHeading();
for (const auto& donation : sortedDonations)
{
donation.displayRecord();
}
break;
case 2:
sortByCompanyNameAscending(sortedDonations);
break;
case 3:
sortByCompanyNameDescending(sortedDonations);
break;
case 4:
sortByCategoryAscending(sortedDonations);
break;
case 5:
sortByGiftID(sortedDonations);
break;
case 6:
string donorName;
cout << "Enter donor name: ";
cin >> donorName;
vector filteredDonations;
for (const auto& donation : donations){
if (donation.getDonorName()== donorName){
filteredDonations.push_back(donation);
}
}
sort(filteredDonations.begin(), filteredDonations.end(),[](const DonationRecord& a, const DonationRecord& b){
return a.getValue()> b.getValue();
});
displayHeading();
for (const auto& donation : filteredDonations){
donation.displayRecord();
}
break;
default:
cout << "Sorry your choice was not recognized. Please try again." << endl;
return; // Return to avoid further processing
}
float total =0;
for (const auto& donation : sortedDonations)
{
total += donation.getValue();
}
cout << "Total" <<"\t\t\t\t\t\t\t$"<< total << endl;
}
int main()
{
vector donations = readDonationsFromFile("Donations.csv");
int choice;
do {
displayMenu();
cin >> choice;
switch (choice)
{
case 1:
case 2:
case 3:

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

Students also viewed these Databases questions

Question

Organizing Your Speech Points

Answered: 1 week ago