Question: From this comment---- Indicate how useful the feedback was.  Did you understand the comments/observations/suggestions? Did the review point out flaws/shortcomings in your program? Did you learn anything from the critique?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

#include <iostream>

#include <string>

#include <iomanip>

#include <fstream>

 

using namespace std;

 

//Declaring the function

void sum_of_votes();

 

//Defining the main

int main() {

  sum_of_votes();

  return 0;

}

 

void sum_of_votes()

{

  int Max=10;

  ifstream inputFile;

  inputFile.open("ballot.txt");

 

  //Variable Initialzing

  string candidates[Max];

  int votes[Max];

  float percent[Max];

  int max=0,total_votes=0;

  int i=0,count=0;

  string name;

 

  //Looping

   while (!inputFile.eof())

   {

     inputFile>>candidates[i];

     cout<<"Enter the number of votes received by "<<candidates[i]<<" :";

 

     count+=1;

 

    //Getting the candidate name and votes

    cin>>votes[i];

    cout<<endl;

    if(votes[i]<0)

    {

        cout<<"The number of votes cannot be less than 0. Please try again"<<endl;

        cout<<"Enter the number of votes received by "<<candidates[i]<<" :";

        cin>>votes[i];

        cout<<endl;

    }

    if(cin.fail())

    {

        cin.clear();

        cin.ignore(numeric_limits<streamsize>::max(),'\n');

        cout<<"This is not a number! Please try again."<<endl;

        cout<<"Enter the number of votes received by "<<candidates[i]<<" :";

        cin>>votes[i];

        cout<<endl;

    }

 

    //calculating the total votes

    total_votes+=votes[i];

    i+=1;

  }

    //Looping

    for(int i=0;i<count;i++)

    {

 

        percent[i]=(votes[i]/(float)total_votes)*100.0;

 

        if(percent[i]>percent[max])

        {

            //Storing the max value

            max=i;        }

    }

\

 

  cout<<endl;

  cout<<"Candidate"<<"\t\t"<<"Votes Received"<<"\t\t\t"<<"% of Total Votes"<<endl;

  for(int i=0;i<count;i++)

  {

 

     std::cout << std::left << std::setw(30) << candidates[i] << std::setw(30) << votes[i] <<std::setw(30)<<fixed<<setprecision(2)<<percent[i] <<'\n';

  }

 

  cout<<std::left<<setw(30)<<"Total Votes"<<setw(30)<<total_votes<<endl;

  cout<<"The winner of the Election is "<<candidates[max]<<".\n";

 

}

Comment: I really like the design of your code as it is really simple and easy to read.  I can follow through line by line and I don't really need the comments to need to know what is happening where, it's simply put.  The documentation is well placed and isn't overly done.  There is documentation at nearly every step that needs it, which is helpful for reference.  Overall, to me the code looks fairly efficient as every variable is used and there isn't any unnecessary lines of code. Nice work!

Question: From this comment----

  • Indicate how useful the feedback was. 
  • Did you understand the comments/observations/suggestions?
  • Did the review point out flaws/shortcomings in your program?
  • Did you learn anything from the critique?
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education