Need help with your Discussion

Get a timely done, PLAGIARISM-FREE paper
from our highly-qualified writers!

glass
pen
clip
papers
heaphones

C++ Struct Exercise Programming Code Project

C++ Struct Exercise Programming Code Project

C++ Struct Exercise Programming Code Project

Description

The skeleton code is given below. The questions are attached as pdf. I attempted some of the exercise but couldn’t complete so you may pick up from there or start fresh. The expected output is in the pdf and I need the exact output for my solution. I do not understand advanced stuff like pointers so please do not use them.

/* Lab 7: Voting -- An election system
 * Struct and separate compilation
 * File: lab7_skeleton.cpp
 */

/* Task 4: After finishing the coding task 1 to task 3
 * separate the single lab7.cpp to 3 files
 *  - lab7.h 
 *  - main.cpp with definition of main()
 *  - lab7functions.cpp with definitions of all other functions
 *  - (optional) Makefile
 * You will need to demo your lab 7 with separate compilation 
 */

#include <iostream>
#include <cstring>
using namespace std;

const int MAX_SIZE = 10;
const int MAX_STRING_LENGTH = 20;

enum Role
{
   CANDIDATE,
   VOTER
};

//names listed in no particular order :)
char names[MAX_SIZE][MAX_STRING_LENGTH] = {"JoeBiden", "QueenElizabethII", "Putin", "Trudeau", "XiJinping", "Macron", "KimJongun", "CarrieLam", "Zelenskyy", "Trump"};

// struct definition of Participant
struct Participant
{
   int id;
   char name[MAX_STRING_LENGTH];
   Role role;     // CANDIDATE or VOTER
   bool hasVoted; // true if voter has voted, false otherwise
   int voteCount; // number of votes received if the participant is a candidate of election, initilized as 0
};

// struct definition of Election
struct Election
{
   Participant participants[MAX_SIZE];
   int numCandidates; //note candidates can also vote
   int numVoters;
   // the candidates will occupy the first numCandidates elements in the participants array,
   // while the other voters will occupy the next numVoters elements in the participants array
};

/* Helper function
 * Print participants
 * Parameter:
 *    - election: the Election struct object
 */
void printParticipants(const Election &election)
{

   for (int i = 0; i < election.numCandidates + election.numVoters; i++)
   {
      cout << "ID: " << election.participants[i].id << "tName:" << election.participants[i].name << "t";
      if (election.participants[i].role == CANDIDATE)
         cout << "Role: Candidate" << endl;
      else
         cout << "Role: Voter" << endl;
   }
}

/* Task 1: 
 * Setup the election
 * - initialize all the member variables of the Election object
 * Parameters:
 *    - election: a Election struct object
 * Note:
 *    - id for voter/candidate are assigned as 1, 2, 3, ...in sequence
 *    - name for voter/candidate are copied from names[][] in sequence
 *    - role: CANDIDATE or VOTER (note candidate can also vote)
 *    - hasVoted = false, voteCount = 0
 */
void setup(Election &election, int numCandidates, int numVoters)
{
   
}
/* Task 2:
 * Casting votes to some candidates by a specific voter given the voter id
 * Parameters:
 *    - election: the Election struct object
 *    - voterId: the voter's id
 * Note:
 *    validates the following 
 *    - voter id has to be valid, note candidate can also vote
 *    - candidate id has to be valid
 *    - voter can only vote once
 */
void voting(Election &election, int voterID)
{
   
}

/* Task 3:
 * Output the number of votes for each candidate
 * and announce the winner by finding who has the maximum number of votes
 * Parameters:
 *    - election: the Election struct object
 * Note: if there is more than 1 candidate has the same number of maximum votes,
 * announce it as a tie election.
 */
void resultTallying(const Election &election)
{
   
}

// Main function for the election system
int main()
{
   // Create an election
   Election election;
   int numCandidates, numVoters;

   cout << "===============================" << endl;
   cout << " Welcome to the voting system! " << endl;
   cout << "===============================" << endl;
   cout << "Preparing ... " << endl;
   do
   {
      cout << "Enter how many candidates will run for the election: n";
      cin >> numCandidates;
      cout << "Enter how many more voters: n";
      cin >> numVoters;
   } while (((numCandidates + numVoters) > MAX_SIZE) || (numCandidates <= 0));
   cout << "n";

   // the setup phase
   setup(election, numCandidates, numVoters);

   // print candidates and voters
   printParticipants(election);

   int currentId;
   int voteCount = 0;

   // voting
   cout << "Voting starts ..." << endl;
   char cmd;
   do
   {
      cout << "Enter the voter id to start voting:n"; //candidates can also vote
      cin >> currentId;

      voting(election, currentId);

      cout << "Continue with the next voter? (y/n) ";
      cin >> cmd;
   } while ((cmd == 'y') || (cmd == 'Y'));

   cout << "Tallying votes ..." << endl;
   //the result-tallying phase
   resultTallying(election);

   cout << "End of the election!" << endl;
   return 0;
}

Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."

Order Solution Now

Our Service Charter


1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers are known for the timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

We Can Write It for You! Enjoy 20% OFF on This Order. Use Code SAVE20

Stuck with your Assignment?

Enjoy 20% OFF Today
Use code SAVE20