Help with C++ Code (using visual studio)
preferred Typed
Result:
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;
}
Your job is to write a program that will help us keep track of the donations to these 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 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 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 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 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 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 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 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 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 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...