Please help!!

Hi guys, I need help with an assignment. I'm very new to C++ (in 8th week of learning) and I don't know where to begin with this assignment.

source file: voting. {c, cpp, java}
input file: voting.in

A committee clerk is good at recording votes, but not so good at counting and figuring the outcome correctly. As a roll call proceeds, the clerk records votes as a sequence of letters, with one letter for every member of the committee:
Y means a yes vote
N means a no vote
P means present, but choosing not to vote
A indicates a member who was absent from the meeting

Your job is to take this recorded list of votes and determine the outcome.

Rules: There must be a quorum. If at least half of the members were absent, respond "need quorum".
Otherwise votes are counted. If there are more yes than no votes, respond "yes". If there are more no than yes votes, respond "no". If there are the same number of yes and no votes, respond "tie".

Input:
The input contains of a series of votes, one per line, followed by a single line with the # character. Each vote consists entirely of the uppercase letters discussed above. Each vote will contain at least two letters and no more than 70 letters.

Output: For each vote, the output is one line with the correct choice "need quorum", "yes", "no", or "tie"

Example input: Example output:
YNNAPYYNY = yes
YAYAYAYA = need quorum
PYPPNNYA = tie
YNNAA = no
NYAAA = need quorum
#

I'm using Visual Studio 2012 and the input has to be either c-string or string.

Right now I have the following.

#include <fstream>
#include <iostream>
using namespace std;
int main(){
ifstream inputFile;
int num;
int sum = 0;

inputFile.open("input.txt");
if (inputFile.fail()){
cout << "file cannot be opened" << endl;
exit(1);

then what? for loop? while? I don't know.


If you guys can help me get some idea or help me at all, I'd appreciate it! Thank you!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
While the input file has data:
    Read a line
    If the line's length is not  zero,
        Parse the input (This could be another function)

End while.

Parse function:

For each character (c) in the line
    switch( c )
        {
        case 'A':
            /*    Do something with 'A'    */
            break;

        case 'N':
            break;

        case 'P':
            break;

        case 'Y':
            break;

        default:
            break;

        }    /*    switch( c )    */
 
A better code would be like this:
While  Read a line from the input file  succeeds:
    If the line's length is not  zero,
        Parse the input (This could be another function)
End while.

etc.
Last edited on
Topic archived. No new replies allowed.