Find Jobs
Hire Freelancers

C++ program using LOOPS and Files

$30-250 USD

Completed
Posted over 10 years ago

$30-250 USD

Paid on delivery
Pirate Election Fifteen men on a dead man's chest. Yo ho ho and a bottle of rum. Drink and the devil have done for the rest. Yo ho ho and a bottle of rum.1 Shiver me timbers, the ship’s captain is swimmin’ in Davey Jone’s Locker! He was infamous for being a lush, gambling too much, and cussing like—well—a sailor. During a recent raid, he got caught by locals for hornswaggling2 and was strung up by a hempen halter3. The Jolly Roger is flying at half-mast until a new captain is picked. That means no raids which has the crew in the grips of seafartherin’ chaos. No one knows what to do so you’ve suggested an election. It’s been generally agreed to with some ground rules, pirates not being the most upright of citizens. While the fuss and muss of an election is inevitable, the crew has also decided to vote on amendments on two long standing pirate laws on the ballot4. That way, they can resolve these issues and elect a new captain and first mate with one ballot. Law 1: A pirate does not ask for directions. He relies only on his gut feeling, a compass, or a treasure map. Amendment 1: GPS be added to the list with the restriction that iPhones, iPads or other iTechnology that comes up must use Google maps5. By Rob’s Rules of Order, this amendment requires 75% of the pirates to vote yes. Law 2: Hooks are the only acceptable hand substitute. Amendment 2: Secondary attachments such as screwdrivers, bottle openers, or corkscrews are permitted. This amendment only requires a majority (> 50%). All of the pirate’s names have been tossed in a hat and after many a mate brawled, it comes down to three burly candidates. Their names are stored in a file called candidates.txt. You need to open this file and read in the names, stored as strings on three separate lines. 1 Treasure Island. 2 To cheat or defraud, often of money or belongings. 3 The hangman's noose. 4 Pirates never, ever obey laws. Period. Ironic, I realize. 5 Relying on the iPhone map app's directions to get to Blackbeard’s island is downright dangerous. Example [login to view URL] file: Jack Black Bartelmy Steve the Pi-rat Pearly Pete The voting process proceeded as follows:  Pirates stand in line to fill out a paper ballot.  Each pirate has been assigned a unique number that they enter on the ballot.  They write down the name of the candidate they are voting for.  They enter Y or N for issue 1 and Y or N for issue 2.  The pirate with the most votes becomes the new ship’s captain.  The pirate with the second most votes becomes the new first mate.  The pirate with the least votes walks the plank6. Note: Pirates are neither honest nor very bright. They tend to get back in line and vote again with the “vote early and vote often” philosophy. They are not, however, smart enough to use a different number. Your file will contain a sorted list of votes so that you can discount duplicates. You only need to check the current pirate number with the last one to see if that pirate has already cast a ballot. Only tally the results of the first ballot for each pirate. Ignore duplicates even if they voted differently the second or third or fourth time. Note that not all numbers may be used, i.e., pirate registration numbers may be 5, 13, 21, and 34. Therefore you’ll need to keep track of how many pirates actually voted. You cannot rely on the last pirate registration number. Ballots are stored in a file called ballots.txt. You need to open this file and read each ballot (one per line) until the end of the file. Example [login to view URL] file: 1YYSteve the Pi-rat 2YNJack Black Bartelmy 2YNJack Black Bartelmy 2NNPearly Pete 3NYSteve the Pi-rat 3YYJack Black Bartelmy 7YNSteve the Pi-rat Format: 6 This encourages only serious candidates to apply. Unfortunately it also encourages a lot of cheating. And fighting. Results would be: 4 pirates voted in this election using 8 ballots. Captain (most votes): Steve the Pi-rat (with 3 votes) First mate: Jack Black Bartelmy (with 1 vote) Pearly Pete did not receive any votes because pirate #2’s first ballot for Jack Black Bartelmy is the one you count. He walks the plank. (Don’t worry, like most pirates, he can swim.) Amendment #1 passes (3 Y, 1 N) – 75% met Amendment #2 fails (2 Y 2 N) – 50% is not a majority Your task is two-fold. First, determine the results of the election and print them out on the screen. Second, as you read in the ballots, create a new ballot file called [login to view URL] that contains only those ballots that were used in the count. Add a space between the ballot entries. For example, with the sample file given, the new file would look like the following. 1 Y Y Steve the Pi-rat 2 Y N Jack Black Bartelmy 3 N Y Steve the Pi-rat 7 Y N Steve the Pi-rat Voting ties: It’s possible that there could be a tie for first or second place. This has been anticipated. The three candidates participated in a rat throwing contest7. Their names are placed in the candidate file according to their hurling skills. Therefore, if there is a tie, the pirate whose name appears first in the file breaks the tie. For example, using the example file, had there been a tie between Jack Black Bartelmy and Pearly Pete, the winner would be Jack Black Bartelmy. Output: 1. Candidate name list and how many votes each received. 2. How many votes were cast. (This includes the cheat ballots.) 3. How many actual pirates voted. 4. If each issue passed or failed and the number of yes votes it received. 5. Who the new captain and first mate are. 6. Give an “Aye! Aye! Captain name of winner!” for each vote the winner received. ex. if Steve the Pi-rat won with 3 votes, end your program with Aye! Aye! Captain Steve the Pi-rat! Aye! Aye! Captain Steve the Pi-rat! Aye! Aye! Captain Steve the Pi-rat! 7 Only the dead ones from the last heat wave. Tips: 1. You are opening two files for input and one file for output. 2. You need a while or do-while loop to read in the ballots. 3. You need to keep track of the most recent pirate number and compare it to the current ballot to determine if you are going to do anything with the ballot or not. 4. You need to tally the votes for each pirate candidate and for each issue. 5. For the captain and first mate election, you only need to know who got the most votes and who came in second. 6. For the issues, you need to know how many pirates actually voted to determine 75% or majority. 7. You will use the actual file names ([login to view URL], [login to view URL] and [login to view URL]) in your code. Do not prompt the user for file names. 8. If a pirate receives one vote, say “… received 1 vote” not “… received 1 votes”. 9. Use a for-loop for your final “aye aye”s. Code:  Use a header comment with your name and the purpose of the program.  Use appropriate code comments.  Use appropriate variable names.  Use good coding practices (i.e., spacing, indentation, etc.)  Do not use functions, classes, arrays, or other techniques not covered through chapter 5 of Gaddis. Submission:
Project ID: 5085082

About the project

2 proposals
Remote project
Active 10 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
Awarded to:
User Avatar
Hello , I am C++ expert and can surely help you here with this project. Please let me know if you are interested. Thank You
$98 USD in 2 days
4.8 (109 reviews)
5.9
5.9
2 freelancers are bidding on average $137 USD for this job
User Avatar
A proposal has not yet been provided
$175 USD in 15 days
5.0 (1 review)
1.9
1.9

About the client

Flag of UNITED STATES
Stow, United States
5.0
2
Payment method verified
Member since Nov 1, 2013

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.