#include #include #include using

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

convert it into file handling. 

#include<iostream>
#include<conio.h>
#include<string>
#include<fstream>
using namespace std;
class votes
{
private:
int no_of_people = 0;
string arr[15] = { "Arif ur Rehman", "Waqar Chohan", "Sumaira Kausar", "Momina Moetesum","Muhammad Muzammal" };
int no[15] = { 77,56,55,44,36 };
public:
void work()
{
string name;
char selection;
do
{
cout << "\n Enter The name of Candidate you Like: ";
getline(cin, name);
char press;
for (int i = 0; i < 10; i++)
{
if (name == arr[0])
{
no_of_people = no[0];
}
else if (name == arr[1])
{
no_of_people = no[1];
}
else if (name == arr[2])
{
no_of_people = no[2];
}
else if (name == arr[3])
{
no_of_people = no[3];
}
else if (name == arr[4])
{
no_of_people = no[4];
}
else if (name == arr[5])
{
no_of_people = no[5];
}
if (name == arr[i])
{
cout << "\n The Candidate is in database. Already " << no_of_people << " people have voted for him.";
cout << " Do you want to vote for him as well(y/n): ";
cin >> press;
if (press == 'y')
{
cout << endl;
no_of_people++;
}
else
{
goto jump;
}
cout << "\n\n Now Candidate is voted by " << no_of_people << " people.";
goto jump;
}
}
cout << "\n\n Candidate is not found in database Do you want to add it in database(y/n).";
char press1;
cin >> press1;
if (press1 == 'y')
{
arr[5].append(name);
cout << "\n\n Candidate added in database";
}
else
{
goto jump;
}
jump:
cout << "\n\n Do you want to look for another Candidate(y/n): ";
cin >> selection;
cin.ignore();
} while (selection != 'n');
}
void Total()
{
int total = 0;
for (int i = 0; i < 10; i = i + 1)
{
total = total + no[i];
}
cout << "\n\n The Total Number of People Who Have Alredy Voted : " << total;
}
void file()
{
ofstream file;
file.open("Data.txt");

if (!file)
{
cout << "\n File Not Open...\n\n";
exit(0);
}
else
{
for (int i = 0; i < 6; i = i + 1)
{
file << arr[i] << "," << no[i] << endl;
}

cout << "\n The file has written..";
}
file.close();
}
void display()
{
cout << "\n **";
cout << "\n The Top five Candidates are: " << endl;
for (int i = 0; i < 6; i++)
{
cout << "\n " << arr[i] << "," << no[i] << endl;
}
cout << "\n **";
}
};
int main()
{
votes v1;
v1.work();
v1.display();
v1.Total();
v1.file();
_getch();
system("pause");
}

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Header Files
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