Question

In: Computer Science

//Write in C++ //use this evote code and add File I/O operations (as specified in the...

//Write in C++

//use this evote code and add File I/O operations (as specified in the comments) to it.

#include<iostream>

using namespace std;

int main()

{int choice;

int bezos = 0 , gates = 0 , bugs = 0 ;

int vc = 0 ;

do {

   cout<<"\n\n\nEVOTE\n-----"

   <<"\n1.Jeff Bezos

   <<"\n2.Bill Gates

   <<"\n3.Bugs Bunny"

// 4. Print current tally [hidden admin option]

// 5. Print audit trail [hidden admin option]

// 6. mess with the vote [hidden hacker option] E.C.

// 7. END THE ELECTION

   <<"\n\n Your selection? ";

   cin >> choice ;

   if(choice==1) {bezos++ ; vc++ ; cout<<"\nThanks for voting!"; }

   if(choice==2) {gates++ ;vc++ ; cout<<"\nThanks for voting!"; }

   if(choice==3) { bugs++ ; vc++ ; cout<<"\nThanks for voting!"; }

   if((choice<1)||(choice>7))cout<<"\nPlease enter 1-3";

   // write what happened to FILES

   // Tally.txt (overwrite) bezos x gates x bugs x

   // auditTrail.txt ios::app (everything typed) 1 2 3 3 56 -12 4

} while(choice != 7 ) ;

  

cout<<"\n\nRESULTS:\n--------"

<<"\nTotal Votes Cast This Election: "<< vc

<<"\nJeff Bezos: "<< bezos

<<"\nBill Gates: "<< gates

<<"\nBugs Bunny: "<<bugs;

  

cout<<"\n\n";

system("pause"); // leave this out if using newer DEV C++

return 0;

}

  

Solutions

Expert Solution

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

int main(){
  int choice;
  int bezos = 0 , gates = 0 , bugs = 0 ;
  int vc = 0 ;
  do {
    cout << "\n\n\nEVOTE\n-----"
    << "\n1.Jeff Bezos"
    << "\n2.Bill Gates"
    << "\n3.Bugs Bunny"
    // 4. Print current tally [hidden admin option]
    // 5. Print audit trail [hidden admin option]
    // 6. mess with the vote [hidden hacker option] E.C.
    // 7. END THE ELECTION
    <<"\n\n Your selection? ";

    cin >> choice;

    if (choice == 1) { bezos++ ; vc++ ; cout << "\nThanks for voting!"; }
    if (choice == 2) { gates++ ; vc++ ; cout << "\nThanks for voting!"; }
    if (choice == 3) { bugs++  ; vc++ ; cout << "\nThanks for voting!"; }
    if ((choice < 1) || (choice > 7)) cout << "\nPlease enter 1-3";
    // write what happened to FILES
    // Tally.txt (overwrite) bezos x gates x bugs x
    ofstream tally;
    tally.open("Tally.txt"); // overwrite
    tally << "bezos " << bezos << " gates " << gates << " bugs " << bugs;
    tally.close();
    // auditTrail.txt ios::app (everything typed) 1 2 3 3 56 -12 4
    ofstream auditTrail;
    auditTrail.open("auditTrail.txt", ios_base::app); // append instead of overwrite
    auditTrail << choice << " ";
    auditTrail.close();

  } while(choice != 7 );

  cout<<"\n\nRESULTS:\n--------"
  << "\nTotal Votes Cast This Election: " << vc
  << "\nJeff Bezos: " << bezos
  << "\nBill Gates: " << gates
  << "\nBugs Bunny: " << bugs;
  cout<<"\n\n";

  system("pause"); // leave this out if using newer DEV C++
  return 0;
}

Related Solutions

For C++ Write a program that opens a specified text file then displays a list of...
For C++ Write a program that opens a specified text file then displays a list of all the unique words found in the file. Hint: Store each word as an element of a set.
****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED Write a C...
****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED Write a C program using system call I/O to determine how many lines there are in a text file.
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a...
WRITE IN C++ Add to the Coord class Edit the provided code in C++ Write a member function named      int distance2origin() that calculates the distance from the (x, y, z) point to the origin (0, 0, 0) the ‘prototype’ in the class definition will be      int distance2origin() outside the class definition             int Coord :: distance2origin() {                         // your code } _______________________________________________________________________________________________________ /************************************************** * * program name: Coord02 * Author: * date due: 10/19/20 * remarks:...
5) File I/O A) Compare and contrast InputStream/OutputStream based file I/O to Scanner/Printwriter based file I/O:...
5) File I/O A) Compare and contrast InputStream/OutputStream based file I/O to Scanner/Printwriter based file I/O: B) Discuss Serialization, what is it? What are the processes and features? What is the function of the keyword Transient?
Write a C program, called reverse, using standard I/O functions, to take a file as input...
Write a C program, called reverse, using standard I/O functions, to take a file as input then copies it to another file in reverse order. That is, the last byte becomes the first, the byte just before the last one becomes the second, etc. The program call should look like: reverse fileIn fileOut
Write a C program using system call I/O to a) open an existing text file passed...
Write a C program using system call I/O to a) open an existing text file passed to your program as a command line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated content of the file
Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O,...
Write a C program using system call I/O to ****NOTE YOU MUST USE SYSTEM CALL I/O, meaning STANDARD I/O IS NOT ALLOWED a) open an existing text file passed to your program as a command-line argument, then b) display the content of the file, c) ask the user what information he/she wants to append d) receive the info from the user via keyboard e) append the info received in d) to the end of the file f) display the updated...
Write a pseudo code for an O (n7log3n) algorithm. Please write in C++.
Write a pseudo code for an O (n7log3n) algorithm. Please write in C++.
I made the command cp code in c language. But when I copy a file, file...
I made the command cp code in c language. But when I copy a file, file permissions are not copied equally. So I want to copy the file authority as well. What should I do? #include #include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { struct stat st; char ch; int src, dst; if(argc != 3) { printf("argument error \n"); printf("usage: ./a.out src dest \n"); exit(0); } src = open(argv[1], O_RDONLY); if(src == -1){ perror("open...
C++ Write a word search program that searches an input data file for a word specified...
C++ Write a word search program that searches an input data file for a word specified by the user. The program should display the number of times the word appears in the input data file. In addition, the program should count and display the number of grammatical characters in the input data file. Your program must do this by providing the following function: void processFile(ifstream &inFile, string wordSearch, int &wordCount, int &grammaticalCount); void processFile(ifstream &inFile, string wordSearch, int &wordCount, int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT