Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Take as your starting point the program below. It reads from a file called \"pol

ID: 3656004 • Letter: T

Question

Take as your starting point the program below. It reads from a file called "polls.txt" lines of the form: NC 46 45 00 Sep 29 Oct 10 High Point University and prints out the state abbreviation found in the beginning of each line of input. MODIFY this program so it does not print any state abbreviation out more than once. If there are consecutive lines having the same state abbreviation, it will still only be printed once. #include #include using namespace std; int main() { ifstream pollFile("polls.txt"); string state = " ", notNeeded, laststate=state; pollFile >> state; while (state!=laststate) { getline(pollFile,notNeeded); cout << state << endl; pollFile >> state;} return 0; } // NC 46 45 00 Sep 29 Oct 10 High Point University // The above line is a typical representative line of data

Explanation / Answer

#include #include #include #define MAX_STRING_LENGTH 30 void alphasort(char** sList, int* nList, int &numStates, bool ascendant); void swapState(char** str1, char** str2); int swapNum(int* num1, int* num2); void freeList(char** sList, int* nList, int numStates); int main(int argc, char** argv) { FILE* ifp; int i = 0, j = 0, k = 0, n = 0, x; int votesToWin = 270, totalVotes; // declares 270 votes needed to win char letter, stateName[MAX_STRING_LENGTH], candidate[10]; char** sList; int* nList; int testCase, numStates, numState, wordLength; int obamaVotes, mccainVotes, stateVotes; ifp = fopen("election.txt", "rt"); // opens election.txt file if(ifp == NULL) { printf("Error in opening the file."); return 1; } fscanf(ifp,"%d ", &testCase); // reads first integer in the file for(k = 1; k
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote