PROGRAMMING PROJECT 1: HOGWART\'S ELECTION Thanks to your programming know-how,
ID: 3829305 • Letter: P
Question
PROGRAMMING PROJECT 1: HOGWART'S ELECTION
Thanks to your programming know-how, your first project went well and the staff at the Hogwart's School of Witchcraft and Wizardry are impressed. Your skills are sought out for a new programming job. The school is in need of your help with designing the run-off election and it will be you against a young man named Harry Potter for leadership of the school. (Pretty good, go from C++ programmer to school headmaster)
While they're going to the trouble of holding an election, they've also decided to vote on ten amendments to the school's constitution, kind of a "bill of lefts":
1. Change the motto from "Never tickle a sleeping dragon" to "Never tickle a dragon".
2. From now on the Quidditch players cannot qualify for a scholarship without a 2.0 GPA.
3. Beginning this year, hold an open house to all qualified muggles.
4. Have tours of the Chamber of Secrets every month.
5. Begin having the Defense of the Dark Arts classes online.
6. Offer 10% tuition break for the descendants of previous students of Hogwarts.
7. All feasts shall no longer include potions to drink.
8. The Goblet of Fire feast to celebrate the beginning of the Triwizard Tournament will be called Fear the Goblet.
9. Tuition costs will no longer include buying supplies and gaining access to Diagon Alley.
10. Everyone will hide the secret handshake at all graduation ceremonies.
All must pass by a 2/3 majority.
General Election Procedures
The voting proceeded as follows:
" Staff members stand in line to electronically cast their votes using machines made in Ohio.
" Each staff member has been assigned a unique number that they enter on the ballot.
" They enter the name of the candidate they are voting for, either "Harry Potter" or "the new guy".
" They enter Y or N for issues 1 through 10.
" The candidate with the most votes becomes the new Headmaster.
" The candidate with the second most votes is the runner up.
Note that staff members are neither honest nor very bright. They tend to get back in line and vote again with the "vote early and vote often" philosophy, and the machines let them get away with it. They are not, however, smart enough to use a different number. Your file will contain a sorted list of votes with possible duplicates. You need to check the current staff member number with any duplicates to see if that staff member has already cast a ballot. Only keep and tally the results of the first ballot for each staff member. Ignore duplicates even if they voted differently the second or third or fourth time. Note that not all numbers may be used, i.e., staff member registration numbers may be 5, 13, 21, 34, etc. Therefore, you'll need to keep track of how many staff members actually voted. You cannot rely on the last staff member registration number.
Ballots are stored automatically in a file called ballots.txt. The file only will hold a maximum of 100 staff member ballots. You need to open this file and read each ballot (one per line) until the end of the file. Sample ballots.txt file:
1YYYYYYYYYYThe New Guy
2YNYNYNYNYNHarry Potter
2YNNYYNNYYNHarry Potter
2NNNNNNNNNNThe New Guy
3NYNYNYNYNYThe New Guy
3YYYYYYYYYYHarry Potter
7YNYNYNYNYNThe New Guy
Note the format of each data line:
<integer> <char> <char> <char> <char> <char> <char> <char> <char> <char> <char> <string>
This Assignment
Your task is three-fold. First, as you read in the ballots, create parallel arrays full of all of the ballot file's ballots, but that keeps or contains only those ballots that were used in the count, and not the duplicates. Remember that will be the first vote you encounter in the data for each staff member. You will also need to keep track of all of the "cheat" votes, those that were duplicates or triplicates or … You will not need to store those in any form except to accumulate a total of them.
Next, you will need to create a new file (counted.txt) and simply write out your good ballots from your arrays into this file. It will end up looking like the original ballot.txt, less those duplicated votes that you did not put into your arrays.
Finally, determine the results of the election and print them out on the screen. Your output should include:
1. The candidate name list and how many votes each received.
2. How many total votes were cast. (This includes the cheat ballots.)
3. How many actual staff members voted.
4. If each issue passed or failed and the number of yes votes it received.
5. Who the new Headmaster and runner up are.
For example:
4 staff members voted in this election using 8 ballots.
Headmaster (most votes): The New Guy (with 3 votes)
Runner up: Harry Potter (with 1 vote)
Amendment #1 passes (3 Y, 1 N) - 75% met
Amendment #2 fails (2 Y 2 N) - 50% is not a majority
Amendment #3 passes (3 Y, 1 N) - 75% met
Amendment #4 fails (2 Y 2 N) - 50% is not a majority
Amendment #5 passes (3 Y, 1 N) - 75% met
Amendment #6 fails (2 Y 2 N) - 50% is not a majority
Amendment #7 passes (3 Y, 1 N) - 75% met
Amendment #8 fails (2 Y 2 N) - 50% is not a majority
Amendment #9 passes (3 Y, 1 N) - 75% met
Amendment #10 fails (2 Y 2 N) - 50% is not a majority
Tips:
1. You are opening one file for input and one file for output, closing both at program's end.
2. You need a while, do-while, or for loop to read in the ballots and to write out to your counted file.
3. You need to keep track of the most recent staff member number and compare it to the current ballot to determine if you are going to do anything with the ballot or not.
4. You are required to use 3 arrays in parallel. You should allocate them at 99 elements each, and assume they will be partially filled.
5. You need to tally the votes for each staff member candidate and for each issue.
6. For the Harry Potter and new guy election, you only need to know who got the most votes and who came in second.
7. For the issues, you need to know how many staff members actually voted to determine 2/3 or majority.
8. You will use the actual file names (ballots.txt and counted.txt) in your code. Do not prompt the user for file names.
9. If a staff member receives one vote, say "… received 1 vote" not "… received 1 votes".
Code:
" Use a header comment with your name and the purpose of the program.
" Your design must include breaking your code into functions, as follows:
o Function for creating the arrays;
o Function for writing parallel arrays to the counted output file;
o Function for determining the election winner;
o Function for processing the bills/amendments;
o One function must be called using pass-by-reference (you choose). The data obviously should be updated in your function.
" Functions must use a separate file (.hpp)
" Functions must have header comments that include the purpose of the function and the pre-condition and post-condition documentation as well.
" Follow the guidelines from the RubricProgrammingforAssignments on Springboard. As part of that rubric remember that your program will follow the CSI 3460:209 guidelines as described:
o Constants are declared with ALL CAPITAL LETTERS.
o Each curly bracket is on a line by itself
o Each level of indentation (such as the body of a function or the body of a loop) is indented either 3 or 4 extra spaces
o Blank lines are used in a meaningful way
o Formulas are nicely spaced with a space around every operator (except *, / and %), and a space after every comma in an argument list.
Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
#include <windows.h>
using namespace std;
struct student
{
string fname;
string lname;
string Registration;
string classes;
}studentData;
struct teacher
{
string fst_name;
string lst_name;
string qualification;
string exp;
string pay;
string subj;
string lec;
string addrs;
string cel_no;
string blod_grp;
string serves;
}tech[50];
void main()
{
int i=0,j;
char choice;
string find;
string srch;
while(1)
{
system("cls");//Clear screen
cout<<"\\\\\\\";
cout<<" SCHOOL MANAGEMENT PROGRAM ";
cout<<"\\\\\\\";
cout<<" MAIN SCREEN ";
cout<<"Enter your choice: "<<endl;
cout<<"1.Students information"<<endl;
cout<<"2.Teacher information"<<endl;
cout<<"3.Exit program"<<endl;
cin>>choice;
system("cls");
switch(choice)
{
case '1':
{
while(1)
{
system("cls");
cout<<" STUDENTS INFORMATION AND BIO DATA SECTION ";
cout<<"Enter your choice: "<<endl;
cout<<"1.Create new entry ";
cout<<"2.Find and display entry ";
cout<<"3.Jump to main ";
cin>>choice;
switch (choice)
{
case '1':
{ ofstream f1("student.txt",ios::app);
for( i=0;choice!='n';i++)
{
if((choice=='y')||(choice=='Y')||(choice=='1'))
{
cout<<"Enter First name: ";
cin>>studentData.fname;
cout<<"Enter Last name: ";
cin>>studentData.lname;
cout<<"Enter Registration number: ";
cin>>studentData.Registration;
cout<<"Enter class: ";
cin>>studentData.classes;
f1<<studentData.fname<<endl<<studentData.lname<<endl<<studentData.Registration<<endl<<studentData.classes<<endl;
cout<<"Do you want to enter data: ";
cout<<"Press Y for Continue and N to Finish: ";
cin>>choice;
}
}
f1.close();
}
continue;
case '2':
{ ifstream f2("student.txt");
cout<<"Enter First name to be displayed: ";
cin>>find;
cout<<endl;
int notFound = 0;
for( j=0;(j<i)||(!f2.eof());j++)
{
getline(f2,studentData.fname);
if(studentData.fname==find)
{
notFound = 1;
cout<<"First Name: "<<studentData.fname<<endl;
cout<<"Last Name: "<<studentData.lname<<endl;
getline(f2,studentData.Registration);
cout<<"Registration No number: "<<studentData.Registration<<endl;
getline(f2,studentData.classes);
cout<<"Class: "<<studentData.classes<<endl<<endl;
}
}
if(notFound == 0){
cout<<"No Record Found"<<endl;
}
f2.close();
cout<<"Press any key two times to proceed";
getch();
getch();
}
continue;
case '3':
{
break;
}
}
break;
}
continue;
}
case '2':
{
while(1)//inner loop-2
{
system("cls");//Clear screen
cout<<" TEACHERS INFORMATION AND BIODATA SECTION ";
cout<<"Enter your choice: "<<endl;
cout<<"1.Create new entry ";
cout<<"2.Find and display ";
cout<<"3.Jump to main ";
cin>>choice;
switch (choice)
{
case '1':
{
ofstream t1("teacher.txt",ios::app);
for(i=0;choice!='n'&& choice!='N';i++)
{
if((choice=='y')||(choice=='Y')||(choice=='1'))
{
cout<<"Enter First name: ";
cin>>tech[i].fst_name;
cout<<"Enter Last name:: ";
cin>>tech[i].lst_name;
cout<<"Enter qualification: ";
cin>>tech[i].qualification;
cout<<"Enter experiance(year): ";
cin>>tech[i].exp;
cout<<"Enter number of year in this School: ";
cin>>tech[i].serves;
cout<<"Enter Subject whos teach: ";
cin>>tech[i].subj;
cout<<"Enter Lecture(per Week): ";
cin>>tech[i].lec;
cout<<"Enter pay: ";
cin>>tech[i].pay;
cout<<"Enter Phone Number: ";
cin>>tech[i].cel_no;
cout<<"Enter Blood Group: ";
cin>>tech[i].blod_grp;
t1<<tech[i].fst_name<<endl<<tech[i].lst_name<<endl
<<tech[i].qualification<<endl<<tech[i].exp<<endl
<<tech[i].serves<<endl<<tech[i].subj<<endl<<tech[i].lec
<<endl<<tech[i].pay<<endl<<tech[i].cel_no<<endl<<tech[i].blod_grp<<endl;
cout<<"Do you want to enter data: ";
cin>>choice;
}
}
system("cls");
t1.close();
}
continue;
case '2':
{
ifstream t2("teacher.txt");
cout<<"Enter name to be displayed: ";
cin>>find;
cout<<endl;
int notFound = 0;
for( j=0;((j<i)||(!t2.eof()));j++)
{
getline(t2,tech[j].fst_name);
if(tech[j].fst_name==find)
{
notFound = 1;
cout<<"First name: "<<tech[j].fst_name<<endl;
getline(t2,tech[j].lst_name);
cout<<"Last name: "<<tech[j].lst_name<<endl;
getline(t2,tech[j].qualification);
cout<<"Qualification: "<<tech[j].qualification<<endl;
getline(t2,tech[j].exp);
cout<<"Experience: "<<tech[j].exp<<endl;
getline(t2,tech[j].serves);
cout<<" number of year in this School: "<<tech[j].serves<<endl;
getline(t2,tech[j].subj);
cout<<"Subject whos teach: "<<tech[j].subj<<endl;
getline(t2,tech[j].lec);
cout<<"Enter Lecture(per Week): "<<tech[j].lec<<endl;
getline(t2,tech[j].pay);
cout<<"pay: "<<tech[j].pay<<endl;
getline(t2,tech[j].addrs);
cout<<"Address: "<<tech[j].addrs<<endl;
getline(t2,tech[j].cel_no);
cout<<"Phone Number: "<<tech[j].cel_no<<endl;
getline(t2,tech[j].blod_grp);
cout<<"Bool Group: "<<tech[j].blod_grp<<endl;
}
}
t2.close();
if(notFound == 0){
cout<<"No Record Found"<<endl;
}
cout<<"Press any key two times to proceed";
getch();
getch();
}
continue;
case '3':
{
break;
}
}
break;
}
continue;
}
case '3':
{
break;
}
break;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.