Question

Help with C++ Code (using visual studio)

preferred Typed

Your job is to write a program that will help us keep track of the donations to these candidates. You will assume that the pr

Result:

Election Contributions v1.0 Anders vs. Valerie 1- Contribute to a Campaign 2- Report per Candidate 0- Exit Make a choice (1-3

Your job is to write a program that will help us keep track of the donations to these candidates. You will assume that the program is written for this election where Anders and Valerie are running. It is OK to hard code these into your program. Don't worry about case sensitivity of names Here are the features of the program Feature #1: Contribute to a Campaign [60 points] When someone wants to make a contribution we use this feature to enter the contribution information to the system. Program asks for which candidate the contribution is, and the amount of the contribution, along with the name of the person making the contribution To make things easier for you - You may assume that the name of the donor is just the last name. No spaces allowed in the last name and assume that no two donors will ever have the same last name.:-) According to US laws, no individual is allowed to make political contributions exceeding $2700 per election. The program should not accept the contribution if the total amount of contribution of that individual (go by last name) exceeds $2700 [50 points] The candidate that will be entered by the user will always be either Anders or Valerie -you do not need to error check for this The program supports up to 1000 donations. Feature #2: Report per Candidate a) Displays how many contributions are in the system for each candidate. [30 points] b) The total amount contributed for each candidate. [30 points] c) The average contribution amount for each candidate. This is basically the number you found for a) divided by the number you reported for b) for each candidate. [30 points] File I/O [60 points]: Make sure that you have file l/O in place so we do not loose information when we close the program Classes [40 points]: Make sure that you are using a class representing a donation
Election Contributions v1.0 Anders vs. Valerie 1- Contribute to a Campaign 2- Report per Candidate 0- Exit Make a choice (1-3): 1 Candidate (Anders or Valerie): Anders Donation Amount: 1300 Your Name: Jackson Election Contributions v1.0 Anders vs. Valerie 1- Contribute to a Campaign 2- Report per Candidate 0- Exit Make a choice (1-3): 1 Candidate (Anders or Valerie): Anders Donation Amount: 1500 Your Name: Jackson You cannot exceed $2700 per election Election Contributions v1.0 Anders vs. Valerie 1- Contribute to a Campaign 2- Report per Candidate 0- Exit Make a choice (1-3): 2 Anders Total: $1300 # of Donations: 1 lvg. Amount: $1300 Valerie Total: 0 # of Donations: 0 lvg. Amount $0 Election Contributions v1.0 Anders vs. Valerie 1- Contribute to a Campaign 2- Report per Candidate 0- Exit Make a choice (1-3): 1 Candidate (Anders or Valerie): Valerie Donation Amount: 1500 Your Name: Brown Election Contributions v1.0 Anders vs. Valerie 1- Contribute to a Campaign 2- Report per Candidate 0- Exit Make a choice (1-3): 2 AndersTotal of Donations: 1 Avg. Amount: $1300 alerie Total of Donations: 1
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)

#include <iostream>
#include <string>
#include <fstream>
#include <vector>

using namespace std;

class Donation {
public:
   string name;
   double amount;
   string candidate;

};

void displayMessage();
void readFile(Donation donors[], int &count);
void writeFile(Donation donors[], int count);
void addContribution(Donation *donors, int &count, int &countAnders, int &countValerie, double &totalAnders,
                     double &totalValerie);
void eachCandidateReport(Donation *donors, int count, int countAnders, int countValerie, double totalAnders,
                         double totalValerie);

int main() {
  
   int choice = 0;
   const int SIZE = 1000;
   Donation donors[SIZE];
   int count = 0;
   int countAnders = 0;
   int countValerie = 0;
   double totalAnders = 0;
   double totalValerie = 0;

   readFile(donors, count);

   do {
       displayMessage();
       cin >> choice;
       if (choice == 1) {
            addContribution(donors, count, countAnders, countValerie, totalAnders, totalValerie);
       }
       else if (choice == 2) {
            eachCandidateReport(donors, count, countAnders, countValerie, totalAnders, totalValerie);
       }
   } while (choice != 0);

   writeFile(donors, count);

   system("PAUSE");
   return 0;
}

//function definitions
void displayMessage() {
   cout << "===========================\n"
       << "Election Contributions v1.0\n"
       << "     Anders vs. Valerie    \n"
       << "===========================\n"
       << "1 - Contribute to Campaign\n"
       << "2 - Report per Candidate\n"
       << "0 - Exit\n"
       << "Choose one: ";
}

void readFile(Donation donors[],int &count) {
   ifstream fileIn("/Users/swapnil/CLionProjects/ElectionContributions /input.txt");
   if (!fileIn) {
       cout << "File has failed to open.\n";
       system("PAUSE");
       exit(EXIT_FAILURE);
   }
   while (!fileIn.eof()) {
       fileIn >> donors[count].name;
       fileIn >> donors[count].amount;
       fileIn >> donors[count].candidate;
       count++;
   }
}
void writeFile(Donation donors[], int count) {
   ofstream fileOut("/Users/swapnil/CLionProjects/ElectionContributions /output.txt");
   for (int i = 0; i < count; i++) {
       fileOut << donors[i].name << " " << donors[i].amount << " " << donors[i].candidate;
       if (i < count - 1) {
           fileOut << endl;
       }
   }
   fileOut.close();
}
void addContribution(Donation *donors, int &count, int &countAnders, int &countValerie, double &totalAnders,
                     double &totalValerie) {
   for (int i = 0; i < count; i++) {
       if (donors[i].candidate == "Anders") {
           totalAnders += donors[i].amount;
       }
       if (donors[i].candidate == "Valerie") {
           totalValerie += donors[i].amount;
       }
   }
   cout << "What is your last name?\n";
   cin >> donors[count].name;

   for (int i = 0; i < count; i++) {
       double total = 0;
       if (donors[count].name == donors[i].name) {
           total += donors[i].amount;
       }
       if (total > 2700) {
           cout << "You are not allowed to donate more. Your contribution will not be accepted.\n";
           return;
       }
   }

   cout << "How much do you want to donate?\n";
   cin >> donors[count].amount;

   cout << "Which candidate are you donating to? (Anders OR Valerie)\n";
   cin >> donors[count].candidate;
   if (donors[count].candidate == "Anders") {
       countAnders++;
   }
   if (donors[count].candidate == "Valerie") {
       countValerie++;
   }

   count++;
}
void eachCandidateReport(Donation *donors, int count, int countAnders, int countValerie, double totalAnders,
                         double totalValerie) {

   double avg = 0;
   avg = totalAnders / countAnders;
   cout << "The number of contributions is: " << countAnders << endl;
   cout << "The total amount collected for Anders is: " << totalAnders << endl;
   cout << "The average amount collected for Anders is: " << avg << endl;

   avg = 0;
   avg = totalValerie / countValerie;
   cout << "The number of contributions is: " << countValerie << endl;
   cout << "The total amount collected for Valerie is: " << totalValerie << endl;
   cout << "The average amount collected for Valerie is: " << avg << endl;
}



-/CLionProjects ElectionContributions] - .main.cpp 温main.cpp *一 △CMakeists.txt 島 Project ▼ ▼ ElectionContributions -XLionProj

Add a comment
Know the answer?
Add Answer to:
Your job is to write a program that will help us keep track of the donations to these candidates....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates...

    (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates for an upcoming election. This program needs to allow the user to enter candidates and then record votes as they come in and then calculate results and determine the winner. This program will have three classes: Candidate, Results and ElectionApp Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are...

  • Can you help us!! Thank you! C++ Write a program that can be used by a...

    Can you help us!! Thank you! C++ Write a program that can be used by a small theater to sell tickets for performances. The program should display a screen that shows which seats are available and which are taken. Here is a list of tasks this program must perform • The theater's auditorium has 15 rows, with 30 seats in each row. A two dimensional array can be used to represent the seats. The seats array can be initialized with...

  • Requires Python to answer A client wishes to keep track of his investment in shares. Write...

    Requires Python to answer A client wishes to keep track of his investment in shares. Write a program to help him manage his stock portfolio. You are to record both the shares that he is holding as well as shares that he has sold. For shares be is curreatly holding, record the following data: .a 3-character share code, share name, last purchase date, volume currently held and average purchase price (refer to description under part cii) option 2) For shares...

  • If your program does not compile, you will not receive any points! You will write a program to keep up with a Jewelry...

    If your program does not compile, you will not receive any points! You will write a program to keep up with a Jewelry store and some of the Inventory (rings/necklaces/earrings) purchased there (The Jewelry store can be real or not) using Object-Oriented Programming (OOP). The important aspect of object-oriented programming is modular development and testing of reusable software modules. You love selling rings, necklaces, and earrings as well as programming and have decided to open a Jewelry store. To save...

  • Written in Java Your job is to produce a program that sorts a list of numbers...

    Written in Java Your job is to produce a program that sorts a list of numbers in ascending order. Your program will need to read-in, from a file, a list of integers – at which point you should allow the user an option to choose to sort the numbers in ascending order via one of the three Sorting algorithms that we have explored. Your program should use the concept of Polymorphism to provide this sorting feature. As output, you will...

  • Topics: list, file input/output (Python) You will write a program that allows the user to read...

    Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...

  • Problem Specification: Write a C++ program to calculate student’s GPA for the semester in your class. For each student, the program should accept a student’s name, ID number and the number of courses...

    Problem Specification:Write a C++ program to calculate student’s GPA for the semester in your class. For each student,the program should accept a student’s name, ID number and the number of courses he/she istaking, then for each course the following data is needed the course number a string e.g. BU 101 course credits “an integer” grade received for the course “a character”.The program should display each student’s information and their courses information. It shouldalso display the GPA for the semester. The...

  • I need help writing c++ code to make this program. 1. Define a function that can...

    I need help writing c++ code to make this program. 1. Define a function that can read the input file answers.dat. This function should not print anything. 2. Define a function that computes the quiz score of the function by comparing the correct answers to the student’s answer. The result should be a percentage between 0 and 100, not a value between 0 and 1. This function should not print anything. 3. Define a function that prints the report as...

  • Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program...

    Help write down below program with C++ language!!! Please... The Cipher Program Requirements An interactive program is required that allows a user to encode text using any of three possible ciphers. The three ciphers you are to offer are: Caesar, Playfair and Columnar Transposition. • The program needs to loop, repeating to ask the user if they wish to play with Caesar, Playfair or Columnar Transposition until the user wishes to stop the program. •For encoding, the program needs to...

  • Comprehensive Problem 5-1 John Williams (birthdate August 2, 1976) is a single taxpayer. John's earnings and...

    Comprehensive Problem 5-1 John Williams (birthdate August 2, 1976) is a single taxpayer. John's earnings and withholdings as the manager of a local casino for 2019 are reported on his Form W-2 (see separate tab). John received Form 1098 from the Reno Bank & Trust (see separate tab). John's other income includes interest on a savings account at Nevada National Bank of $13,691. John pays his ex-wife, Sarah McLoughlin, $3,900 per month in accordance with their February 12, 2013 divorce...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT